MPU-9250 Teensy Library

My TD 1.44 download dated 9/19/2018 give a splash of just 1.44 - not beta?

As for the Amazon 9250's - minor name change on the silkscreen between the two - but all else looks the same on pin labels and parts location and type. Let me know when you get your hooked up Mike and I'll give mine try if possible. The ASYNC/DMA SPI seems like it would be helpful when getting 100-1000 updates a second! SPI faster and if the DMA engine does the work ASYNC then no wait when the INT arrives … then the data arrives … repeat.

It has been some time - and not used or updated - but I was getting 1 Mhz or faster on i2c - though there was some anomaly I noted with leaving the update speed set I never resolved … maybe that was a side effect of the HIGH speed.
 
Never mind I know what I did. Better let Mr S. know.

but I was getting 1 Mhz or faster on i2c - though there was some anomaly I noted with leaving the update speed set I never resolved
I remember, I was too but now I seem to be having a problem. Not sure what happened. Would like to track it down though. Just very strange because it seemed to be working in prior versions.

I do remember we use to see spikes in the data periodically, don't know if that is related or not. What really got me was the temperature spikes dropping like that when I ran the filters.
 
Whoa, this is bizarre. Works great for me on Arduino 1.8.5 with Teensyduino 1.44, but not with 1.8.7...
 
Whoa, this is bizarre. Works great for me on Arduino 1.8.5 with Teensyduino 1.44, but not with 1.8.7...

NEVERMIND...forgot that I had de-soldered some resistors and had to jumper a few more things than normal. Works fine on a fresh 1.8.7 with Teensyduino 1.44 install on Windows 10.
 
NEVERMIND...forgot that I had de-soldered some resistors and had to jumper a few more things than normal. Works fine on a fresh 1.8.7 with Teensyduino 1.44 install on Windows 10.
Ok, but not sure what that means when I am dealing with a normal breakout board. Are you using your board or a breakout board? Just curious I am not having a problem with Wire when using Kris Winer's library.
 
To get SPI to work on that breakout there are a couple 0 Ohm resistors that need to be de-soldered, which I did. The thing is that then, you need to remember to tie nCS to power for I2C to work properly.
Oh, ok now I understand what you were talking about. I have that board as well and modified it to use SPI. Didn't know all I had to do to I2C to work again was to tie nCS to power. Glad I asked.

Still have to figure out why I am having issues with other breakout boards.

TEMP CALC WRONG IN LIBRARY. By the way when I was working with the temp calc noticed you had the calculation wrong:
IS:
Code:
_t = ((((float) _tcounts) - _tempOffset)/_tempScale) + _tempOffset;

SHOULD BE:
Code:
 _t = ((float) _tcounts / _tempScale) + _tempOffset)
 
Hi Brian - on the embedded masters 9250 breakout board I seem to remember you also had to connect vdio to vdd and FSYNC to ground is that correct?

EDIT: THANKS FOR THE FAST RESPONSE :)
 
Hello everybody,

I want to read the BMI160 with teensy3.6.
I get the code from hanyazou and get the following error: Wire.endTransmission() failed.

How can it set the sda, scl pin configuration in the BMI160Gen.cpp oder .h?
Do you have an idea?
 
Hello everybody,

I want to read the BMI160 with teensy3.6.
I get the code from hanyazou and get the following error: Wire.endTransmission() failed.

How can it set the sda, scl pin configuration in the BMI160Gen.cpp oder .h?
Do you have an idea?

Seems like this deserves its own thread.
 
Hello,

I try to use the brian taylor library for the mpu9250 (the library have been downloaded using the arduino library manager)
I try to use the library with a basic blue mpu9250 board like this one : https://www.robot-maker.com/shop/capteurs/217-imu-9-axes-mpu9250-6500-spi-217.html on a teensy 4.0 board.



I connect :
MPU9250 TO Teensy 4.0
VCC 5V ( the mpu board have a 3.3V converter integrated)
GND GND
SCL/SCLK 13
SDA/SDI 11
AD0/SDO 12
NCS 10
FSYNC GND

Other MPU9250 pins are left unconnected.

I use the Basic SPI code to make a simple test.


Code:
/*
Basic_SPI.ino
Brian R Taylor
brian.taylor@bolderflight.com

Copyright (c) 2017 Bolder Flight Systems

Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
and associated documentation files (the "Software"), to deal in the Software without restriction, 
including without limitation the rights to use, copy, modify, merge, publish, distribute, 
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or 
substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include "MPU9250.h"

// an MPU9250 object with the MPU-9250 sensor on SPI bus 0 and chip select pin 10
MPU9250 IMU(SPI,10);
int status;

void setup() {
  // serial to display data
  Serial.begin(115200);
  while(!Serial) {}

  // start communication with IMU 
  status = IMU.begin();
  if (status < 0) {
    Serial.println("IMU initialization unsuccessful");
    Serial.println("Check IMU wiring or try cycling power");
    Serial.print("Status: ");
    Serial.println(status);
    while(1) {}
  }
}

void loop() {
  // read the sensor
  IMU.readSensor();
  // display the data
  Serial.print(IMU.getAccelX_mss(),6);
  Serial.print("\t");
  Serial.print(IMU.getAccelY_mss(),6);
  Serial.print("\t");
  Serial.print(IMU.getAccelZ_mss(),6);
  Serial.print("\t");
  Serial.print(IMU.getGyroX_rads(),6);
  Serial.print("\t");
  Serial.print(IMU.getGyroY_rads(),6);
  Serial.print("\t");
  Serial.print(IMU.getGyroZ_rads(),6);
  Serial.print("\t");
  Serial.print(IMU.getMagX_uT(),6);
  Serial.print("\t");
  Serial.print(IMU.getMagY_uT(),6);
  Serial.print("\t");
  Serial.print(IMU.getMagZ_uT(),6);
  Serial.print("\t");
  Serial.println(IMU.getTemperature_C(),6);
  delay(100);
}

The output I have on the serial monitor is :

IMU initialization unsuccessful

Check IMU wiring or try cycling power

Status: -2




Can someone confirm me that the librarie I try to use can be used on a teensy4.0?
I read in another thread that status = - 2 was a " spi problem "... Does I need to rewrite some code to make it working?
Can someone help me to figure what step is wrong in my experiment?

Thank you in advance

Best regards.
 
With the modification made, now the status is 1 as expected and basic spi as well as interrupt spi seems to work well.
Thank you!

Note : I only added the
#if defined(__IMXRT1062__)
#else
#endif
part in the .cpp file.

I don't know what is the "int readSensorCounts(int16_t* rawValues);" modification in the .h file ...

Best regards.
 
With the modification made, now the status is 1 as expected and basic spi as well as interrupt spi seems to work
I don't know what is the "int readSensorCounts(int16_t* rawValues);" modification in the .h file ...

IIRC, some people wanted access to the raw counts from the sensor data instead of the float values.
 
You really need to add external pull up resistors between each of the SDA and SCL pins and 3.3v. Typically 2.2K is used for 3.3v systems like the Teensy and 4.7K is used for 5v systems, but it really depends on the electrical characteristics of your i2c bus

IO pins on the Teensy3.2 have very weak pullups, as low as 50K, so for the purposes of I2C you should treat them like open drain pins. I2C uses open drain drivers to allow multiple devices to write to the bus, so the pullup resistor is wholly responsible for pulling up the lines when switching from logic 0 to 1. The speed at which this occurs is dependent on the inductance and capacitance in traces and cables between devices, and the size of the pullup resistors. The pullup resistance must be the same at both ends for both SDA and SCL.

The IO on the Teensy 3.2 has a 3.3V spec of 9mA sinking to 0.5V. So the parallel resistance (all nodes) @ 3.3V must be more than 300 ohms. As @MichaelMeissner noted 2.2K resistors are often used. That results in 1.1K parallel resistance for a 2 node bus. This is a compromise between speed and power. The Teensy 3.2 can drive as low as 620 ohm resistors with two devices on the bus, or ~1K with 3 devices. However, there is no need to go that low if you can get the speed you want with a larger resistor.

You can get higher speed and better margins either by reducing the size of the pullup, within the limits of the driver pin (9mA -> 0.5V here), or reducing the capacitance or inductance in the wiring between devices. On a PCB you can reduce capacitance by separating traces with a small gap. If using a cable you can decrease capacitance by minimizing the conductor diameter or maximizing the insulation diameter. You can reduce inductance by using twisted pair. At speeds in excess of 100KHz I try to match trace lengths on the PCB though that is likely overkill at those speeds.

I use a scope to verify final operation.
 
Hi, brtaylor

I read the MPU9250 sensor with teensy 4.1 and use the library you made, I use it on the Arduino IDE and platformIO. But can't.

problem with :
#include "Eigen/Core"
#include "Eigen/Dense"
#include "core/core.h"
#include "imu/imu.h"
#include "statistics/statistics.h".

Has anyone experienced it. Please help. thank you
 
Hi Brian..

Thanks for your answer...So I can use that library ini teensy 4.1 using SPI or just using I2C..Because when i use that library with SPI communication in teensy 4.1 still error...thanks...

Regards
jay

Should work, or at least it works fine for me. Please post your complete code, the error message that you get indicating it's not working, and a picture of the sensor and connections to the Teensy.
 
Teensy 4.1, arduino IDE, MPU9250, sampling rate

Should work, or at least it works fine for me. Please post your complete code, the error message that you get indicating it's not working, and a picture of the sensor and connections to the Teensy.

Hi brian...

The library is already working for me. I am using Teensy 4.1 and arduino IDE. but it only can run in CPU speed is at 398 Mhz, why can't it be increased to 600 Mhz? Why is the sampling rate only at 1000 Hz? can I increase it to 4000 or 2000 Hz? which part should I edit? Thank you for all the help and responses that have been given


Best regards
Jay
 
Hi brian...

The library is already working for me. I am using Teensy 4.1 and arduino IDE. but it only can run in CPU speed is at 398 Mhz, why can't it be increased to 600 Mhz? Why is the sampling rate only at 1000 Hz? can I increase it to 4000 or 2000 Hz? which part should I edit? Thank you for all the help and responses that have been given


Best regards
Jay

Should work at a CPU speed of 600 MHz. The sampling rate will always be 1kHz or less because we're using the MPU-9250 internal filter. To go above the 1kHz, you need to disable the internal filtering and then read each sensor at its raw sampling rate. Honestly, at that point you would just be using the ReadRegister and WriteRegister methods in my library and the rest would need to be updated.
 
Should work at a CPU speed of 600 MHz. The sampling rate will always be 1kHz or less because we're using the MPU-9250 internal filter. To go above the 1kHz, you need to disable the internal filtering and then read each sensor at its raw sampling rate. Honestly, at that point you would just be using the ReadRegister and WriteRegister methods in my library and the rest would need to be updated.

Hi Brian
Taking a break from my other distractions and just gave you latest library changes a try with one of those generic mpu-9250 boards and I am having problems. Haven't had a chance to debug yet but this is all I am getting with the Basic_SPI example:
Code:
IMU initialization unsuccessful

Now if I use the last version of the library I was using it works without an issue even at 600Mhz. I am attaching the version I have that works. As time permits will do some debugging.

@ora_jago you are free to give the version I just attached to see if it works - might help with the debugging.
 

Attachments

  • MPU9250.zip
    27.3 KB · Views: 51
Back
Top