How to Connect the RoboRio to an Arduino


#1

I’m trying to connect an Arduino to the RoboRio. I looked at the 2014 I2C code, but it uses Digital Module which doesn’t seem to exist anymore. I tried using RS-232 with Serial Port, but it keeps throwing errors when I use the .readString() function.

How do I set this up. Links to code that works in 2018 would be appreciated.


#2

I pasted some code into this thread about how our team connected the rio to an Arduino Uno. Take a look and feel to let me know if you have any questions.


#3

What errors are being thrown? Also could you post your code? We used an Arduino last year connected over USB and it worked very well. Still considering using it again this year…


#4

If you wanna connect any co-processor you have to connect with the port on radio, for example use a switch for extend the number of ports for rj45 communication, or if you can use the ‘can’ communication with a module


#5

That isn’t true in many regards. You can connect many types of systems to the Roborio via the I2C port or SPI port. Or in the case of the RIOduino and others you can use the MXP port. Programming for these things is not always easy though as they most likely won’t have built in libraries.


#6

So How did you manage to connect a USB to the arduino? If you could email me at caleb.gaming01@gmail.com that would be wonderful!


#7

They probably used a ttl-usb converter.


#8

You can plug the Arduino directly into the Rio as you would if you were hooking the Arduino to a computer for programming and use a Serial connection between the two devices. WPILib has a constant SerialPort.Port.kUSB for a serial device connected via the Rio’s USB port. Here’s what we’re using this year:

SerialPort arduino = new SerialPort(9600, SerialPort.Port.kUSB);
...
arduino.writeString("Hello, Arduino!");
String response = arduino.readString();

On the Arduino side, check out the Read example which reads Serial data into your program. If you’re using a compatible board, you can also use the SerialEvent method which may be beneficial in some programs.