[SER] Failed to get information off device No valid sensor readings received from device. Note that the data forwarder can only auto-detect frequencies >2Hz. You can override the frequency via --frequency.
I am running an Arduino UNO R3 with a 9 Axis Motion Shield, I’m just trying to get out the magnetometer data to Edge Forwarder. I’m running the serial comms at 115,200 baud, and tested data in the serial monitor tab and it looks good and well formatter, but can’t seem to figure out what I’m missing here.
If I output my data it looks like this:
But the one random time the forwarder actually started up I complained about NaN’s
Where is the disconnect happening?
#include <Arduino_NineAxesMotion.h>
// Instantiate the NineAxesMotion class
NineAxesMotion myMotionSensor;
#define FREQUENCY_HZ 50
#define INTERVAL_MS (1000 / FREQUENCY_HZ) // Corrected frequency calculation
static unsigned long last_interval_ms = 0;
static unsigned long lastPrintTime = 0;
void setup() {
// Initialize serial communication
Serial.begin(115200);
// Initialize the Wire library (I2C communication)
Wire.begin();
// Initialize the 9-axis motion sensor
myMotionSensor.begin();
// Set the operation mode to compass (only magnetometer)
myMotionSensor.setOperationMode(OPERATION_MODE_COMPASS);
// Set update mode to manual
myMotionSensor.setUpdateMode(MANUAL);
Serial.println("9-Axis Motion Shield initialized.");
}
void loop() {
// Check if the interval has passed
if (millis() > last_interval_ms + INTERVAL_MS) {
last_interval_ms = millis();
// Update magnetometer readings manually
myMotionSensor.updateMag();
// Get magnetometer data (in microteslas)
float mx = myMotionSensor.readMagX();
float my = myMotionSensor.readMagY();
float mz = myMotionSensor.readMagZ();
// // Print the magnetometer values in a comma-separated format
Serial.print(mx);
Serial.print(",");
Serial.print(my);
Serial.print(",");
Serial.println(mz);
}
}