I've been building an IMU for the past couple days that uses the i2c ITG-3200. The ITG operates @ 3.3v so I used a logic converter for the two communication lines. The problem I am having is reading the values from the ITG. When I open up the serial port, The only values that I get back are 0. I just used the stock ITG example code from spark fun:

Load the sketch and open the serial window at 9600 bps. Arduino will output the raw X,Y and Z axis data being read from the gyroscope.

*/

//The Wire library is used for I2C communication#include <Wire.h>

//This is a list of registers in the ITG-3200. Registers are parameters that determine how the sensor will behave, or they can hold data that represent the//sensors current status.//To learn more about the registers on the ITG-3200, download and read the datasheet.char WHO_AM_I = 0x00;char SMPLRT_DIV= 0x15;char DLPF_FS = 0x16;char GYRO_XOUT_H = 0x1D;char GYRO_XOUT_L = 0x1E;char GYRO_YOUT_H = 0x1F;char GYRO_YOUT_L = 0x20;char GYRO_ZOUT_H = 0x21;char GYRO_ZOUT_L = 0x22;

//This is a list of settings that can be loaded into the registers.//DLPF, Full Scale Register Bits//FS_SEL must be set to 3 for proper operation//Set DLPF_CFG to 3 for 1kHz Fint and 42 Hz Low Pass Filterchar DLPF_CFG_0 = (1<<0);char DLPF_CFG_1 = (1<<1);char DLPF_CFG_2 = (1<<2);char DLPF_FS_SEL_0 = (1<<3);char DLPF_FS_SEL_1 = (1<<4);

//I2C devices each have an address. The address is defined in the datasheet for the device. The ITG-3200 breakout board can have different address depending on how//the jumper on top of the board is configured. By default, the jumper is connected to the VDD pin. When the jumper is connected to the VDD pin the I2C address//is 0x69.char itgAddress = 0x69;

//In the setup section of the sketch the serial port will be configured, the i2c communication will be initialized, and the itg-3200 will be configured.void setup(){ //Create a serial connection using a 9600bps baud rate. Serial.begin(9600);

//Initialize the I2C communication. This will set the Arduino up as the 'Master' device. Wire.begin();

//Configure the gyroscope //Set the gyroscope scale for the outputs to +/-2000 degrees per second itgWrite(itgAddress, DLPF_FS, (DLPF_FS_SEL_0|DLPF_FS_SEL_1|DLPF_CFG_0)); //Set the sample rate to 100 hz itgWrite(itgAddress, SMPLRT_DIV, 9);}

//The loop section of the sketch will read the X,Y and Z output rates from the gyroscope and output them in the Serial Terminalvoid loop(){ //Create variables to hold the output rates. int xRate, yRate, zRate;

//Wait 10ms before reading the values again. (Remember, the output rate was set to 100hz and 1reading per 10ms = 100hz.) delay(10);}

//This function will write a value to a register on the itg-3200.//Parameters:// char address: The I2C address of the sensor. For the ITG-3200 breakout the address is 0x69.// char registerAddress: The address of the register on the sensor that should be written to.// char data: The value to be written to the specified register.void itgWrite(char address, char registerAddress, char data){ //Initiate a communication sequence with the desired i2c device Wire.beginTransmission(address); //Tell the I2C address which register we are writing to Wire.write(registerAddress); //Send the value to write to the specified register Wire.write(data); //End the communication sequence Wire.endTransmission();}

//This function will read the data from a specified register on the ITG-3200 and return the value.//Parameters:// char address: The I2C address of the sensor. For the ITG-3200 breakout the address is 0x69.// char registerAddress: The address of the register on the sensor that should be read//Return:// unsigned char: The value currently residing in the specified registerunsigned char itgRead(char address, char registerAddress){ //This variable will hold the contents read from the i2c device. unsigned char data=0;

//Wait for a response from the I2C device if(Wire.available()){ //Save the data sent from the I2C device data = Wire.read(); }

//End the communication sequence. Wire.endTransmission();

//Return the data read during the operation return data;}

//This function is used to read the X-Axis rate of the gyroscope. The function returns the ADC value from the Gyroscope//NOTE: This value is NOT in degrees per second. //Usage: int xRate = readX();int readX(void){ int data=0; data = itgRead(itgAddress, GYRO_XOUT_H)<<8; data |= itgRead(itgAddress, GYRO_XOUT_L);

return data;}

//This function is used to read the Y-Axis rate of the gyroscope. The function returns the ADC value from the Gyroscope//NOTE: This value is NOT in degrees per second. //Usage: int yRate = readY();int readY(void){ int data=0; data = itgRead(itgAddress, GYRO_YOUT_H)<<8; data |= itgRead(itgAddress, GYRO_YOUT_L);

return data;}

//This function is used to read the Z-Axis rate of the gyroscope. The function returns the ADC value from the Gyroscope//NOTE: This value is NOT in degrees per second. //Usage: int zRate = readZ();int readZ(void){ int data=0; data = itgRead(itgAddress, GYRO_ZOUT_H)<<8; data |= itgRead(itgAddress, GYRO_ZOUT_L);

return data;}

I checked with my oscilloscope that the signals are being converted properly and that the ITG was wired correctly. Does anyone know if there are any differences with the leonardos i2c than the other arduinos, or what my issue could be? Thank you.

How have you wired the the module to the Leonardo? Are you aware that the Leonardo doesn't have the SDA and SCL on A4/5, because that's mentioned in the code? The Leonardo has separate pins labeled SDA and SCL for that.

The level converter isn't necessary with I2C, pullups to 3V3 should be enough.

I checked the data sheet for the atmega32u4 and double checked the wiring. It's connected correctly. I have the pull-ups enabled. Do you think That because the level converter isn't necessary it's causing problems with the signal?

Thanks Erdin for the reply, I just uploaded the code and ran it through a test. I got one address back(0x3C). But, I have a total of four i2c devices on the circuit board. Shouldn't I be receiving an address from them as well? If so I must be having some problem reading those three sensors?

Okay I must be having some issues with the sensors for I am still only getting back the one address. I'm going to work on the board a little and get back to you with an update in the next couple hours. LMK if you think of anything else.

I checked the data sheet for the atmega32u4 and double checked the wiring.

Wo where did you connect the I2C then? You should have checked the schematics of the Leonardo, the datasheet of the ATmega32U4 does make sense when you know where the Leonardo pins are routed to. Again: show us your wirings!

Quote

I have the pull-ups enabled.

What does that mean? Do you have the internal pull-ups enabled?

Quote

But, I have a total of four i2c devices on the circuit board.

What devices are on the circuit board then? We know of exactly one yet. Are all 3V3 devices or do you have 5V devices too?