Hello, I am currently having an issue with my 2 LSM6DS3 Accelerometers and Gyro's. I implemented the hardware and software changes for SPI mode. However, when I connect both devices the data is incorrect and only 1 will become active. If only one is connected, then everything works fine. I tried to set the pins HIGH and LOW (this is done in their library already), pull up resistors on my breadboard and via the code, different SS pins and nothing has worked. Any advice and help would be appreciated, thank you.
#include "SparkFunLSM6DS3.h"
#include "SPI.h"
//Create two instances of the driver class
LSM6DS3 SensorOne(SPI_MODE, 8);
LSM6DS3 SensorTwo(SPI_MODE, 6);
int i = 0; // while loop
int val = 0;
int val2 = 0;
void setup() {
Serial.begin(115200);
SensorOne.settings.accelRange = 2;
SensorTwo.settings.accelRange = 2;
delay(1000); //relax...
Serial.println("Processor came out of reset.\n");
} // end set up
void loop()
{
int sTime = millis();
while (i < 1000) {
Serial.print(i); // print the increment
Serial.print('\t');
Serial.println(millis());// - sTime);
// digitalWrite(6, HIGH); //turn off Sensor 2
// delay(0.2);
// digitalWrite(8, LOW); // turn on Sensor 1
// pinMode(6, INPUT_PULLUP); //Sensor 2 off
if ( SensorOne.begin() != 0 )
{
Serial.println("Problem starting the sensor with CS @ Pin 9.");
} else {
Serial.println("Sensor with CS @ Pin 9 started.");
} // end else
Serial.print('\t');
Serial.print(SensorOne.readFloatAccelX());
Serial.print('\t');
Serial.print(SensorOne.readFloatAccelY());
Serial.print('\t');
Serial.print(SensorOne.readFloatAccelZ());
Serial.print('\t');
Serial.print(SensorOne.readFloatGyroX());
Serial.print('\t');
Serial.print(SensorOne.readFloatGyroY());
Serial.print('\t');
Serial.println(SensorOne.readFloatGyroZ());
// digitalWrite(9, HIGH); // turn 1 off
// delay(0.2);
// digitalWrite(7, LOW); // turn 2 on
pinMode(8, INPUT_PULLUP); //sensor 1 off
if ( SensorTwo.begin() != 0 )
{
Serial.println("Problem starting the sensor with CS @ Pin 7.");
} else {
Serial.println("Sensor with CS @ Pin 7 started.");
} // end else
val = digitalRead(9); // read the input pin
Serial.println(val); // gives a '1'
Serial.println('\t');
val2 = digitalRead(7); // read the input pin
Serial.println(val2); // gives a '1'
Serial.print('\t');
Serial.print(SensorTwo.readFloatAccelX());
Serial.print('\t');
Serial.print(SensorTwo.readFloatAccelY());
Serial.print('\t');
Serial.print(SensorTwo.readFloatAccelZ());
Serial.print('\t');
Serial.print(SensorTwo.readFloatGyroX());
Serial.print('\t');
Serial.print(SensorTwo.readFloatGyroY());
Serial.print('\t');
Serial.println(SensorTwo.readFloatGyroZ());
delay(0.2);
i++; // increment while loop
} // end while
} // end program loop