Problems connecting LSM6DS3 to Xiao Ble on SPI

lucamox
Tue, 31 Mar 2026 19:54:57 +0000

Hi everyone,

I need to connect an imu (lsm6ds3trc) to a Xiao Ble (not sense), using the SPI bus.

The main reason is becuase I already have another sensor connected in SPI and I would like to share the same bus.

I tried various LSM6DS3 libraries, the Seed , the Sparkfun, and the Adrafruit.

The only one that works is the Adafruit, but I found the library not very flexible, mainly because I would like to write directly to the imu registers, to optimize the imu performances and power consumption.

The seed library (which works well in i2c) simply couldn´t find the imu in spi, and the sparkfun library is stuck in myimu.begin().

This is the code:

#include <SPI.h>
#include <ADS1220_WE.h>
//#include <SparkFunLSM6DS3.h>
//#include <Adafruit_LSM6DS3.h>
#include <LSM6DS3.h>


#define SAMPLE_RATE       90
#define IMU_CS    D6
#define ADS_CS    D7
#define ADS_DRDY  D3

bool adcok = true;
bool imuok = true;


LSM6DS3 MyImu(SPI_MODE, IMU_CS);
ADS1220_WE ads(ADS_CS, ADS_DRDY);


void setup() {
  Serial.begin(115200);
  delay(1000);


  Serial.println("Init Sensors");

  ads.setSPIClockSpeed(1000000);
  if (!ads.init()) {
    Serial.println("ADS1220 is not connected!");
    adcok = false;
  } else {
    Serial.println("ADS1220 found");
    ads.setGain(ADS1220_GAIN_128);
    ads.setOperatingMode(ADS1220_DUTY_CYCLE_MODE);
    //ads.setDataRate(ADS1220_DR_LVL_2);  // 90 SPS normal mode
    ads.setDataRate(ADS1220_DR_LVL_4);  // 82.5 SPS duty cycle mode
    ads.setConversionMode(ADS1220_CONTINUOUS);
    ads.setCompareChannels(ADS1220_MUX_1_2);
    ads.setVRefSource(ADS1220_VREF_REFP1_REFN1);
    ads.setLowSidePowerSwitch(ADS1220_SWITCH);
  }

delay(500);

  if( MyImu.begin() != 0)
  {
	  Serial.println("IMU not found!");
    imuok = false;
  } else {
    Serial.println("IMU found");
  }

}

void loop() {
  int cnt = SAMPLE_RATE;
  int32_t reading = 0;
  float GyroZ;

//  int gxRaw, gyRaw, gzRaw;         // BMI160 raw gyro values

  while (cnt > 0){

      if (adcok) {
        reading = ads.getRawData(); // get raw data
      } else delay(15);

      if(imuok) GyroZ = MyImu.readFloatGyroZ();
      cnt--;
  }

  Serial.print("Bridge Reading: ");
  Serial.println(reading);
  Serial.print("Gyroscope: Z1 = ");
  Serial.println(GyroZ, 4);

}

Thank you

Luca