View Single Post
  #6   Spotlight this post!  
Unread 07-02-2014, 17:10
Bobert's Avatar
Bobert Bobert is offline
Registered User
FRC #0696
 
Join Date: Jan 2009
Location: La Crescenta
Posts: 12
Bobert will become famous soon enoughBobert will become famous soon enough
Re: Arduino-cRIO I2C Communication

I am also trying to communicate with an Arduino over i2c. I can't get anything to be transmitted. I'm using this code on the cRIO:

Code:
public static void sendMessage(int message){
        DigitalModule.getInstance(1).getI2C(1).setCompatabilityMode(true);
        DigitalModule.getInstance(1).getI2C(1).write(4, message);
    }
And this code on the Arduino:

Code:
void setup()
{
  Wire.begin(4);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);           // start serial for output
  Serial.print("Start up");
  pinMode(13, OUTPUT); 
  digitalWrite(13, LOW); 
}

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)
{
  while(1 < Wire.available()) // loop through all but the last
  {
    char c = Wire.read(); // receive byte as a character
    Serial.print(c);         // print the character
  }
  int x = Wire.read();    // receive byte as an integer
  Serial.println(x);         // print the integer
  digitalWrite(13, HIGH);
}
I tried changing the addresses like you said, but saw no effect. Am I doing something stupid? I really feel like I'm making this harder than it should be.
Reply With Quote