Is it possible to have two Adafruit L3GD20H connected to the spark?

I would like to have two L3GD20H connect to one sparkcore via the I2C bus. Im currently using Adafruit library.

Is that possible? If its not possible by simply connecting the I2C bus to the L3GD20H, is their an alternative?

You can attempt to modify the board slightly…

The Slave ADdress (SAD) associated to the L3GD20H is 110101xb. SDO/SA0 pin can be
used to modify less significant bit of the device address. If SDO/SA0 pin is connected to
voltage supply LSb is ‘1’ (address 1101011b) else if SDO/SA0 pin is connected to ground
LSb value is ‘0’ (address 1101010b). This solution permits to connect and address two
different gyroscopes to the same I2C bus.

oh great.

Just to be clear, if I connect one of the L3GD20H to SA0 to 3V it will use a different address, correct?

Seems like that’s possible but that’s assuming that adafruit set it to ground :wink:

So I would need to add another Adafruit_L3GD20H.h (rename to something else)

  This is a library for the L3GD20 GYROSCOPE
  Designed specifically to work with the Adafruit L3GD20 Breakout 
  These sensors use I2C or SPI to communicate, 2 pins (I2C) 
  or 4 pins (SPI) are required to interface.
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!
  Written by Kevin "KTOWN" Townsend for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
#ifndef __L3GD20_H__
#define __L3GD20_H__

//#if (ARDUINO >= 100)
// #include "Arduino.h"
// #include "WProgram.h"
//#include "Wire.h"
#include "application.h"

#define L3GD20_ADDRESS                (0x6B)        // 1101011
#define L3GD20_POLL_TIMEOUT           (100)         // Maximum number of read attempts
#define L3GD20_ID                     0xD4
#define L3GD20H_ID                    0xD7

#define L3GD20_SENSITIVITY_250DPS  (0.00875F)      // Roughly 22/256 for fixed point match
#define L3GD20_SENSITIVITY_500DPS  (0.0175F)       // Roughly 45/256
#define L3GD20_SENSITIVITY_2000DPS (0.070F)        // Roughly 18/256
#define L3GD20_DPS_TO_RADS         (0.017453293F)  // degress/s to rad/s multiplier

class Adafruit_L3GD20
    typedef enum
    {                                               // DEFAULT    TYPE
      L3GD20_REGISTER_WHO_AM_I            = 0x0F,   // 11010100   r
      L3GD20_REGISTER_CTRL_REG1           = 0x20,   // 00000111   rw
      L3GD20_REGISTER_CTRL_REG2           = 0x21,   // 00000000   rw
      L3GD20_REGISTER_CTRL_REG3           = 0x22,   // 00000000   rw
      L3GD20_REGISTER_CTRL_REG4           = 0x23,   // 00000000   rw
      L3GD20_REGISTER_CTRL_REG5           = 0x24,   // 00000000   rw
      L3GD20_REGISTER_REFERENCE           = 0x25,   // 00000000   rw
      L3GD20_REGISTER_OUT_TEMP            = 0x26,   //            r
      L3GD20_REGISTER_STATUS_REG          = 0x27,   //            r
      L3GD20_REGISTER_OUT_X_L             = 0x28,   //            r
      L3GD20_REGISTER_OUT_X_H             = 0x29,   //            r
      L3GD20_REGISTER_OUT_Y_L             = 0x2A,   //            r
      L3GD20_REGISTER_OUT_Y_H             = 0x2B,   //            r
      L3GD20_REGISTER_OUT_Z_L             = 0x2C,   //            r
      L3GD20_REGISTER_OUT_Z_H             = 0x2D,   //            r
      L3GD20_REGISTER_FIFO_CTRL_REG       = 0x2E,   // 00000000   rw
      L3GD20_REGISTER_FIFO_SRC_REG        = 0x2F,   //            r
      L3GD20_REGISTER_INT1_CFG            = 0x30,   // 00000000   rw
      L3GD20_REGISTER_INT1_SRC            = 0x31,   //            r
      L3GD20_REGISTER_TSH_XH              = 0x32,   // 00000000   rw
      L3GD20_REGISTER_TSH_XL              = 0x33,   // 00000000   rw
      L3GD20_REGISTER_TSH_YH              = 0x34,   // 00000000   rw
      L3GD20_REGISTER_TSH_YL              = 0x35,   // 00000000   rw
      L3GD20_REGISTER_TSH_ZH              = 0x36,   // 00000000   rw
      L3GD20_REGISTER_TSH_ZL              = 0x37,   // 00000000   rw
      L3GD20_REGISTER_INT1_DURATION       = 0x38    // 00000000   rw
    } l3gd20Registers_t;

    typedef enum
    } l3gd20Range_t;

    typedef struct l3gd20Data_s
      float x;
      float y;
      float z;
    } l3gd20Data;

    Adafruit_L3GD20(int8_t cs, int8_t mosi, int8_t miso, int8_t clk);

    bool begin(l3gd20Range_t rng=L3DS20_RANGE_250DPS, byte addr=L3GD20_ADDRESS);
    void read(void);

    l3gd20Data data;    // Last read will be available here

    void write8(l3gd20Registers_t reg, byte value);
    byte read8(l3gd20Registers_t reg);
    uint8_t SPIxfer(uint8_t x);
    byte address;
    l3gd20Range_t range;
    int8_t _miso, _mosi, _clk, _cs;


change the L3GD20_ADDRESS … 1101010b would translate 0x6A. Anything else I would need to change?

i think you can use one library but declare 2 instance of the function…

 Adafruit_L3GD20 gyro1;
 Adafruit_L3GD20 gyro2;

void setup(){
   gyro1.begin(range, address);
   gyro2.begin(range, address);

the address would be in HEX? so

gyro1.begin(gyro1.L3DS20_RANGE_2000DPS, 0x6A);
gyro2.begin(gyro2.L3DS20_RANGE_2000DPS, 0x6B);

while at work I started thinking about using SPI instead of I2C because for the Adafruit libraries using SPI, the pins need to be define. If that’s the case, I could have a sets of pins for each gyro.

Would that work @kennethlimcp?

in case someone is trying to do something like what Im doing, SA0 goes to GND not 3V… and it works.

1 Like

Using SPI is a matter of having 2 separate Chip Select pins but seems like having 2 different address on I2C might be better with 2 pins saved!