Using multiple Gyro on Hardware SPI

Hello

I’ve bought 2 x LSM9DS0 gyro boards.
I’m using Arduino Uno to run them.

I’m trying to connect two LSM9DS0 boards working in the same time.
To do that I’m modifying attached lsm9doftest standard example in the way presented below.
I’m using hardware SPI protocol for communication, PIN 9,10 as CS GYRO 1 and PIN 6,7 as CS GYRO 2.

I think this looks ok, but it doesn’t work.
Separately (lsm on and lsm_1 marked // or vice versa) they are working but together not.

Is anybody who can help me, what should be changed ??

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_LSM9DS0.h>
#include <Adafruit_Sensor.h>  // not used in this demo but required!

// i2c
//Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0();

// You can also use software SPI
//Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0(13, 12, 11, 10, 9);
// Or hardware SPI! In this case, only CS pins are passed in
Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0(10, 9);
Adafruit_LSM9DS0 lsm_1 = Adafruit_LSM9DS0(7, 6);

void setupSensor()
{
 // 1.) Set the accelerometer range
 lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_2G);
 lsm_1.setupAccel(lsm.LSM9DS0_ACCELRANGE_2G);  
 
 // 2.) Set the magnetometer sensitivity
 lsm.setupMag(lsm.LSM9DS0_MAGGAIN_2GAUSS);
 lsm_1.setupMag(lsm.LSM9DS0_MAGGAIN_2GAUSS);  

 // 3.) Setup the gyroscope
 lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_245DPS);
 lsm_1.setupGyro(lsm.LSM9DS0_GYROSCALE_245DPS);  
}

void setup() 
{
 while (!Serial); // flora & leonardo
 
 Serial.begin(9600);
 Serial.println("LSM raw read demo");
 
 // Try to initialise and warn if we couldn't detect the chip
     if (!lsm.begin())
   {
     Serial.println("Oops ... unable to initialize the LSM9DS0. Check your wiring!");
     while (1);
   }

   if (!lsm_1.begin())
 {
   Serial.println("Oops ... unable to initialize the LSM9DS0 GYRo 2. Check your wiring!");
   while (1);
 }
 
 Serial.println("Found LSM9DS0 9DOF");
 Serial.println("");
 Serial.println("");
}

void loop() 
{

 lsm.read();

 Serial.print("Accel X: "); Serial.print((int)lsm_1.accelData.x); Serial.print(" ");
 Serial.print("Y: "); Serial.print((int)lsm_1.accelData.y);       Serial.print(" ");
 Serial.print("Z: "); Serial.println((int)lsm_1.accelData.z);     Serial.print(" ");
 Serial.print("Mag X: "); Serial.print((int)lsm_1.magData.x);     Serial.print(" ");
 Serial.print("Y: "); Serial.print((int)lsm_1.magData.y);         Serial.print(" ");
 Serial.print("Z: "); Serial.println((int)lsm_1.magData.z);       Serial.print(" ");
 Serial.print("Gyro X: "); Serial.print((int)lsm_1.gyroData.x);   Serial.print(" ");
 Serial.print("Y: "); Serial.print((int)lsm_1.gyroData.y);        Serial.print(" ");
 Serial.print("Z: "); Serial.println((int)lsm_1.gyroData.z);      Serial.println(" ");
 Serial.print("Temp: "); Serial.print((int)lsm_1.temperature);    Serial.println(" ");
 
 delay(200);
 

 lsm_1.read();
 
 Serial.print("Accel X: "); Serial.print((int)lsm_1.accelData.x); Serial.print(" ");
 Serial.print("Y: "); Serial.print((int)lsm_1.accelData.y);       Serial.print(" ");
 Serial.print("Z: "); Serial.println((int)lsm_1.accelData.z);     Serial.print(" ");
 Serial.print("Mag X: "); Serial.print((int)lsm_1.magData.x);     Serial.print(" ");
 Serial.print("Y: "); Serial.print((int)lsm_1.magData.y);         Serial.print(" ");
 Serial.print("Z: "); Serial.println((int)lsm_1.magData.z);       Serial.print(" ");
 Serial.print("Gyro X: "); Serial.print((int)lsm_1.gyroData.x);   Serial.print(" ");
 Serial.print("Y: "); Serial.print((int)lsm_1.gyroData.y);        Serial.print(" ");
 Serial.print("Z: "); Serial.println((int)lsm_1.gyroData.z);      Serial.println(" ");
 Serial.print("Temp: "); Serial.print((int)lsm_1.temperature);  

 delay(200); 
 
}
  1. Repost your code this time using code tags

  2. Look up SPI in the learning area and see what you are doing wrong. What makes you think there are two lots of SPI pins?

Mark

Hi again !

I have solved (with the help of my friend:) ) the case above.
We change in the code CS pins to which GYRO sensor I’m talking to.

Now modified and working code looks as follows:

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_LSM9DS0.h>
#include <Adafruit_Sensor.h>  // not used in this demo but required!

// i2c
//Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0();

// You can also use software SPI
//Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0(13, 12, 11, 10, 9);
// Or hardware SPI! In this case, only CS pins are passed in
Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0(10, 9);


void setupSensor()
{
  // 1.) Set the accelerometer range
  lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_2G); 
  
  // 2.) Set the magnetometer sensitivity
  lsm.setupMag(lsm.LSM9DS0_MAGGAIN_2GAUSS);

  // 3.) Setup the gyroscope
  lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_245DPS);
}

void setup() 
{
  while (!Serial); // flora & leonardo
  
  Serial.begin(9600);
  Serial.println("LSM raw read demo");

  
  Serial.println("Found LSM9DS0 9DOF");
  Serial.println("");
  Serial.println("");
}

void loop() 
{
  lsm = Adafruit_LSM9DS0(10, 9);
  lsm.begin();
  lsm.read();
  Serial.println("GYRO 1");
  Serial.print("Accel X: "); Serial.print((int)lsm.accelData.x); Serial.print(" ");
  Serial.print("Y: "); Serial.print((int)lsm.accelData.y);       Serial.print(" ");
  Serial.print("Z: "); Serial.println((int)lsm.accelData.z);     Serial.print(" ");
  Serial.print("Mag X: "); Serial.print((int)lsm.magData.x);     Serial.print(" ");
  Serial.print("Y: "); Serial.print((int)lsm.magData.y);         Serial.print(" ");
  Serial.print("Z: "); Serial.println((int)lsm.magData.z);       Serial.print(" ");
  Serial.print("Gyro X: "); Serial.print((int)lsm.gyroData.x);   Serial.print(" ");
  Serial.print("Y: "); Serial.print((int)lsm.gyroData.y);        Serial.print(" ");
  Serial.print("Z: "); Serial.println((int)lsm.gyroData.z);      Serial.println(" ");
  Serial.print("Temp: "); Serial.print((int)lsm.temperature);    Serial.println(" ");
  
  delay(200);
  lsm.end();

  lsm = Adafruit_LSM9DS0(7, 6);
  lsm.begin();
  lsm.read();
  Serial.println("GYRO 2");
  Serial.print("Accel X: "); Serial.print((int)lsm.accelData.x); Serial.print(" ");
  Serial.print("Y: "); Serial.print((int)lsm.accelData.y);       Serial.print(" ");
  Serial.print("Z: "); Serial.println((int)lsm.accelData.z);     Serial.print(" ");
  Serial.print("Mag X: "); Serial.print((int)lsm.magData.x);     Serial.print(" ");
  Serial.print("Y: "); Serial.print((int)lsm.magData.y);         Serial.print(" ");
  Serial.print("Z: "); Serial.println((int)lsm.magData.z);       Serial.print(" ");
  Serial.print("Gyro X: "); Serial.print((int)lsm.gyroData.x);   Serial.print(" ");
  Serial.print("Y: "); Serial.print((int)lsm.gyroData.y);        Serial.print(" ");
  Serial.print("Z: "); Serial.println((int)lsm.gyroData.z);      Serial.println(" ");
  Serial.print("Temp: "); Serial.print((int)lsm.temperature);    Serial.println(" ");
  
  delay(200); 
  lsm.end();
  
}