View Single Post
  #6   Spotlight this post!  
Unread 23-01-2014, 22:58
randantor randantor is offline
Registered User
AKA: James Y
FRC #0624 (CRyptonite)
Team Role: Alumni
 
Join Date: Jun 2013
Rookie Year: 2012
Location: Katy, TX
Posts: 48
randantor is a glorious beacon of lightrandantor is a glorious beacon of lightrandantor is a glorious beacon of lightrandantor is a glorious beacon of lightrandantor is a glorious beacon of lightrandantor is a glorious beacon of light
Re: Arduino with LabVIEW

You can find the I2C VIs under the "communications" section of the WPILib palette.

Using I2C between an arduino and LabVIEW is ...odd to say the least. It's pretty poorly documented and there are pitfalls that can cost you a lot of time just trying to get it to work. The library is set up for i2c sensors, so it has this concept of "registers".

Basically when writing to a device, you give it a "register address", which is actually just a byte that is sent before the rest of the data. For example if you told LabVIEW to send the bytes 0xFF 0xFF to register 0x01, the data that would actually be sent would be [0x01, 0xFF, 0xFF]. If you are writing to an arduino, you can treat the register as just a slot for the first byte. Additionally, you can only send 8 bytes (the register byte and 7 data bytes) at a time. Any extra bytes passed to the write VI are silently discarded.

When reading from a slave, there is again a "register". This time it is a byte array that is sent to the i2c slave right before reading from it. I believe you can simply pass it a 0-length array if you don't want to send any data before reading, though I haven't tried it.

A major thing to be aware of is the fact that an i2c address set on an arduino needs to be shifted one bit to the left when set on the cRIO. For example, in your arduino code, you have the address set to 2; you will need to set it to 4 on the cRIO code if you want them to actually communicate.

When writing to an arduino slave, you should set "CompatibilityMode" to true.

I noticed your adruino code also sent 6 bytes to the cRIO. It seems the cRIO is only capable of reading 4 bytes at a time, so you should be aware of that.
Reply With Quote