LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading I2C in LabVIEW

Hey all, I'm having a really difficult time understanding how to read from an I2C to USB converter. I have my device hooked up right, because it works perfectly with the company's OEM reading software. I cannot get the device to read in LabVIEW, however. Here's some info on the product I'm using, the Sensirion SFM3000: http://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/GasFlow/Sensirion_Gas_F...

 

My biggest questions I suppose:

 

How can I create a 16-bit array?

How can I send an unsigned 16-bit array to the device while the VISA/I2C VI's only allow 8 bits?

How can I get LabVIEW to read the returned array?

 

Thank you!

0 Kudos
Message 1 of 5
(4,988 Views)

I2C uses 8-bit register sizes.  Therefore all commands and responses will be in terms of 8 bits.  You seem to be confused by this point.  You can see this demonstated on page 3 of the manual for your device:

 

data.JPG

 

So you will send one set of 8 bits, wait for acknowledge, send another set of 8 bits.  Similarly you will read 8 bits, send an acknowledge, and then read 8 more bits.  (And if you want the CRC, send another acknowledge and read 8 more bits).

 

EDIT:

 

To more specifically answer your questions:

 

1. How can I create a 16-bit array?

 

A. You really need 2, 8-bit values.  You can either make two arrays of booleans (size = 😎 and make each one a bit.  Or use an 8-bit integer and just enter the entire value in decimal/binary/octal/hex depending on how you choose to represent it in LabVIEW properties for the numeric constant.

 

2. How can I send an unsigned 16-bit array to the device while the VISA/I2C VI's only allow 8 bits?

 

A. I don't have the time to help you more specifically, but this should show you how to set it up and send data over VISA: http://www.ni.com/white-paper/4478/en/

 

I also would see this thread (specifically the second post): http://forums.ni.com/t5/LabVIEW/I2C-implementation-using-Labview/td-p/558366

 

3. How can I get LabVIEW to read the returned array?

 

A. You will also use VISA to read from your device.  Again, you should read two 8-bit values.  You will probably have to do some bit-banging here to extract the actual values.

 

Note:  I've also never used VISA to do this.  I have used other methods.  So perhaps someone with more specific info can answer the VISA side of things more specifically.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
Message 2 of 5
(4,979 Views)

Thanks, this makes sense! I'm still lost on how to actually send/recieve the bits - I know that I'll be using the I2C write/read VI's (duh) but how can I configure the bits themselves?

 

and another issue - I usually can't get my device to show up on the list of serial devices even though it's connected to the COM4 port. Do you have any idea why?

0 Kudos
Message 3 of 5
(4,974 Views)

What Mr Happy says is true, but the thing to remember is that once you put the I2c to USB converter in the mix, as far as LV is concerned, it's just another serial device so all you are ever really sending is a series of U8 values in the form of a string. Unless it has been changed in recent years, the internal representation in LV for an array of U8s and a string are exactly the same.

 

In terms of the 16-bit values, the documentation on the device should tell you the expected byte order so you may only need to cast the array to a string and you're done.

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 4 of 5
(4,969 Views)

@hineybush wrote:

Thanks, this makes sense! I'm still lost on how to actually send/recieve the bits - I know that I'll be using the I2C write/read VI's (duh) but how can I configure the bits themselves?

 

and another issue - I usually can't get my device to show up on the list of serial devices even though it's connected to the COM4 port. Do you have any idea why?


See my edit.  I've never done this specifically using VISA, but VISA should allow you to treat the USB device like any serial device.  Which VIs are you referring to?

 

Are you on Windows?  Does it show up in the Device Manager?  I would guess it may be a driver issue.  Which seems strange if you had it working with the OEM software (or did it sometimes not show up for that as well?)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
0 Kudos
Message 5 of 5
(4,968 Views)