I2C LED Control with Rioduino


#1

Hey All,

Last year we used a string of blue LED’s on our robot to indicate robot status to our drivers. This year we want to use RGB LED’s to indicate more events. The plan is to use a rioduino over the I2C bus (Either onboard, or through MXP slot), to control a strand of LEDs. I have seen the labview example, and the touchscreen example, but we program in JAVA. Also, I’m trying to simplify the code by only sending a single character per status to the Rioduino. I would have a case switch in the Rioduino C# code with the different LED patterns. The sticking point seems to be in the JAVA code for sending characters. I just can’t figure out I2C api notes. I can post both my arduino and java code if people are interested. Any notes, hints, example code or tutorials are appreciated.

Thanks.


#2

I’m not sure how to do this with I2C as we used serial but we appear to think alike, as I sent single characters last season (over serial). Worked great!


#3

Thanks, although, that doesn’t seem like enough code. How does the mode change? Does it send the entire string " Pulse_Color" or just a single character? Additionally, do you have your rioduino side code?

Thanks a bunch for helping out.


#4

It’s sending a character.

Mode is an enum.

mode.ordinal returns the position of the value as an integer (Eg. passing Mode.PULSE_GREEN to setMode will result in a 1), which is then type-casted to a char.

The code for the RIODuino is also on our github. It’s basically the example code from Andymark’s page, with some modifications.


#5

Greetings!

Our team isn’t using a Rioduino, but from what I read it’s basically just an Uno R3, right? If there’s a fundamental difference in the operation then the following may be invalid:

We’re currently using a plain-old Uno R3 hooked to the RoboRio via the dedicated I2c connection and the kids are using the following code on the Rio in the Java program:


static I2C arduino;
...
(in robotInit)
arduino = new I2C(I2C.Port.kOnboard, 4);
...
static void UpdateLEDs(String WriteString)
	{
		char] CharArray = WriteString.toCharArray();
		byte] WriteData = new byte[CharArray.length];
		for (int i = 0; i < CharArray.length; i++) {
			WriteData* = (byte) CharArray*;
		}
		arduino.transaction(WriteData, WriteData.length, null, 0);
	}

Then they call “Robot.UpdateLEDs([mode])” with a given game-mode, such as “TELEOP”.

On the Arduino side, they’ve got the following: https://pastebin.com/6ZVZ0qs0

Right now, they’re only using it to determine if the robot is in Teleop, Auto, or Disabled, but it’s working and looks good!**


#6

@Muskie Thanks for clarifying that and sharing your 'duino code. I’ll test it out as soon as the kids let me have the RIO for 10 mins.

@ mrEkko Super thanks for the JAVA code, that was the part I was struggling with the most. Ditto for 'duino code. One question, what was the object “LED” declared as? The compiler does not like that it does not have a declaration.


#7

We have strips of NeoPixel LEDs (digital) and we use the Arudino_NeoPixel library. More information about the LEDs and the library can be found at the following links:
https://www.adafruit.com/category/168


#8

Thanks for the quick reply. I think I have succeeded in getting both sets of code to compile properly. Now I need access to a Rio to actually test.


#9

After a bit of finagling, here is our current RIOduino and Java code for controlling LEDs. Thanks @Mr.Ekko for providing help in the right direction.

Robot.java (4.11 KB)
LED I2C Drive Status Code.txt (6.04 KB)