Welcome to Synthiam!

Program robots using technologies created from industry experts. ARC is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.

Get Started
Asked — Edited

I2c Compass/Accelerometer Lsm303dlh Help

Hi,

I've been playing around with this sensor and I haven't had any luck getting it to work with EZ-Builder. The Script I am using is this:
I2CStart()
I2CRestart()
I2CWrite(0x3C) //write mag
I2CWrite(0x30) //Select register OUT_X_L_M
I2CStart()
I2CReStart()
I2CWrite(0x3D) //read mag
I2CRead(Auto,8)


Even though I get a reading, it never changes I get the same thing until I remove power from it:
I2C Response: 16 32 3 1 211 254 223 0

Some of the data sheets I have been reading:
http://www.pololu.com/file/0J433/LSM303DLH.pdf
http://www.pololu.com/file/0J434/LSM303DLH-compass-app-note.pdf

So far I am batting zero, has anyone else worked with this module before?

I'd appreciate any help with this

AI Support Bot
Related Content
Synthiam
PRO
Synthiam
#1  
I will have to look at the datasheet, but check these things first..

The // is not a valid comment signature. The manual reads that # is used for comments. A year ago, // used to be used, but it has been depricated. Please change your // to # as per the manual.:)

Also, i2c is funny when it comes to the type and length of wire being used. Ensure your wire is short as possible, or add pull-up resistors. I don't feel that is your issue, becuase you are returning some data.

Code:


I2CStart()
I2CRestart()
I2CWrite(0x3C) # write mag
I2CWrite(0x30) # Select register OUT_X_L_M
I2CStart()
I2CReStart()
I2CWrite(0x3D) # read mag
I2CRead(Auto,8)


If I have some time this week, i'll take a look at the datasheets:)
#2  
Thanks DJ, I made the comment changes like you mentioned, I have the wires shorter than 3 inches at this point and I also even tried adding in resistors to the SDA and SDL lines. It's almost like it takes a reading the first time, but after that does not update at all I get the same numbers.
I also noticed something else, the address for this device is 7-bit...... Still reading more docs..
Thanks again
PRO
Synthiam
#3  
Every time you call i2cread or i2cwrite, the data can not be cached by anything EZ-Robot related. The function depends entirely on the data being returned from the i2c interface all the way back to the ARC software. So what you are seeing is indeed the data being returned from the device... However, the data doesn't look correct:) So that means something is not being sent correctly to the device.

Most likely requires some sort of init parameter that isn't being sent.

You are correct about the wire and resistors - I don't agree that is the issue. If it was an issue, you'd be getting no data back. Because you are receiving data, that means the connection is okay:)
#4  
Going through more of the docs, and I was reading the section on just getting readings from the compass:
"default (factory) 7-bit slave address is 00111100b
(0x3C) for write operations, or 00111101b (0x3D) for read operations."

How the hec do I do that with ARC using EZ-Script? Where I want to do a I2CRead I didn't see any options to specify a different address?

Thanks again
#5  
DJ,

After doing more research on this sensor, this is what I have now to test:

:Main
I2CStart()
I2CRestart()
I2CWrite(0x3C, 0x02, 0x00) #Init Mag
I2CStart()
I2CReStart()
I2CWrite(0x3D)
I2cRead(Auto,6)
I2CStop()
goto(Main)

The following are the readings I am getting while the sensor is not moving:
LSM303DLH - Start
LSM303DLH - I2C Response: 0 105 255 47 254 66
LSM303DLH - I2C Response: 0 104 255 56 254 73
LSM303DLH - I2C Response: 0 101 255 46 254 66
LSM303DLH - I2C Response: 0 110 255 48 254 72
LSM303DLH - I2C Response: 0 98 255 44 254 64
LSM303DLH - I2C Response: 0 98 255 44 254 64
LSM303DLH - I2C Response: 0 98 255 44 254 64
LSM303DLH - I2C Response: 0 98 255 44 254 64
LSM303DLH - I2C Response: 0 98 255 44 254 64
LSM303DLH - I2C Response: 0 114 255 46 254 69
LSM303DLH - I2C Response: 0 99 255 47 254 71
LSM303DLH - I2C Response: 0 107 255 54 254 68
LSM303DLH - I2C Response: 0 115 255 47 254 74
LSM303DLH - I2C Response: 0 115 255 47 254 74
LSM303DLH - I2C Response: 0 108 255 49 254 71
LSM303DLH - I2C Response: 0 104 255 48 254 81
LSM303DLH - I2C Response: 0 106 255 40 254 73
LSM303DLH - Stopping
LSM303DLH - I2C Response: 0 106 255 56 254 71
LSM303DLH - Done

When I am turning the sensor clockwise:
LSM303DLH - I2C Response: 255 46 255 241 254 20
LSM303DLH - I2C Response: 255 36 0 16 254 25
LSM303DLH - I2C Response: 255 55 0 66 254 17
LSM303DLH - I2C Response: 255 121 0 109 254 26
LSM303DLH - I2C Response: 255 184 0 136 254 19
LSM303DLH - I2C Response: 255 250 0 155 254 33
LSM303DLH - I2C Response: 0 79 0 165 254 37
LSM303DLH - I2C Response: 0 181 0 103 254 72
LSM303DLH - I2C Response: 0 198 0 56 254 70
LSM303DLH - I2C Response: 0 206 0 1 254 79
LSM303DLH - I2C Response: 0 228 255 206 254 77
LSM303DLH - I2C Response: 0 234 255 149 254 100
LSM303DLH - I2C Response: 0 179 255 87 254 88
LSM303DLH - I2C Response: 0 125 255 50 254 77
LSM303DLH - I2C Response: 0 92 255 40 254 70
LSM303DLH - I2C Response: 0 36 254 254 254 81
LSM303DLH - I2C Response: 255 250 255 1 254 74
LSM303DLH - I2C Response: 255 200 254 254 254 71
LSM303DLH - I2C Response: 255 164 255 0 254 68
LSM303DLH - I2C Response: 255 121 254 252 254 78
LSM303DLH - I2C Response: 255 80 255 27 254 64
LSM303DLH - I2C Response: 255 80 255 38 254 58
LSM303DLH - I2C Response: 255 47 255 54 254 65
LSM303DLH - I2C Response: 255 37 255 85 254 56
LSM303DLH - I2C Response: 255 35 255 99 254 56
LSM303DLH - I2C Response: 255 35 255 99 254 56
LSM303DLH - I2C Response: 255 46 255 89 254 48
LSM303DLH - I2C Response: 255 42 255 95 254 40
LSM303DLH - I2C Response: 255 47 255 100 254 48
LSM303DLH - I2C Response: 255 55 255 94 254 46
LSM303DLH - I2C Response: 255 48 255 91 254 41
LSM303DLH - I2C Response: 0 102 254 208 254 118
LSM303DLH - I2C Response: 0 156 254 251 254 108
LSM303DLH - I2C Response: 0 159 255 3 254 107
LSM303DLH - I2C Response: 0 166 255 11 254 109
LSM303DLH - I2C Response: 0 177 255 28 254 111
LSM303DLH - I2C Response: 0 190 255 21 254 106
LSM303DLH - I2C Response: 0 186 255 28 254 111
LSM303DLH - I2C Response: 0 192 255 24 254 107
LSM303DLH - I2C Response: 0 193 255 38 254 111
LSM303DLH - I2C Response: 0 186 255 42 254 110
LSM303DLH - I2C Response: 0 192 255 37 254 103
LSM303DLH - I2C Response: 0 192 255 48 254 106
LSM303DLH - I2C Response: 0 190 255 35 254 102
LSM303DLH - I2C Response: 0 194 255 50 254 103
LSM303DLH - I2C Response: 0 192 255 41 254 106
LSM303DLH - I2C Response: 0 201 255 46 254 93
LSM303DLH - I2C Response: 0 191 255 52 254 110
LSM303DLH - I2C Response: 0 194 255 52 254 102
LSM303DLH - I2C Response: 0 194 255 51 254 101
LSM303DLH - I2C Response: 0 198 255 57 254 100
LSM303DLH - I2C Response: 0 198 255 43 254 92
LSM303DLH - I2C Response: 0 196 255 55 254 101
LSM303DLH - I2C Response: 0 193 255 53 254 107
LSM303DLH - I2C Response: 0 205 255 58 254 103
LSM303DLH - I2C Response: 0 198 255 50 254 97
LSM303DLH - I2C Response: 0 187 255 54 254 104
LSM303DLH - I2C Response: 0 193 255 56 254 105
LSM303DLH - I2C Response: 0 192 255 55 254 105
LSM303DLH - I2C Response: 0 205 255 56 254 97
LSM303DLH - I2C Response: 0 199 255 65 254 103
LSM303DLH - I2C Response: 0 191 255 62 254 104
LSM303DLH - I2C Response: 0 193 255 57 254 107
LSM303DLH - I2C Response: 0 195 255 64 254 106
LSM303DLH - I2C Response: 0 193 255 64 254 100
LSM303DLH - I2C Response: 0 199 255 58 254 98
LSM303DLH - I2C Response: 0 200 255 50 254 113
LSM303DLH - I2C Response: 0 195 255 64 254 99
LSM303DLH - I2C Response: 0 198 255 58 254 105
LSM303DLH - I2C Response: 0 195 255 67 254 100
LSM303DLH - I2C Response: 0 197 255 65 254 106
LSM303DLH - I2C Response: 0 190 255 63 254 93
LSM303DLH - I2C Response: 0 201 255 63 254 102
LSM303DLH - Stopping
LSM303DLH - I2C Response: 0 193 255 52 254 95
LSM303DLH - Done

Still working on it..
#6  
I have version 2013.06.15.00 of ARC and when I try using the scripting command for I2C it's say Unknown command, I made a copy past of the script in this page and the I2CStart() is not recognize. Have you erase the I2C commands except for the I2Cwrite ?
United Kingdom
#7  
Remove all I2CStart, I2CStop and I2CRestart commands since they no longer exist and are no longer required, the only commands needed are the I2CWrite and I2CRead.

I2C Commands are detailed on Page 4 of the EZ-Script manual.
#8  
Thank you Rich but I suggest you try typping the I2CRead( in the script editor, it's not recognized. In the auto typing aid it will not appear and if you type it manually (and correctly) it will said it's not a valid command.
United Kingdom
#9  
I2C changed a few months ago, I've yet to use I2CRead, I will have a look for the topic in which it was discussed when I get chance.

In the mean time it may be worthwhile to try changing the I2CRead commands to something like $gps=I2CRead(Auto,6) or maybe even $gps=I2CWrite(Auto,6). As far as I know, just using an I2CRead on it's own would be much like using a GetADC or GetPWM without storing it in a variable.