Serial Recognizes Port but doesn't receive raw data

michaelpromeo's icon

Hi,

I'm on a Nano BLE 33 Rev 2. I've uploaded the following code:


#include "Arduino_BMI270_BMM150.h"

void setup() {
  Serial.begin(9600);
  while (!Serial);
  Serial.println("Started");

  if (!IMU.begin()) {
    Serial.println("Failed to initialize IMU!");
    while (1);
  }
  Serial.print("Gyroscope sample rate = ");
  Serial.print(IMU.gyroscopeSampleRate());
  Serial.println(" Hz");
  Serial.println();
  Serial.println("Gyroscope in degrees/second");
  Serial.println("X\tY\tZ");
}

void loop() {
  float x, y, z;

  if (IMU.gyroscopeAvailable()) {
    IMU.readGyroscope(x, y, z);

    Serial.println(x);
    Serial.print('\t');
    Serial.println(y);
    Serial.print('\t');
    Serial.println(z);
  }
}

Max sees the port but doesn't get any raw data.

I've reset, I've rebooted, I make sure Arduino IDE isn't open at the same time, I can see data in serial plotter if I check Arduino IDE. Nothing seems to work. FYI I'm NOT using the bluetooth functionality, I am simply connecting with USB.

Any ideas would be great!

Source Audio's icon
michaelpromeo's icon

Thanks so much! That seems to now recognize the Serial input because when I view raw data after setting 'dtr 1' I'm getting a hang. So maybe a bug with the latest Max 8.5.7 unless anyone sees something weird about the arduino code posted above that would cause a hang or overflow of data that I would just get spinning wheel for some reason?

Source Audio's icon

remove unneeded stuff from both max patch and arduino code.

how fast are you sending ?

is 9600 baud enough ?

test with simpler sketch to verify data flow,

than analyse sensor speed and tame it.

michaelpromeo's icon

Ok so there was a two part solution here:

  1. You absolutely need to bang a 'dtr 1' message to the 'serial' object.

  2. I altered the Arduino code to only loop serial data if Serial.available() and also added a short delay between loop. See below:


#include "Arduino_BMI270_BMM150.h"

void setup() {
  Serial.begin(9600);
  //while (!Serial);
  //Serial.println("Started");

  if (!IMU.begin()) {
    Serial.println("Failed to initialize IMU!");
    while (1);
  }
  Serial.print("Gyroscope sample rate = ");
  Serial.print(IMU.gyroscopeSampleRate());
  Serial.println(" Hz");
  Serial.println();
  Serial.println("Gyroscope in degrees/second");
  Serial.println("X\tY\tZ");
}

void loop() {

  if (Serial.available()) {
    float x, y, z;

    if (IMU.gyroscopeAvailable()) {
      IMU.readGyroscope(x, y, z);

      Serial.print(x);
      Serial.print(" ");
      Serial.print(y);
      Serial.print(" ");
      Serial.print(z);
      Serial.println();
      delay(50);
    }
  }
}

I attached my max patch here as well for anyone who is looking to get IMU data from the Arduino Nano BLE 33 (not bluetooth connected but via USB, bluetooth is a whole other complication I have yet to solve).

Appreciate the help!

BLE IMU.maxpat
Max Patch