View Single Post
  #1   Spotlight this post!  
Unread 02-16-2015, 12:57 PM
AquaWarrior12's Avatar
AquaWarrior12 AquaWarrior12 is offline
Registered User
FRC #2582 (Panther Bots)
Team Role: Programmer
 
Join Date: Dec 2013
Rookie Year: 2014
Location: Texas
Posts: 4
AquaWarrior12 is an unknown quantity at this point
Help Communicating the RIODuino with the RoboRIO

Hello fellow Programmers, I am in need of assistance. I am currently attempting to make a RIODuino communicate with the roboRIO. However, I have run into some difficulties concerning the code that allows them to communicate. I have this Java code, which reads:

Quote:
static I2C Wire = new I2C(Port.kOnboard, 4);

if (Global.driver.Buttons.Back.changedDown) {
String WriteString = "go";
char[] CharArray = WriteString.toCharArray();
byte[] WriteData = new byte[CharArray.length];
for (int i = 0; i < CharArray.length; i++) {
WriteData[i] = (byte) CharArray[i];
}
Wire.transaction(WriteData, WriteData.length, null, 0);
}
As it is, the Global reads as an error. If anyone can tell me how to fix this code, or potentially convert it to C++(which is how my team actually codes), then it would be greatly appreciated.
Also, the Arduino code reads:
Quote:
#include <Wire.h>

void setup()
{
pinMode (13, OUTPUT);
Wire.begin(4); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
}

void loop()
{
delay(100);
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
String LED = "";

while ( Wire.available() > 0 )
{
char n=(char)Wire.read();
if(((int)n)>((int)(' ')))
LED += n;
}

if (LED == "go")
{

digitalWrite (13, HIGH);


}
}
This Arduino code runs properly, or at least it appears so.
Again, any assistance in my problem would be greatly appreciated.
Thank you!
Reply With Quote