Go Down

Topic: I2C - Analog (Read 975 times) previous topic - next topic

dmen

I have been trying for some time now to get any sort of data from a gyro module. I posted a message earlier specifically about the l3g4200d module, but I think the question is probably not specific to the module, so I am starting a new thread.

So, I need to communicate on I2C, at least that what all the example show. I have a readI2C method like so:

Code: [Select]
int readI2C (byte regAddr) {   
    Wire.beginTransmission(Addr);
    Wire.write(regAddr);                // Register address to read
    Wire.endTransmission();          // Terminate request
   
    Wire.requestFrom(Addr, 1);          // Read a byte
   
    while(!Wire.available()) { };
    return( Wire.read() );
}


I have seen numerous examples just like this. However the while loop runs forever and I get no return. I was starting to think the gyro module was bad...

So, I tried to read data using analogRead just to see if there was anything.

I am getting values reading pins A4 and A5, which are hooked to SDA/SCL respectively. As I move the gyro the analog values change, so I assume the thing is working. I just need to be able to read the proper registers to get x,y,z data...

Anyone know why waiting for Wire.available() would hang?

thanks

michinyon

It will "hang" if it never gets a response.

First thing to do,  is run the i2C_scanner  sketch  and check that the device is
present and responding at the i2C address which you expect.

Next thing is to check you have done the right thing with the voltages, if necessary.

AWOL

Quote
I am getting values reading pins A4 and A5, which are hooked to SDA/SCL respectively. As I move the gyro the analog values change

Are you saying you're doing "analogRead" on A4 and A5?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

dmen

Yes, I was doing analogRead(A4) or A5 and getting changing values in the 500 or so. I was just trying to get something is all.

I tried the i2c scanner and got nothing. Based on a couple of replies in my other thread I think I can get it worked out though. I seem to not have things hooked up quite right for i2c to work. I'll continue this in that thread, so I don't have two conversations going about the same thing. I just wasn't sure, so I had two threads. That other one is 'could use a hand with l3g4200d gyro module'.

Thanks much.

AWOL

Quote
Yes, I was doing analogRead(A4) or A5 and getting changing values in the 500 or so. I was just trying to get something is all.

Waste of time.

Have you got external 4k7 pullups on the I2C lines?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

dmen

>>Have you got external 4k7 pullups on the I2C lines?

No, nothing I've read has mentioned anything like that. In fact the doc from Parallax's website shows the wiring diagram as so:

http://learn.parallax.com/KickStart/27911

Arduino at the bottom. It has the i2c stuff in the code and just has the 4 wire hookup I did.

AWOL

OK, the datasheet says the level shifters have built-in pullups.
However, that rather begs the question - "Why were analogReads only returning around half the supply voltage?"
(A schematic would be useful, Parallax)
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

dmen

OK, cool, at least I know I don't need to worry about that. Now I just need to find out how to get I2C working properly.

dmen

There is a documentation pdf here:
http://www.parallax.com/portals/0/downloads/docs/prod/sens/27911-GyroscopeL3G4200D-v1.0.pdf

It states the device operates by default in i2c, and shows the simple 4 wire hookup as well... frustrating.

rgallant

Are you sure the device address is correct ?  There is an alternate IC2 Lib you can use http://dsscircuits.com/articles/arduino-i2c-master-library.html

This one a a bus scan function built in.  It might help.

dmen

I believe the 105 is correct, but the i2c scanner sketch is not finding it and it tries 105, so I'm really not sure. Anyone offer any suggestions? Could the gyro be defective? Based on their docs, and other sources it seems everything is hooked up properly.

dmen

A MarkT in a different thread said this:

The CS pin (pin 3) must be held logic-HIGH to use I2C mode - if you don't do this is probably won't work (datasheet isn't
clear on this)

Check SDA is connected to pin 5 and SCL to pin 4.  Tie pin 6 low via a 1k resistor to ensure consistent I2C addressing
BTW.


Could anyone offer up and more explanation on this - I'm just not clear on what he meant there.

rgallant

If the IC2 scanner finds no devices, then either the power is no good ie the gryo is not powered or your connections are incorrect.

Does the IC2 scanner find any devices ?

dmen

No, it doesn't find anything - though the gyro is the only thing connected to the Arduino.

I think Power is fine - if I measure power at the gyro, I get 5.08, or 3.30 on my multimeter, depending on which voltage I connected to from the Arduino. I have 5V from the Arduino connected to VIN on the gyro, ground to ground, pin 4 to SDA and pin 5 to SCL.

Go Up