Teensy 3.0 driving 9-DOF accelerometer?

Status
Not open for further replies.

kwaegel

Member
Hi everyone. I'm looking to use a Teensy 3.0 as a USB driver for a 9-DOF sensor chip, but I don't have much experience in electronics. Are there any pitfalls I should look out for?

I'm planning on using a MPU-9150 IMU with a breakout board:
11486-01.jpg

It communicates over I2C, so I assume it would be fairly straightforward to set up if I use the Wire library.
 
That example code might be based on Jeff's original 6050-based code. FreeIMU uses that same code. It had a couple 16 bit integer assumptions which were fixed (places where "int16_t" needs to be used rather than "int", which is 16 bits on AVR and 32 bits on ARM).

I seem to recall the main problem was the getMotion6 function... I just looked at Sparkfun's code and it seems to have those fixes. Of course, I don't have this Sparkfun board, so I can say for sure. If you do run into problems, just post here....
 
For anyone else interested, the Arduino example code from SparkFun works out of the box. I only needed to connect the gnd, vcc, sda, and scl pins.
 
FreeIMU also runs, but required some work. As Paul suggested, several of the sketches had to be modified to work with the change from 16 to 32-bit integers. The code to handle magnetometer data also had to be changed, since the 9150 just uses a single getMotion9() call.

I'd be interested in merging the changes with the FreeIMU trunk, but I'm not sure who (if anyone) is managing that project now.
 
Hi,
I am a newbie. I need help with MPU 9150.
I am trying to read data from an MPU 9150 as well using arduino pro mini 3.3 v. But my sampling rate is only 18 millisecond. Please could tell me what is the sampling rate with Teensy 3.0. I plan to use in the near future. Does the spark fun code work with Teensy 3.0 for MPU 9150 without any major changes. Please let me know.
 
Thank you

I need a sampling rate of 3 millisecond in text mode on serial monitor using teensy 3.0. I need to read the data from a MPU9150. I have to save this data to an openlog (https://www.sparkfun.com/products/9530) based micro SD card (16 GB). The data output rate from an MPU 9150 is at 400 Hz. So I just want to read whatever comes out of it in real time without loosing much time. So if I can sample at 3 millisecond then I am sampling at 333.3 Hz. That is good enough for my requirements.

I am unable to open the file from Fabio as its in gz format. Please could you mail me a normal zip file which I can open using windows 7. Any suggestion or help is welcome as I have been struggling for the last two months to get it going. My current sampling rate is 18 milliseconds using an Arduino pro mini 3.3 V 8 MHz processor.



Much, much faster! Here's a post with some benchmarks:

http://freeimu.varesano.net/node/34#comment-209

Fabio merged this faster code, but it was not published as an official release before he died. Here is the last code, rev 49, from his repository:

http://www.pjrc.com/teensy/beta/freeimu_trunk-r49.tgz
 
Has anyone used MPU 9150 with Teensy 3.0 in fast mode (400 Hz). If so please guide me though the steps. I am a new Newbie. Please help.
 
Has anyone used MPU 9150 with Teensy 3.0 in fast mode (400 Hz). If so please guide me though the steps.

Extract the file. It contains a *LOT* of stuff.

Copy all the libraries from fabio-varesano/freeimu/trunk/libraries into your Arduino libraries folder.

Then run Arduino (or quit and restart, so it will re-detect the libraries list). Open the speed test from File > Examples > FreeIMU > FreeIMU_speedtest. Make sure Teensy 3.0 is selected in Tools > Boards. Then click Upload.

Regarding the 400 kHz mode, look for this line in the code:

Code:
  my3IMU.init(true); // the parameter enable or disable fast mode

If you put "true" in the init function, it runs at 400 kHz. If you use "false" or leave it empty, it runs at 100 kHz.
 
MPU9150 partly works

When I use Fabio code. I am able to sample at 4 milliseconds (sometimes 6 milliseconds). But it does not let me access data from the AK8975 magnetometer which is built into the MPU9150 chip. (As you may be aware that MPU 9150 is a combination of MPU6050 (accelerometer and gyroscope)and AK8975(magnetometer)). When I tried to include the AK8975 libraries and tried to include the functions to call AK8975. The programme hangs.

I am using the AK8975 code from Jeff Rowberg's git hub library. My current arduino version is 1.0.1. And I am using the Arduino pro mini 3.3V 328 P 8 MHz.

The output on the serial monitor is also jerky. Its not smooth and continuous for Accelerometer and Gyroscope output. Please help.


Extract the file. It contains a *LOT* of stuff.

Copy all the libraries from fabio-varesano/freeimu/trunk/libraries into your Arduino libraries folder.

Then run Arduino (or quit and restart, so it will re-detect the libraries list). Open the speed test from File > Examples > FreeIMU > FreeIMU_speedtest. Make sure Teensy 3.0 is selected in Tools > Boards. Then click Upload.

Regarding the 400 kHz mode, look for this line in the code:

Code:
  my3IMU.init(true); // the parameter enable or disable fast mode

If you put "true" in the init function, it runs at 400 kHz. If you use "false" or leave it empty, it runs at 100 kHz.
 
Maybe someone else here can help?

I've done everything I can for you, using Fabio's code (which I didn't write) on an Arduino Mini (which PJRC does not sell) with a motion sensor chip I've never used (and PJRC does not sell). Sorry, I just can't help any more than I have already tried.
 
Thank you

Thank you for your timely help so far.
Maybe someone else here can help?

I've done everything I can for you, using Fabio's code (which I didn't write) on an Arduino Mini (which PJRC does not sell) with a motion sensor chip I've never used (and PJRC does not sell). Sorry, I just can't help any more than I have already tried.
 
FreeIMU has no implementation of the AK8975 magnetometer, so it works like for a MPU6050 (Gyro+Accel)

I think you will not get 400Hz from the magnetometer (the datasheet says that the maximum is 8000Hz for the Gyro, 1000Hz for the Accelerometer, and on the AK8975 datasheet it is written that the magnetometer needs at least 7.3 millisecond for a reading), it should be somehow above 100Hz. If you check the Sparkfun implementation which is for the 6050 with the addition of the AK8975 in the function "MPU6050::getMotion9" they implement two delays of 10 milliseconds when they call the magnetometer, so the overall reading cannot be faster than 50Hz.

There is also this library which I have not tried but is working with the Teensy3 it seems.
 
Thank you for your post. I have read the data sheet and AK8975 operates in two modes. One is standard mode where it operates at 100 Hz and the second is fast mode where is it capable of operating at 400 Hz. I need to operate at the fast mode at 400 Hz. I do not know how to go about. In case it operates at fast mode then I can sync all the three sensors that is the idea.

FreeIMU has no implementation of the AK8975 magnetometer, so it works like for a MPU6050 (Gyro+Accel)

I think you will not get 400Hz from the magnetometer (the datasheet says that the maximum is 8000Hz for the Gyro, 1000Hz for the Accelerometer, and on the AK8975 datasheet it is written that the magnetometer needs at least 7.3 millisecond for a reading), it should be somehow above 100Hz. If you check the Sparkfun implementation which is for the 6050 with the addition of the AK8975 in the function "MPU6050::getMotion9" they implement two delays of 10 milliseconds when they call the magnetometer, so the overall reading cannot be faster than 50Hz.

There is also this library which I have not tried but is working with the Teensy3 it seems.
 
FreeIMU has no implementation of the AK8975 magnetometer, so it works like for a MPU6050 (Gyro+Accel)

I think you will not get 400Hz from the magnetometer (the datasheet says that the maximum is 8000Hz for the Gyro, 1000Hz for the Accelerometer, and on the AK8975 datasheet it is written that the magnetometer needs at least 7.3 millisecond for a reading), it should be somehow above 100Hz. If you check the Sparkfun implementation which is for the 6050 with the addition of the AK8975 in the function "MPU6050::getMotion9" they implement two delays of 10 milliseconds when they call the magnetometer, so the overall reading cannot be faster than 50Hz.

There is also this library which I have not tried but is working with the Teensy3 it seems.

Nice find, freto. I'll have to try out that library. My current hacked-up version of FreeIMU works, but it's less than elegant and I never managed to get the magnetometer working correctly (without the 20ms delay). Removing the delays causes it to return gyroscope data, for some reason. Oddly enough, I still can't get the sample speed above ~600 Hz. Still working on what's causing that.

Space, you need to use "my3IMU.init(true);" in the example code to enable fast I2C mode (400 kHz), as Paul said in one of his earlier posts.

I'd offer to send some example code, but right now my system just sends the raw sensor data to the host and does the motion fusion there (a huge Kalman filter).
 
Space, I think you are confusing the speed of the I2C bus which indeed can be 100 KiloHertz or 400KHz and the sensor speed which is more limited in this case.
For a simpler implementation you can use the i2cdevlib, which as the AK8957 implemented on its own, and again you see the 10 millisecond delay necessary to call the sensor and read it.

Another example is the more common compass HMC5883L (on the last freeIMU hardware), on page two of its datasheet you will see that it use the I2C bus at 400Khz, but its output rate is 75Hz or 160Hz max.
 
Thank for your quick reply. Yes I was a bit confused between the two. I am a Newbie. I am not an electronics/computer science engineer by training. Hence the confusion. Thank you for correcting me.

When I run the AK8975 on its own then I get 12 millisecond delay. I cannot make it go any faster which is about 83.33 Hz. I just want to know what is Maximum speed of AK8975 because I did not get any useful information on the data sheet for the same.

I have used HMC5883L on a different project. (But I do get your point now. Its a lot more clear to me that I should not confuse the serial clock speed with the actual operating speed of the device.) But I currently using MPU9150 as there is a space limitation in the current project.

Thank you for the quick help and support.

Space, I think you are confusing the speed of the I2C bus which indeed can be 100 KiloHertz or 400KHz and the sensor speed which is more limited in this case.
For a simpler implementation you can use the i2cdevlib, which as the AK8957 implemented on its own, and again you see the 10 millisecond delay necessary to call the sensor and read it.

Another example is the more common compass HMC5883L (on the last freeIMU hardware), on page two of its datasheet you will see that it use the I2C bus at 400Khz, but its output rate is 75Hz or 160Hz max.
 
The library that you are referring to on GitHub is from Pansenti. He does not provide any support without payment of a fee. Only the code is free. The rest he expects people to figure it out themselves. I did not find where he mentions that his code runs on Teensy 3.0.
 
Last edited:
Please could you guide me to the location in the code in " i2cdevlib, which as the AK8957 implemented on its own" where he mentions about the 10 millisecond delay. I am not able to find it any of the examples for AK8975 in i2cdevlib. Please help.
 
I am using "my3IMU.init(true);" in the code. I also have written some of my own code for talking to MPU9150 and I am able to sample at 4 milliseconds when I run the accelerometer and gyro on MPU9150. But when I try to run all the three (acc, gyro and mag) together then I am able to sample at 18 milliseconds. The Mag (AK 8975) alone runs at 12 milliseconds but why does the sampling rate go up by 6 milliseconds the moment I turn on the accelerometer and gyroscope. This is something that I do not follow. Please help.
 
Status
Not open for further replies.
Back
Top