Go to Post In most cases on FIRST robots, we have more material than in we need in some places and less than we need in others. That single phenomenon is the leading cause of robot failures. - Paul Copioli [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 19-03-2013, 17:01
Bryce Paputa's Avatar
Bryce Paputa Bryce Paputa is offline
FF TSL: Frog Farce
FRC #0503 (Frog Force)
Team Role: Alumni
 
Join Date: Jan 2012
Rookie Year: 2008
Location: Novi Michigan
Posts: 454
Bryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond repute
Arduino-cRIO I2C Communication

Has anybody used I2C to talk to an arduino from the crio (Java)? I would like to do it to control some lights on our robot, and I think I know what the crio side of the code should look like, but I don't know how to do the arduino side. Does anybody have any suggestions? Has anyone had a good experience with a different method?
Reply With Quote
  #2   Spotlight this post!  
Unread 19-03-2013, 17:05
engunneer's Avatar
engunneer engunneer is offline
Alumni turned Mentor
AKA: Branden Gunn
FRC #4761
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 1996
Location: Reading, MA
Posts: 862
engunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond repute
Re: Arduino-cRIO I2C Communication

you'll want to use the Wire library, probably. If you are trying to be an I2C slave, worst case you can bit-bang it.

How many different light patterns do you want to display? It may be easier to just use a few I/O between the two as raw signals instead of doing a bus-type interface.
__________________
Student FRC23 (1996-1999), Mentor FRC246 (2000), Mentor FRC1318 (2007-2009), Mentor FRC93 (2011), Mentor FRC2151 (2012), Mentor FRC23 (2013), Mentor FRC4761 (2014-2017)
1998 - National Chairman's Award and Woodie Flowers Award (FRC23, Mike Bastoni ) | 2007 - PNW SF (488, 1595) | 2008 - Oregon RCA - Seattle #2 Seed, SF (488, 1696) | 2009 - Oregon #1 Seed, Winners (1983, 2635) - Seattle SF (945, 2865) - Galileo #2 Seed, SF (973, 25) | 2012 Midwest F (111, 71) | 2014 RIDE Winners (78, 125), Inspector - NEU #24, QF (3479, 3958) - NECMP #35 | 2015 Reading #11, SF (1058, 190), Inspector - RIDE #17, QF(4055, 5494), Inspector - NECMP #57 | 2016 Reading #4, SF (133, 4474), DCA, Inspector - Ride #22, SF (1735, 2067), Creativity, Inspector - NECMP #48, RCA - Archimedes
Reply With Quote
  #3   Spotlight this post!  
Unread 19-03-2013, 19:00
AlexBrinister AlexBrinister is offline
Registered User
AKA: Alex Brinister
FRC #1768 (RoboChiefs)
Team Role: Alumni
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Bolton, MA
Posts: 93
AlexBrinister will become famous soon enough
Re: Arduino-cRIO I2C Communication

We tried to mimic some Accelerometer code from WPILib since it is also an I2C device. However, we couldn't really get it to work so it didn't end up on this year's robot. I'd recommend looking at the ADXL345_I2C class.

Alex Brinister
Reply With Quote
  #4   Spotlight this post!  
Unread 20-03-2013, 22:13
Mike Bortfeldt Mike Bortfeldt is offline
Registered User
FRC #1126 (& 1511)
Team Role: Mentor
 
Join Date: Oct 2004
Rookie Year: 2004
Location: Rochester, NY
Posts: 119
Mike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud of
Re: Arduino-cRIO I2C Communication

Quote:
Originally Posted by Bryce Paputa View Post
Has anybody used I2C to talk to an arduino from the crio (Java)? I would like to do it to control some lights on our robot, and I think I know what the crio side of the code should look like, but I don't know how to do the arduino side. Does anybody have any suggestions? Has anyone had a good experience with a different method?
Bryce,

What you are trying to do is definately possible as we've implemented this on our robot this year, both for LED control as well as gyro and field positioning. There are a couple of bugs you have to watch out for, two on the cRIO side, and one on the Arduino, but once you understand what they are, it works reasonably well. I say, reasonably, because we were having some sporatic communication issues that I think is due to the I2C cable length, but as the robot is bagged, I can't test it out. Initial bench testing didn't seem to have this issue. As Branden mentioned, you will want to use the Wire library with the Arduino as the I2C slave. You will need to bit shift the address you use left by 1 for the cRIO as it apparently interprets the LSB (the read/write bit) as part of the address. For example, if you use an address of "2" for the Wire library on the Arduino, you will have to use an address of "4" on the cRIO. Second, there is a bug in the Wire library in the slave "restart" command that will prevent the cRIO from completing a successful write/read transaction with the Arduino. You can get around this by splitting the transaction into two parts, a write only (0 bytes for the read) followed by a read (0 write bytes). Alternately, there is a fix for the Wire library you can find on the net if you search (this is where I found it). Finally, there seems to be a bug in the WPI Library, where if you try to send (write) multiple bytes to the Arduino, it will interpret the individual bytes as "signed integers" and possibly overwrite some bytes with a value of 255 up to the integer 4 byte boundry where it will work again. The easiest way around this is to make sure you never send a value greater than 127 to the Arduino, or ensure that if you do need to do so, it is either the 4th byte or last byte sent. Finally, this brings up the fact that the cRIO limits you to 7 bytes of data communication per transaction each way. If you have any other questions, PM me, and I'll try to help.

Mike
Reply With Quote
  #5   Spotlight this post!  
Unread 09-04-2013, 22:51
Mike Bortfeldt Mike Bortfeldt is offline
Registered User
FRC #1126 (& 1511)
Team Role: Mentor
 
Join Date: Oct 2004
Rookie Year: 2004
Location: Rochester, NY
Posts: 119
Mike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud of
Re: Arduino-cRIO I2C Communication

Quote:
Originally Posted by Mike Bortfeldt View Post
we were having some sporatic communication issues that I think is due to the I2C cable length, but as the robot is bagged, I can't test it out. Initial bench testing didn't seem to have this issue.
For reference, the communication failures were resolved by calling:
Code:
SetCompatabilityMode(true);
on the I2C object.

Mike
Reply With Quote
  #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
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 13:29.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi