0

I am trying to read sensor data from two MPU9250s with both one Arduino Nano and a Arduino Nano 33 BLE using SPI. As for the Arduino nano, I was successful to acquire the sensor data and output it in the serial monitor. However, unlike the old Nano device, the new Nano 33 BLE does not output any sensor readings in its serial monitor. Sometimes and very rarely though, I do receive a couple of readings (usually not more than 1-2 readings), after which no readings are received. Apparently, at least the sensor initialization seems to be always working on the 33 BLE device as my code runs past the Sensor OK messages in the setup routine.

I have been using bolderflight's MPU9250 library for talking to the sensors.

I've also tried reading only one sensor at a time, but that didn't really help, as I still didn't receive sensor readings. I didn't try I2C so far, mainly due to a lack of time.

Any ideas of what to try or why things might have gone wrong are appreciated.

Here's my code:

#include "MPU9250.h"

MPU9250 SENSOR1(SPI, 9);
MPU9250 SENSOR2(SPI, 10);
int status1, status2;

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

  // start communication with IMU 
  status1 = SENSOR1.begin();
  if (status1 < 0) {
    Serial.println("Sensor 1 error!");
    Serial.println(status1);
    while(1) {}
  }
  Serial.println("Sensor 1 OK");

  status2 = SENSOR2.begin();
  if (status2 < 0) {
    Serial.println("Sensor 2 error!");
    Serial.println(status2);
    while(1) {}
  }
  Serial.println("Sensor 2 OK");
}

void loop() {
  // read the sensor
  SENSOR1.readSensor();
  SENSOR2.readSensor();
  // display the data
  Serial.print("X: ");
  Serial.print(SENSOR1.getAccelX_mss(),6);
  Serial.print(" ");
  Serial.println(SENSOR2.getAccelX_mss(),6);
  Serial.print("Y: ");
  Serial.print(SENSOR1.getAccelY_mss(),6);
  Serial.print(" ");
  Serial.println(SENSOR2.getAccelY_mss(),6);
  Serial.print("Z: ");
  Serial.print(SENSOR1.getAccelZ_mss(),6);
  Serial.print(" ");
  Serial.println(SENSOR2.getAccelZ_mss(),6);
  delay(100);
}
  • Can the library used with the Nano 33? Old Nano and Nano 33 are not the same – chrisl Sep 25 at 15:28
  • To be honest, that is what I am not really certain of. But from what I understood, it should be... but I might have missed something. – medonja Sep 25 at 15:47

Your Answer

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

Browse other questions tagged or ask your own question.