
charleybot
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
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:
If I have some time this week, i'll take a look at the datasheets
I also noticed something else, the address for this device is 7-bit...... Still reading more docs..
Thanks again
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
"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
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..
I2C Commands are detailed on Page 4 of the EZ-Script manual.
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.