Roborio and Arduino wiring

Hello my team is interested in adding lights to our robot using an Arduino Leonardo++. I have looked around on how to get the Roborio and Arduino to communicate and I got a variety of answers such as analog, I²C, and serial. But I couldn’t find anything on how to actually wire it up. Can you please help.

Thank you.

The wiring you use will depend on the protocol you decide to use. Have you decided whether you will use analog, digital, I2C, SPI, UART, etc? I think that digital may be the easiest to get started. However you need 4 wires to get 8 patterns (ground + 3 signal = 2^3 = 8). 5 wires to get 16, 6 wires for 32, etc.

As a project over the summer I used the I2C bus on the RoboRio to send commands to an Arduino UNO (wired via I2C ports on the UNO) which drove a strip of LEDs based on the command sent.

The I2C class in WPILib is fairly straightforward, and the Wire library for Arduino is even easier to use. The I2C pins on the Leonardo are 2 (SDA) and 3 (SCL). Connect these, the 3.3v and the ground pins from the Arduino to the I2C port on the Rio and you are all set.

Here is the code I used on the Rio’s side to send the commands. It uses 1 integer as the data, and each of the 8 bits in the integer represent a state of the robot that I wish to reflect in the LEDs. For example, if the robot is on the blue alliance, it will enable the 0th bit (least significant bit), and if the robot is in teleop, it will enable to 1st bit.

The Arduino code simply catches the data integer and checks each bit, and tells the LEDs how to behave based on the parameters we have sent it.

I chose to send 1 integer of data because it was pretty straightforward, however, you can send multiple variables or stings of text over the I2C line, but it would be more difficult on both ends to program.

Hope this helps.

I actually got code on the Rio working so that we could have it communicate with an Uno using serial over just a USB cable. This method is very simple, as the Arduino can both be powered by and communicate with the Rio using only one cable. Are you using the Leonardo++ from a past KoP? This one perhaps? I had some issues using it, I could never quite figure out why though. I opted for using an Uno instead (I had plenty at home that we could have used).

On the Arduino side, I just had it poll the serial buffer until something came in. Once the Rio sent it something, I had the Uno interpret that as some pre-defined sequence (for example, sending “B” made all of the LED strips turn blue).

Let me know if you were at all interested in seeing either the Arduino or Rio code. What language is your team using for your bot? We are a C++ team, but I’m sure it would function just as well on the Java side. Below is a link to the WPILib documentation on the SerialPort class that I used on the Rio.