2 years back, one of our mentors helped us to use network tables to have the cRIO talk to our Arduino Ethernet for controlling LEDs. We abandoned the project last year due to time, but this year we were hoping to have the same Arduino talk to the roboRIO, but we have not been able to find out how to do it, even after doing extensive research. Our java code can read the serial outputs from the Arduino, but we do not know how to have the Arduino read from our java code (we hope to have different LED patterns for certain situations such as autonomous or which alliance we are on).
If any of you guys have been able to do this with the roboRIO, help would be appreciated! Thanks.
We don’t have any experience using a Ethernet interface on an Arduino for command and control. However, we are using a Arduino this year to control LEDs as well. Our implementation is fairly simple. We have 4 separate LED patterns which our Arduino can run. To tell the Arduino which pattern to show, we connected two digital outputs from the roboRIO to digital inputs on the Arduino.
The Arduino just monitors the digital inputs to see which LED pattern to show.
We just use two DigitalOutput objects on the roboRIO side to tell the Arduino which pattern we want it to display.
It’s not the most sophisticated system, but it works well and is simple to implement when it’s late in the season and you want to get your LEDs lit.
I didn’t actually write the code on the LED side (we have a lot of kids on the team and gave that task to a group of them).
However, I’m pretty sure the following code fragment demonstrates how to detect the current LED mode (4 choices: 0, 1, 2 and 3) and whether the mode has just changed:
// Change to the I/O pins you used
// to connect your Arduino to your roboRIO
int ledControl0 = 8;
int ledControl1 = 9;
// Current LED operating mode
int curMode = -1;
void setup() {
// Set up I/O pins for LED control as inputs
pinMode(ledControl0, INPUT);
pinMode(ledControl1, INPUT);
}
void loop() {
// Assume no LED mode change
int modeChanged = 0;
// Start with mode 0
int mode = 0;
if (digitalRead(ledControl0)) {
// Control line 0 set, add 1 to mode (set bit 1 in mode)
mode = mode + 1;
}
if (digitalRead(ledControl1)) {
// Control line 1 set, add 2 to mode (set bit 2 in mode)
mode = mode + 2;
}
// Check to see if mode changed since last check
if (mode != curMode) {
curMode = mode;
modeChanged = 1;
}
// At this point, curMode will be a value of 0, 1, 2 or 3
// and modeChanged will be 1 if the mode has changed from
// last invocation or 0 if it is the same as last time
// Add your code below to set your LED display output
// accordingly ...
}