0
\$\begingroup\$

I have an Arduino Uno, an Arduino Nano, a Teensy 3.0 and a 3-axis gyroscope (L3G4200D module from Parallax http://www.parallax.com/StoreSearchResults/tabid/768/txtSearch/gyroscope/List/0/SortField/4/ProductID/778/Default.aspx)

When I hook up the Arduino Nano or Arduino Uno to the gyroscope and use the sample code provided at the bottom of this page, it works great: http://learn.parallax.com/kickstart/27911

I get the readings I expect from the gyroscope.

When I hook up the same gyroscope to my Teensy 3.0, I get readings... but they aren't quite right. Instead of reading (x, y, z) 0, 0, 0 at rest, it will read 574, 0, 574. Sometimes 574, 0, 0, and sometimes 574, 574, 574.

When I move the module around, though, the numbers read closer to what I would expect from the Arduino boards.

I'm still very new to hardware. I understand some of the basics, and I know enough to make sure I have all the right wires plugged in to the right pins, etc. I'm sure there is something in the sample code that I'm using causing the problem - after all, this is arduino sample code that I'm using with a teensy...

I'm coding in the Arduino IDE w/ the TeensyDuino add-on. I have the board configured correctly in the Arduino options, of course.

Does anyone have any idea why my X and Z axis are reading 574 most of the time? What do I need to do to fix this?

[EDIT]

Per comment requests, here are images of my setup.

The Teensy setup: http://cl.ly/image/0E3R0x380d3R

The Arduino Nano setup: http://cl.ly/image/2S1J03123L16

As you can see, the setup is the same - just putting the pins in the right place for the controller I'm using. The Nano produces the correct results, while the Teensy does not.

[EDIT]

Would the Arduino being 16 bit while the Teensy being 32 bit cause problems? Do I need to adjust the math to calculate the two's complement differently? Use different variable types to store the resulting information? Or am I thinking wrong on this path?

\$\endgroup\$
  • \$\begingroup\$ Are you using the correct voltage levels for both parts? Teensy3 uses 3v3 IO voltage while I believe Uno is 5v, not sure if that would be a problem. \$\endgroup\$ – Tim May 9 '13 at 5:10
  • \$\begingroup\$ You use the same sketch for both Uno, and Teensy? \$\endgroup\$ – jippie May 9 '13 at 8:41
  • \$\begingroup\$ How do you power the sensor, are there some decoupling capacitors in place? Maybe a picture of both setups gives us a clue. \$\endgroup\$ – jippie May 9 '13 at 8:42
  • \$\begingroup\$ The Teensy is 3.3v and the Undo is 5v but also has a 3.3v output. The gyroscope module accepts input voltage from 2.7v to 6.5v. I've run the gyroscope from my uno, unsing the 3.3v settings and it works just fine. Voltage shouldn't be the problem. The gyroscope module has a voltage regulator built in to it. \$\endgroup\$ – Derick Bailey May 9 '13 at 12:15
  • \$\begingroup\$ Yes, I'm using the same sketch for both the Uno and the Teensy. I've got the wires all connected to the same, and correct pins. The Teensy pin diagram confirmed that pin 4 & 5 are use for the I2C communication, the same as the Uno and Nano \$\endgroup\$ – Derick Bailey May 9 '13 at 12:16
2
\$\begingroup\$

I figured it out.

The problem was in the 32bit vs 16bit architecture of the Teensy vs Arduino boards. In a 32 bit environment, an int is 32 bits. In a 16bit environment, an int is 16 bits. At least, that's what I'm seeing in Teensy (32bit) vs Arduino (16bit). This makes a difference in the bit shifting / 2's complement calculation done for the X, Y, and Z values.

When I change the data types from int x, y, z; to short x, y, z; in my Teensy sketch, it gives me the correct reading for the values.

\$\endgroup\$
  • \$\begingroup\$ You might want to take a look at stdint.h so you can use types like int16_t that will be more portable across platforms. \$\endgroup\$ – PeterJ May 10 '13 at 2:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.