Using I2C Device (AS5600) with non default SDA & SLC

I am using an ESP32, and I have 2 IC2 sensors I want to use. The first works well using the default IC2 pins G21 and G22, but I have problems setting up the second (using GitHub - RobTillaart/AS5600: Arduino library for AS5600 magnetic rotation meter)

I am trying to work out what I have done wrong, and have got this far. The second I2C device does not connect to successfully.

#include "Adafruit_VL53L0X.h" // Laser distance measurment (VL53L0X)    
Adafruit_VL53L0X lox = Adafruit_VL53L0X();

#include "AS5600.h" // Hall Rotation Sensor (AS5600)

TwoWire I2Ctwo = TwoWire(1);
AS5600 as5600(&I2Ctwo);  

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

  // VL53L0X - Uses default SDA, SCL
  while (!Serial)
  {
    delay(1);
  }
  
  Serial.println("Adafruit VL53L0X test");
  if (!lox.begin())
  {
    Serial.println(F("Failed to boot VL53L0X"));
    while(1);
  }
  Serial.println(F("Boot VL53L0X success"));
  delay(1000);

  // AS5600 - Uses my chosen SDA, SCL (since default is already used by VL53L0X)
  as5600.begin(16,17); //  My choice: SDA & SCL 
  delay(1000);

  int b = as5600.isConnected();
  Serial.print("Connect: ");
  Serial.println(b);            // I get a 0 (false) here :(
  delay(1000);
  
}

void ReadVL53L0X() {
    VL53L0X_RangingMeasurementData_t measure;

    // Reading a measurement
    lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout!
    
    if (measure.RangeStatus != 4) // phase failures have incorrect data
    { 
      Serial.print("Distance (mm): "); 
      Serial.println(measure.RangeMilliMeter);
    }
    else
    {
      Serial.println(" out of range ");
    }
}


void loop()
{
  ReadVL53L0X();
  delay(10); 

  Serial.print(as5600.readAngle());
  delay(10); 
}

The output shows that as5600.isConnected() fails.

The AS5600 library offers this help(which I have tried to follow - unsuccessfully) -

It's been a while since I did it but the ESP32 has 2 I2C device drivers. I noticed that the pins being used is one of the serial ports.

This is no longer needed:

TwoWire I2Ctwo = TwoWire(1);

You can remove that, and directly use "Wire1".

The library will do the Wire1.begin() for you, if you give the pin numbers.

AS5600 as5600(&Wire1);

void setup()
{
  as5600.begin(16,17); //  My choice: SDA & SCL
  ... 

Why do you use the second I2C bus ? Do they conflict on the same I2C bus ?
I suggest to first try the AS5600 on the normal I2C bus with nothing else connected, then try the second I2C bus then try to add the VL53L0X.

when I looked both devices use the same I2C address of 0x36

1 Like

Excellent comments and knowledge! Thank you so much - I will follow each item up :slight_smile:

Hi Idahowalker,

The I2C address of the AS5600 is always 0x36
The VL53L0X has a default I2C address of 0x29

That's what I've found. Please pass on anything you have found that contradicts this ?

1 Like

If both devices have different I2C address just connect them to the same bus.

Thanks Idahowalker! That information was what I needed :slight_smile:

1 Like

Post#4 had the answer before I came up with it.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.