Been trying on and off for a couple days to get any data from this module and have had no luck. Really hoping someone might be able to help. I'm using an Arduino Micro and have it connected to the gyro as follows:
GND > GND
5v > VIN
A4 > SDA
A5 > SCL
Following is the code, sorry if it's too long - I pared it down a bunch, currently I'm trying to just see the X axis.
#include <Wire.h>
int Addr = 105; // I2C address of gyro
int x, y, z;
void setup(){
Wire.begin();
Serial.begin(9600);
writeI2C(0x20, 0x1F); // Turn on all axes, disable power down
writeI2C(0x22, 0x08); // Enable control ready signal
writeI2C(0x23, 0x80); // Set scale (500 deg/sec)
delay(100);
}
void loop(){
getGyroValues();
Serial.print("Raw X:"); Serial.print(x / 114);
delay(500);
}
void getGyroValues () {
byte MSB, LSB;
MSB = readI2C(0x29);
LSB = readI2C(0x28);
x = ((MSB << 8) | LSB);
}
int readI2C (byte regAddr) {
Serial.print("readI2C");
Wire.beginTransmission(Addr);
Wire.write(regAddr); // Register address to read
Wire.endTransmission(); // Terminate request
Wire.requestFrom(Addr, 1); // Read a byte
//while(!Wire.available()) { }; // Wait for receipt
return(Wire.read()); // Get result
}
void writeI2C (byte regAddr, byte val) {
Wire.beginTransmission(Addr);
Wire.write(regAddr);
Wire.write(val);
Wire.endTransmission();
}
If I uncomment the while in the readI2C method I never get any output in serial monitor.
Thanks! I ran the scanner sktetch and I get "no I2C device found". So, obviously that's a problem. The gyro module is the Parallax l3g4200d and it states an operating voltage of 3 - 6.5vdc. Probably, that is not the issue though - the i2c is. Just so much reading to go through, various boards etc, makes it tough for a newbie to figure this stuff out... at least I'm getting closer though.
That board has level shifters on all the pins so it is fully 5V compatible. It also has built-in pull-ups so no external pull-ups
are required (usually needed for I2C, note).
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.
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
Tie pin 6 low via a 1k resistor to ensure consistent I2C addressing BTW.
Sorry, I'm quite new to electronics and this doesn't make a whole lot of sense to me yet. When you say pin 6 - do you mean analog pin 6 on the micro - A6? Tie that to CS with a 1K resistor?
I did see a different wiring diagram that used 3.3v and that went to both VIN and CS... but there was no resistor in there.
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
Tie pin 6 low via a 1k resistor to ensure consistent I2C addressing BTW.