![]() |
Use Sidecar I2C port to communicate with Arduino?
My team is working on a project that involves the digital sidecar sending information over I2C to an Arduino Uno (R2, if it matters). Is this possible, and how can it be done? I know nothing of LabView (which is what my team uses to program the robot) but I know quite a bit of arduino C.
Would this code work? All I need to do is have the Arduino receive one byte of information at a time. I want the Arduino configured as master and the sidecar configured as slave. Code:
#include <Wire.h>//I2C library for Arduino |
Re: Use Sidecar I2C port to communicate with Arduino?
evanperryg,
You can use the cRIO to communicate with the Arduino, several teams have done so, including mine. However, to the best of my knowledge, the cRIO has to be the master as an I2C slave is not currently supported. There are a couple of threads on this topic that might help if you search. I can help if you have specific questions from the Arduino side, (or cRIO from a Java perspective). Mike |
Re: Use Sidecar I2C port to communicate with Arduino?
Our team has been having some trouble with this. We don't have anybody experienced with the arduino, and we are seeing what we think to be incorrect I2C timing on the cRIO side. If you have an example for the arduino and for java, it would be appreciated.
|
Re: Use Sidecar I2C port to communicate with Arduino?
I will try to post some sample code tonight, however if you are having what you believe are timing issues, take a look at this post.
Mike |
Re: Use Sidecar I2C port to communicate with Arduino?
I've done some research, and I have pretty much drawn a blank on how to get this to work. If someone has example code of an arduino being used as slave and recieving data, then that would be awesome.
|
Re: Use Sidecar I2C port to communicate with Arduino?
Did some quick googling, found this that should work for i2c on the arduino side.
Code:
#include <Wire.h> |
Re: Use Sidecar I2C port to communicate with Arduino?
We used an Arduino on our robot, this year, to give us very accurate gyro readings and to control LED's on the robot. We program in java on the cRIO and at first had trouble. It turns out that the cRIO is not defaulted to transfer I2C data correctly because we would receive fault values followed by a correct value. To fix this issue we added the line:
private static I2C i2c = digitalSidecar.getI2C(4); i2c.setCompatabilityMode(true); to our startup code. This solved our main problem and data was reliable recieved/sent after that, |
Re: Use Sidecar I2C port to communicate with Arduino?
Here is some sample code from http://blog.oscarliang.net/raspberry...connected-i2c/ that communicates via I2C to a Raspberry Pi, although it will be pretty much the same to communicate with the cRio.
Code:
#include <Wire.h> |
Re: Use Sidecar I2C port to communicate with Arduino?
OK, here is some sample code that should allow you to communicate between an Arduino and the cRIO. Sorry for it being a little longer than I intended. First off, while the format is similar to what we use on the robot, I can not test this out to ensure there are no errors as I do not have the hardware available. There shouldn't be any syntax errors, but by extracting and making a sample program, I may have introduced some other problem. Hopefully not so severe that you can't make it work relatively easily.
This sample includes both a read and a write example with the Arduino code handling both. A couple of items to note... A write/read transaction is never performed in the same function call. This is because there is a bug in the Arduino wire library that sends a "STOP" after the first part of the transaction even though it is setup as a SLAVE. There is a fix for this, but I have not had the chance to test it out. This method of splitting the write and read into two parts should always work. Second, there is a bug in the JAVA version of the I2C library that could corrupt data sent to the Arduino if any of the bytes are greater than 127. This is due to how the library combines the "bytes" into "int"s prior to sending and JAVA interprets all bytes as signed. The next version of WPILib will correct this. 'C' and Labview users shouldn't see this problem. Finally, the Arduino code uses an I2C address of 2, while the cRIO uses an address of 4. This is intentional. The cRIO code is not complete. It only has pieces that can be added into your own code and prints out error messages if the communication fails. The Arduino code, however, is a complete sketch and "should" work out of the box. Finally, you need to have at least 3 wires between the cRIO and the Arduino for the Clock, Data, and Ground. Omitting a ground wire between the two will cause the communication to fail. If you have (find) any errors, let me know and I will try to fix them. Hope this helps. Mike cRIO Part Code:
import edu.wpi.first.wpilibj.I2C;Code:
#include <Wire.h> |
Re: Use Sidecar I2C port to communicate with Arduino?
Thanks guys! I will post my changed code here as soon as I can. Just in case any of you are curious, the objective of this was to add more lights to my team's robot before IRI. (and if any of you have seen our robot, you probably know we like lights. a lot.)
|
Re: Use Sidecar I2C port to communicate with Arduino?
Thanks to you all, I got the code fixed up. If you guys see any issues in the code, please tell me so I can get them patched up as soon as possible.
Code:
/*REALLY COOL LIGHTS PROGRAM I2C rev 1.3 |
| All times are GMT -5. The time now is 03:05. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi