Hi
I have been attempting to connect a L3G4200D Parallax gyroscope to the Arduino Due. I tried the following pin connections:
Gyro-->Due
SCL-->Pin 21(SCL)
SDA-->Pin 20(SDA)
Vin--> 5 V
GND--> GND
and the following code (the one provided by parallax for arduino)
#include <Wire.h>
#define CTRL_REG1 0x20
#define CTRL_REG2 0x21
#define CTRL_REG3 0x22
#define CTRL_REG4 0x23
int Addr = 105; // I2C address of gyro
int x, y, z;
void setup(){
Wire.begin();
Serial.begin(9600);
writeI2C(CTRL_REG1, 0x1F); // Turn on all axes, disable power down
writeI2C(CTRL_REG3, 0x08); // Enable control ready signal
writeI2C(CTRL_REG4, 0x80); // Set scale (500 deg/sec)
delay(100); // Wait to synchronize
}
void loop(){
getGyroValues(); // Get new values
// In following Dividing by 114 reduces noise
Serial.print("Raw X:"); Serial.print(x / 114);
Serial.print(" Raw Y:"); Serial.print(y / 114);
Serial.print(" Raw Z:"); Serial.println(z / 114);
delay(500); // Short delay between reads
}
void getGyroValues () {
byte MSB, LSB;
MSB = readI2C(0x29);
LSB = readI2C(0x28);
x = ((MSB << 8) | LSB);
MSB = readI2C(0x2B);
LSB = readI2C(0x2A);
y = ((MSB << 8) | LSB);
MSB = readI2C(0x2D);
LSB = readI2C(0x2C);
z = ((MSB << 8) | LSB);
}
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()) { }; // 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();
}
The output in the serial window for this code was strange. I seemed to get reasonable rates when i rotated the gyro in the CCW direction but when rotated CW, instead of getting a negative rate i got something in the rage of 500-600 deg/sec. I posted about this problem on the parallax forums and they told me that i might have damaged my board due to the sensor being powered by the 5V pin. I knew that the Due I/O pins were not 5V tolerant but I had no idea this rule applied to the 5V pin itself. So I come to my question, have I fried my board?
P.S The sensor itself is fine, i checked it with an Uno