LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

i2c

Hello everyone,

I am starting to use sensors that use both i2c and SPI.  i need a little direction on how to use these two methods.  i2c the biggest issue im having is how do i get the ip address of the sensor im using.  how do i find that?  Thanks for the help everyone.

0 Kudos
Message 1 of 10
(6,067 Views)

I2C devices don't use IP addresses but they do use something similar.  It is a 7 bit number that is accompanied by a read/write bit.  The datasheet for the sensor will have this 7-bit number listed somewhere.  Typically, they have will have two address that differ by the least significant bit (LSB) of the 7-bit address.  Often, this is controlled by connecting one of the pins to Vcc or GND.  Not all breakout boards give you access to this pin and have the address 'hardcoded'.

0 Kudos
Message 2 of 10
(4,281 Views)

ok. this is the sensor from adafruit in trying to use.

https://www.adafruit.com/products/2021

0 Kudos
Message 3 of 10
(4,281 Views)

Is there another question that you have?

0 Kudos
Message 4 of 10
(4,281 Views)

http://www.adafruit.com/datasheets/LSM9DS0.pdf

this is the datasheet.  I guess what my question is because ive never used this before its a bit overhelming.  I found in section 6.1 in this thing info in the address, however there seems to be info in high and low and binary and a million other things.  Is there some reference you know of where i can read about which i should use and/or how to use it?

0 Kudos
Message 5 of 10
(4,281 Views)

Yeah, datasheets can be very confusing to read sometime especially when you are not used to the format.  I even get confused on some datasheets even after reading a bunch of others.  One good way to start with a sensor in LIFA or LINX is to find an existing (working) Arduino library/example code.  It helps so that you don't need to decipher the datasheet because all you need to do is port the Arduino code to LabVIEW.

For this device, there are two different addresses.  One address is for the accelerometer and magnetometer and the other is for just the gyro output (it is two I2C devices in one).

Looking at the code provided by Adafruit, you can see the addresses that should be used with the I2C functions.  Those are the addresses that you'll want to use with the I2C LIFA/LINX VIs.

0 Kudos
Message 6 of 10
(4,281 Views)

ok so i think i was able to figure out the addresses at least a little, however i was going to try a loop structure and find the exact addresses that way.  it looks like if i2c.vi in labview uses a 8 bit address, 0-255 so i was going to just try all in a loop and see what i get a responce from, however, when it gets to the read i2c,vi i get a 5003 error.  i was a simple int, to the int(i2c) and then a read i2c and i get the error when it goes to the read.  any thoughts?

0 Kudos
Message 7 of 10
(4,281 Views)

You don't need to search for the address, both addresses are shown in the example Arduino code.

The I2C Read VI will always timeout if you tell it to get more bytes than are actually being transmitted back.  You can look at the official error documentation to see other possible reasons.

0 Kudos
Message 8 of 10
(4,281 Views)

Youll have to forgive me,  i looked at the example, and it looks like the use SPI not i2c, so i didnt see the address for it.  I used the datasheet and converted the HEX to an 8bit but what i found want some shared the same number... is this common?

Also for the arudino i2c vi.  i have no idea what to put for the bytes to read.  I know each high low number from the DOF of the gyro is a 16 bit number but i dont understand what the vi is asking for.

0 Kudos
Message 9 of 10
(4,281 Views)

That particular sensor can be used with SPI or I2C.  So, you get to choose which one you want to use.

If you ask it for a value that is 16 bits then you need to read 16 bits.  So, given that 1 byte is 8 bits, 16 bits is 2 bytes.  HOWEVER, there are some things that need to be understood about this specific device before you can get it to read back more than a single byte.  This device requires that the MSb (the Most Significant bit) of the register address (referred to as the sub-address or SAD in the text of the datasheet) be set to 1 if you want to read more than a single byte back in a single "read operation" (a write and a read).

In fact, this is very similar to the device that I once worked with for which I created a library.  I would recommend that you take a look at how I do it there.  You could probably even go in and just modify the parts that are different and save the library as a new one.  Note that not all the register addresses are the same.

If you have issues, let me know.

0 Kudos
Message 10 of 10
(4,281 Views)