LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I;m having problems reading from an I2C device

Ok, quick question. First, thanks for the PNG.

 

How did you change the data type in the type case function? I thought it was a string, but yours is not.

 

I tried see how to change it, and it's probably a simple change, but can't.

 

Thanks!

TheLT

0 Kudos
Message 21 of 48
(1,483 Views)

Type Cast defaults to a string, but you can wire other data types. In this case you just place a numeric constant on the block diagram, set its data type (in this case U16), and connect it to the Type Cast function. This tell it to interpret the data coming in (an array of two U8 values) as a U16. It does exactly the same thing as the Join Numbers function.

0 Kudos
Message 22 of 48
(1,469 Views)

smecurio,

 

   Ok, now I see what you're saying. Fixed.

 

  Now, it does spit out some values that still don't make sense even when I looked at the data sheet.

 

  Do you mind if I upload a screenshot of what I am getting?

 

   Thanks!

    TheLT

0 Kudos
Message 23 of 48
(1,467 Views)

As long as you don't upload bitmaps you can upload whatever you want. And don't do the "I'll just change the extension from .bmp to .png to get around the ban on importing bitmaps" thing. Smiley Wink

0 Kudos
Message 24 of 48
(1,459 Views)

Smecurio,

 

  Ok, please see attached configuration per my front panel. I think we are communicating, but I don't know how to decipher what's being said, and I have read the data sheets.

 

  Thanks!
   TheLT

0 Kudos
Message 25 of 48
(1,444 Views)

Ok, so if anyone is still interested in helping out, I updated my code (attached). I also attached the data sheet to this device (MAG3110).

 

Here's the problem I am facing right now. I am reading from the device (I got rid of Read/Write from I2C, just straight read), but it seems to cycle the readings from the device in some type of waveform (image/png of front panel attached). I know the front panel has all zeros in the read data array, but rest assured when it runs I see the data cycle. I do see numbers I swear!

 

So the good news I am reading from it, but how to "calm it down" and make it useful I am stumped.

 

Can someone out there give me any ideas?

 

Thanks!

TheLT

 

 

0 Kudos
Message 26 of 48
(1,416 Views)

@TheLT wrote:

Ok, so if anyone is still interested in helping out, I updated my code (attached). I also attached the data sheet to this device (MAG3110).

 

Here's the problem I am facing right now. I am reading from the device (I got rid of Read/Write from I2C, just straight read), but it seems to cycle the readings from the device in some type of waveform (image/png of front panel attached). I know the front panel has all zeros in the read data array, but rest assured when it runs I see the data cycle. I do see numbers I swear!

 

So the good news I am reading from it, but how to "calm it down" and make it useful I am stumped.

 

Can someone out there give me any ideas?

 

Thanks!

TheLT

 

 


Hi,

 

A quick thing you can test (not sure it fixes the issues you have):

 

ByteOrder.JPG

 

It could be the byte ordering that causes problems, [hi byte lo byte] alternatively [lo byte hi byte].

 

Br,

 

/Roger

 

0 Kudos
Message 27 of 48
(1,416 Views)

@User002 wrote:

@TheLT wrote:

Ok, so if anyone is still interested in helping out, I updated my code (attached). I also attached the data sheet to this device (MAG3110).

 

Here's the problem I am facing right now. I am reading from the device (I got rid of Read/Write from I2C, just straight read), but it seems to cycle the readings from the device in some type of waveform (image/png of front panel attached). I know the front panel has all zeros in the read data array, but rest assured when it runs I see the data cycle. I do see numbers I swear!

 

So the good news I am reading from it, but how to "calm it down" and make it useful I am stumped.

 

Can someone out there give me any ideas?

 

Thanks!

TheLT

 

 


Hi,

 

A quick thing you can test (not sure it fixes the issues you have):

 

ByteOrder.JPG

 

It could be the byte ordering that causes problems, [hi byte lo byte] alternatively [lo byte hi byte].

 

Br,

 

/Roger

 


Or perhaps like this. 

 

ByteSwap.JPG

 

Probably a Rube implementation, could most likely be a simpler way of swapping the bytes in an U8 byte array.

 

Br,

 

/Roger

 

0 Kudos
Message 28 of 48
(1,407 Views)

You need to pay more attention to the data sheet. The memory map for the device is 12 bytes. At startup the address counter is set to zero. If you perform a burst read, where you try to read more than one byte, the address counter gets incremented after each byte. What do you think will happen after you read the 12th byte? Why do you need to read the other bytes anyway? Aren't you just interested in the X, Y, and Z values? These are in bytes 1 through 7. Thus, what is so difficult about using the Read/Write VI with the startng address set to 1 and the number of bytes to read set to 6 and having that in a loop? If you want to you can Type Cast the array of read bytes (6 of them) into a cluster which consists of 3 U16 values:

 

 

Note: If you want to see the data while the loop is running, then the chart/graph needs to be inside the loop. It's easier to use a chart since that has built-in memory.

0 Kudos
Message 29 of 48
(1,392 Views)

All,

 

 Thanks for you responses and I will try them when I am in the lab tomorrow. I just wanted to leave a brief note as a courtesy that I didn't forget this post!

 

   Thanks!

   TheLT

0 Kudos
Message 30 of 48
(1,370 Views)