Teensy 3.2 and I2C Gyroscope

Status
Not open for further replies.

Reignable

New member
Hi there.

I've just switched from an UNO R3 to a Teensy 3.2 as I needed the extra analogue capabilities. Upon changing everything over, my ITG-3200 is not getting the same readings that it was getting with the UNO. With the UNO the ADC values were being converted to degrees per second just fine but now with the Teensy I'm getting deg/s in the range of -3000 to 3000 even though the sensor isn't rotating that fast.

I have 4K7 resistors on the I2C lines. I'm using a scale factor of 14.375 for conversion.

Many thanks.

View attachment Gyroscope.cpp
View attachment Gyroscope.h
View attachment crashSensorV3.ino
 
Last edited:
Hi there.

I've just switched from an UNO R3 to a Teensy 3.2 as I needed the extra analogue capabilities. Upon changing everything over, my ITG-3200 is not getting the same readings that it was getting with the UNO. With the UNO the ADC values were being converted to degrees per second just fine but now with the Teensy I'm getting deg/s in the range of -3000 to 3000 even though the sensor isn't rotating that fast.

I have 4K7 resistors on the I2C lines. I'm using a scale factor of 14.375 for conversion.

Many thanks.

as the gyro ADC is inside the sensor and (nearly) independent from the MCU (UNO R3 or Teensy)
the only dependency IMO could be, that you send some uninitialized variable to the ITG that could be different for teensy and UNO.
comparing the values you get from UNO and Teensy you may deduce if you simply set the gyro to a different sensitivity.
I have no UNO and no experience with that hardware, but other typical problems are that 'int' may have different sizes on UNO and Teensy.
 
In this code:

Code:
int Gyroscope::readRaw(char high, char low) {
  int data = 0;
  data = itgRead(itgAddress, high) << 8;
  data |= itgRead(itgAddress, low);
  return data;
}

the variable "data" needs to be defined as "int16_t".

This code happens to work only by mistake on AVR, because "int" is 16 bits. When you combine 2 unsigned bytes with logical or, technically the result should be 0 to 65535. On Teensy LC & 3.2, this is what happens. On AVR, it magically becomes -32768 to 32767 only because the result that should have been 0 to 65535 is stored into a signed 16 bit integer.

To make this work the same on Teensy or any other 32 bit chip, you need to use int16_t. The good news is int16_t also works on AVR, so no special checking is needed for the type of chip once the code is properly updated.

After you get it working, perhaps contact the original author or maintainer of this code and ask them to update it.
 
Status
Not open for further replies.
Back
Top