10DOF L3G4200D+ADXL345+HMC5883L+BMP085 Not working?
Vadoo
Posts: 92
I recently purchased a cheap 10DOF board at: http://www.newegg.com/Product/Product.aspx?Item=9SIA2C51450314
I cant get the thing to work. Iv'e tried more programs then I can count. I have been able to get some information from the pressure sensor, but even that is screwy. I thought it was a problem with the module, so I had them send me another one, but I'm getting the same results. I thought I had the gyro and compass working at one point with the first board. I even notated the programs as "working". But after having some success from the pressure sensor, I went back to those "working" programs and got nothing. All "0" or "-1" x y z values.
I'm a bit lost at the moment. I doubt I have two bad modules. It has to be something I'm doing..... Can anyone point me in the right direction?
Thanks!
I cant get the thing to work. Iv'e tried more programs then I can count. I have been able to get some information from the pressure sensor, but even that is screwy. I thought it was a problem with the module, so I had them send me another one, but I'm getting the same results. I thought I had the gyro and compass working at one point with the first board. I even notated the programs as "working". But after having some success from the pressure sensor, I went back to those "working" programs and got nothing. All "0" or "-1" x y z values.
I'm a bit lost at the moment. I doubt I have two bad modules. It has to be something I'm doing..... Can anyone point me in the right direction?
Thanks!
Comments
I greatly appreciate the corrected and notated code. This should help avoid any trouble once that program is able to read data.Right now it is having trouble seeing the device. The method ReadDeviceID seems to be the area of issue. I am getting an "ADXL345 Chip Not Present...Aborting!" message.
I did find another bit of code last night that is able to read from the ADXL345 accelerometer. I have also been able to read from the HMC5883L Compass and the BMP085 Pressure Sensor. I do have problems with some of the information I'm receiving from those devices, but I believe its in my code, not the devices, so I'll come back to that.
What I still can not get any response from is the L3G4200D Gyro. I am attaching some code I am playing with for that. I have spent hours going through the code and the gyro documentation, but it looks right. I think I'm spending too much time on it, and am probably overlooking something simple...
I notice that this object and the ADXL345 object both include their own I2C driver methods and use the same I2C pins. If you're running all of these objects simultaneously they could well be interfering with each other on the bus.
There are numerous stand-alone I2C object in the obex, including a couple in my sig. Just call the appropriate method in the I2C object and use the returned data in your main routine.
I had another thought about the Read2byte method; just juse Mike Green's existing methods like so: As for why your demo isn't seeing it, the demo is trying to address the module at device ID $53, which requires the ALT address pin to be grounded, so that's where I'd check next.
Included in the I2C routines in my sig is a I2C poller that returns the 7-bit address of everything on the bus.
Too funny!
I first tried this by changing only the scl, sda pins to 26 and 27. I then tried a few other things but cant get anything out of it. I also tried the gyro demo with no luck. It seems to get stuck somewhere.
I like the idea of a polling routine. That seems to be the simplest way of verifying what I have works. At this point I'm starting to wonder if I have two bad boards??
Okay, try this poller based on Mike Green's routines. My I2C routines require pull-ups on both the SDA and SCL lines, whereas Mike's routines drive them high, so I figure this is at least worth a shot.
Poller - Archive.zip
The good news is I did get a reply from this one!
The bad news is I only got three replies....
Device found at 0011110
Device found at 1101001
Device found at 1110111
Finished
I have not looked to see what the addresses are yet, but I'm betting its all but the gyro. I'll check the data sheets in a few..
Thanks!
HMC5883L=1E 00011110 (which I received)
L3G4200D=D2 1101001 (which I received) This is the Gyro. It lives???
ADXL345= E5 11100101 (NOT RECEIVED) ???
BMP085= EF or EE 1110111 (I think I got an EE, not sure since the bin is 7 digits. I tried adjusting the code but it put a 0 at the front not the back where it should be)
There are a couple solutions to that one, either put pull-up resistors on the SDA and SCL lines, or use an I2C driver that drives the SDA and SCL lines high and low.
I'll try playing with this and see what happens shortly.
So here's what I'm working on now in an attempt to communicate with the Gyro:
So far all I get out of it is (x: 255).
Here's the code:
Here's the response:
sak1: 00
sak2: 01
sak3: 01
sak4: 00
sak5: 01
sak6: 00
data: FF
All is as expected but the data being returned.
What is not expected, I get the same reply when the SCL is disconnected. I do get all 0's when the SDA is disconnected.
This is more of that 7-bit / 8-bit device ID confusion. You already have the 8-bit address $D2 defined for write, and $D3 defined for read, so you don't need to shift any. Try it again without the << 1.
Alternately, use the 7-bit address defined in DeviceID ($69), with a << 1 for write, and a << 1 | 1 for read.
Also, you're trying to read register $28 << 1, which is register $50, and the datasheet doesn't mention what lives there.
Register $28 is the low-byte of the gyro X-axis, however LG4200 is non-standard in that in order to read consecutive bytes, the msb must set.
In order to read consecutive registers starting from $28 (%0010_1000), you need to address $A8 (%1010_1000).
I just went back to the Gyro documentation and this makes sense now.
"The 7 LSb represent the actual register address while the MSB enables address auto-increment. If the
MSb of the SUB field is 1, the SUB (register address) is automatically incremented to allow
multiple data read/write."
I looked at it on a logic analyzer, and sure enough it was trying to write to $A4, which was not being acknowledged by anything on my board.
I did eventually manage to get the following code to at least show some activity when gyro was jostled.
I don't at all understand why both bytes needed to be ACK'd, but without that all I got were static readings.
And I'm also not at all sure why Mike's driver is working when no others are. I've modified my driver to drive SCL and SDA high and low, as the pull-up resistors are really the only non-standard thing I see about his driver.
Gyroscope demo - Archive.zip
Now for the rest of my troubles
I'll get to the specifics once I have a chance to wrap my brain around the solution to this problem. But ultimately I would like to write a program to read all values from this board to share with everyone, as it seems to have become a popular board (at least with the Audrino community) and should probably be equally supported here!
But this seems to be the key: Though I don't understand some of the characters and what they are doing, it seems its waiting for a change in the x, y, z values before reading them.
Bit 7 in register $23 I believe ensures that when you perform a multi-byte reading, as in reading the high-byte and low-byte of a sample, both bytes come from the same sample... I think.
$1F written to register $20 sets the bandwidth, sets normal mode or sleep mode, and enables the three axis.
Bit 8 in register $27 is, as you figured, set when new data is available to be read.
Oh, and as for the acknowledgements that you were seeing when addressing $D2 << 1, the SDA line is pulled low to indicate ACK, or left floating (pulled up high) to indicate a NAK, so a '1' returned is NAK, '0' returned is ACK.
I'm also having problems with the accelerometer. I can't figure out how to read anything from it yet.
I'll attach "10DOF" which reads from the Gyro and Compass. It then tries to read from the accelerometer, but seems to only loop through (repeat) one time then lock up. The data it puts out for the accel is 65535 for x, y and z. This is the object I'm building for reading everything from the 10DOF.
I'll also attach "ADXL3450ObjectDemo", a functional program that is able to read from the accelerometer. I can't figure out what its doing that I'm not.