We have an arduino that runs the lights on our teams robot. We were wondering if there is a way to have the arduino react to commands made from the driver station. Thanks for any help you can provide.
what do you mean by the driver station commands? what you could do you could use a pwm line or dio from the roborio to the ardouino and read it there
You can have the Driver Station talk to the roboRIO, and then have the roboRIO talk to the Arduino using the serial port or I2C.
How complicated of lighting are we talking here? Would a simple PWM line or DIO not suffice. Just have the roborio output a PWM wave to the arduino to read then you could have your various lighting settings based on the PWM signals.
I would do something like this on arduino side, you could also have multiple pwm values for diffrent lights if you wanted it to.
float PWMsignal;//the signal from the roborio
void setup() {
// put your setup code here, to run once:
PWMsignal=0;//intilizes signal
Serial.begin(9600);//syncs up serial output
}
void loop() {
// put your main code here, to run repeatedly:
PWMsignal=analogRead(3);//reads the pwm value for pin 3
if(PWMsignal=42){//if its whatever pwm value you want turn pin 4 on
digitalWrite(4,HIGH);
}
else{
digitalWrite(4,LOW);
}
Serial.println(PWMsignal);//outputs value to serial port
}
:ahh:
:ahh: indeed
int PWMsignal;
// ...
if (PWMsignal == 42)
// ...
I would say that using that method would be highly susceptible to problems. You’re relying on some undefined capacitance on the analog pin of the Arduino, cabling, and RoboRIO’s PWM pins. You can use I2C, SPI, UART, or UDP/TCP if you get an Ethernet shield.
Another dead simple way would be to use some DIO as outputs. You can have 2^n modes where n is the number of outputs you use.
From Easy to Hard (my opinion of course):
DIO, UART, TCP/UDP, I2C
what would the code be on the roborio? we are using java.
I would definitely recommended this - WPIs I2C wrapper is well documented, as is the Wire library for arduino. The approach I have taken before is to manually enable bits in a single byte to represent certain states like the current mode or alliance, as well as any custom flags I had set like if certain buttons were pressed on a joystick, and then simply sent that byte of data over the I2C bus and had the arduino read that data and process it in a similar way. I have an example of this on github if you would like to see this in practice.
Honestly the easiest way would be to keep it digital. My team did this last year, and although we didn’t implement it totally on the robot, it completely worked and was pretty cool.
Basically we just ran an alarm wire (4 wires + 1 ground) from the arduino to the roborio. The 4 digital pins that we used allowed 2^4 = 16 lighting modes. We could easily write to the digital pins on the roborio, and the arduino would simply react by reading the digital inputs.
Not nearly as robust as an analog/protocol system, but super simple and easy to implement.
how does one set the digital pins to high from the roborio?
DigitalOutput.set(true);](http://first.wpi.edu/FRC/roborio/release/docs/java/edu/wpi/first/wpilibj/DigitalOutput.html#set-boolean-) in Java, where DigitalOutput is a properly constructed DigitalOutput object. C++ should be similar.