Pages: [1]   Go Down
Author Topic: Could use a hand with L3G4200D gyro module  (Read 695 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Code:
#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.

Any help appreciated.


Moderator edit: CODE TAGS dammit.
« Last Edit: April 04, 2013, 06:00:13 am by AWOL » Logged

Offline Offline
Faraday Member
**
Karma: 62
Posts: 3080
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Check that the pins you are using are the correct ones for I2C on YOUR type of Arduino.

Check whether the device is a 5V or 3.3V device.  You may have already ruined it.

Run the I2C_scanner sketch to see if it detects the device at all.
Logged

0
Offline Offline
Shannon Member
****
Karma: 220
Posts: 12682
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You say module.  WHICH module?  Is it really 5V compatible?
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Shannon Member
****
Karma: 220
Posts: 12682
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow, thanks! That helps a lot.

>>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.

Thanks
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh, and just FYI - I got the wiring diagram from Parallax. It's on this page:

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

Down at the bottom is the Arduino stuff. Doesn't mention anything about doing something different for I2C to work.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

>>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.

Any chance someone could explain this further?
Logged

Pages: [1]   Go Up
Jump to: