Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 3 1 2 3 LastLast
Results 1 to 25 of 66

Thread: Teensy 3.0 driving 9-DOF accelerometer?

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    11

    Teensy 3.0 driving 9-DOF accelerometer?

    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:
    Click image for larger version. 

Name:	11486-01.jpg 
Views:	412 
Size:	189.6 KB 
ID:	215

    It communicates over I2C, so I assume it would be fairly straightforward to set up if I use the Wire library.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,303
    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....

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    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.

  4. #4
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    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.

  5. #5
    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.

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,303
    Quote Originally Posted by Space View Post
    Please could tell me what is the sampling rate with Teensy 3.0.
    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

  7. #7

    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.



    Quote Originally Posted by PaulStoffregen View Post
    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

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,303
    Winzip (free) can extract .tgz format.

  9. #9
    Quote Originally Posted by PaulStoffregen View Post
    Winzip (free) can extract .tgz format.
    http://www.7-zip.org/ Recommended

  10. #10
    Senior Member
    Join Date
    Jan 2013
    Location
    San Francisco Bay Area
    Posts
    641
    winrar is also a good utility to have for windows.

  11. #11

    Mpu 9150

    I unzipped the file. Its huge and a large component of the file is just machine language. I am using note pad ++ to view it.



    Quote Originally Posted by PaulStoffregen View Post
    Winzip (free) can extract .tgz format.

  12. #12
    Thank you.

  13. #13
    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.

  14. #14
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,303
    Quote Originally Posted by Space View Post
    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.

  15. #15

    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.


    Quote Originally Posted by PaulStoffregen View Post
    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.

  16. #16
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,303
    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.

  17. #17

    Thank you

    Thank you for your timely help so far.
    Quote Originally Posted by PaulStoffregen View Post
    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.

  18. #18
    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.

  19. #19
    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.

    Quote Originally Posted by freto View Post
    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.

  20. #20
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    Quote Originally Posted by freto View Post
    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).

  21. #21
    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.

  22. #22
    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.

    Quote Originally Posted by freto View Post
    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.

  23. #23
    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 by Space; 05-27-2013 at 06:41 PM.

  24. #24
    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.

  25. #25
    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •