Hi everyone, I’m having trouble reading accelerometer data from a LSM6DS3 IMU.
The LSM6DS3 is connected to a Pro Mini 328P (5V, 16MHz) via an FTDI USB board.
I have been using this equipment successfully for a few years now. The problem now is that additional backup units are not reading the accelerometer data correctly: when I upload my sketch, all axis read “13.25” in the serial monitor of the Arduino application on my MacBook Pro.
Hypotheses I have ruled out:
-
Board, Processor and Port settings in the Arduion application. Code uploads successfully. I’m afraid to try uploading to the working board because I need to have at least one working unit.
-
All hardware. I have successfully tested each component with the one working Pro Mini. The non-working Pro Minis do send correct digital data, so I know that all Pro Minis and all LSM6DS3s are not broken.
-
Serial speed. The digital pins do read correctly on all Pro Minis.
-
Hardware/software incompatibility due to changes in the header files. Header file has a date of 2015, which was about the time I bought the hardware.
Here is the code I’m using:
#include "SparkFunLSM6DS3.h"
#include "Wire.h"
#include "SPI.h"
LSM6DS3 myIMU; //Default constructor is I2C, addr 0x6B
int x = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(1000); //relax...
Serial.println("Processor came out of reset.\n");
for (int pin=2; pin<7; pin++) { pinMode(pin,INPUT_PULLUP); }
//Call .begin() to configure the IMU
myIMU.begin();
}
void loop()
{
for (int pin= 2; pin<=6; pin++){ // Read and send digital pins 2-6
x = digitalRead(pin);
sendInt ( (x - 1) * -1 );
}
//Get IMU parameters (accelerometer & gyroscope)
//accelerometer
sendFloat(myIMU.readFloatAccelX());
sendFloat(myIMU.readFloatAccelY());
sendFloat(myIMU.readFloatAccelZ());
//gyroscope
// sendFloat(myIMU.readFloatGyroX());
// sendFloat(myIMU.readFloatGyroY());
// sendFloat(myIMU.readFloatGyroZ());
Serial.println();
delay(10);
}
void sendInt (int x){ // function to send the pin value followed by a "space".
Serial.print(x);
Serial.print( " " );
}
void sendFloat (float x){ // function to send the pin value followed by a "space".
Serial.print(x);
Serial.print( " " );
}
I’m completely baffled at this point. Can someone offer any additional suggestions? Thanks so much.