Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Running two ToF Adafruit sensors in two seperate I2C channel
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Running two ToF Adafruit sensors in two seperate I2C channel

by lvangelis on Wed Apr 08, 2020 12:51 pm

Hello,

I am trying to initiate the TwoWire function to run two Adafruit toF sensors. The message I get is that they fail to boot and poll no data. Code returns no errors and sensors can be found using the I2C dual scanner method. They also polling if I run independently. Its early days in Arduino so not sure if I am doing something obviously wrong here. Any help would be appreciated.
Code: Select all | TOGGLE FULL SIZE
#include "Adafruit_VL53L0X.h"
#include "Adafruit_VL6180X.h"
#include <Wire.h>

#define SDA1 21
#define SCL1 22

#define SDA2 5
#define SCL2 4


TwoWire WireA = TwoWire(0);
TwoWire WireB = TwoWire(1);

Adafruit_VL53L0X lox = Adafruit_VL53L0X();
Adafruit_VL6180X vl = Adafruit_VL6180X();

float lux = 0.;
uint8_t range = 0;
uint16_t secrange = 0;

void setup() {
  Serial.begin(115200);
  WireA.begin(SDA1, SCL1, 100000); //uses default SDA and SCL and 100000HZ freq
  WireB.begin(SDA2, SCL2, 100000); //uses default SDA and SCL and 100000HZ freq


  // wait until serial port opens for native USB devices
  while (! Serial) {
    delay(1);
  }
  vl.begin();
  lox.begin();

      Serial.println("Adafruit VL53L0X test");
  if (!lox.begin()) {
    Serial.println(F("Failed to boot VL53L0X"));
    while(1);
  }
  // power
  Serial.println(F("VL53L0X API Simple Ranging example\n\n"));
 
  Serial.println("Adafruit VL6180x test!");
  if (! vl.begin()) {
    Serial.println("Failed to find sensor");
    while (1);
  }
}


void loop() {
  VL53L0X_RangingMeasurementData_t measure;
  secrange = measure.RangeMilliMeter;
  Serial.print("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 ");
  }
  lux = vl.readLux(VL6180X_ALS_GAIN_5);
  Serial.print("Lux: "); Serial.println(lux);
 
  range = vl.readRange();
  uint8_t status = vl.readRangeStatus();
 
  if (status == VL6180X_ERROR_NONE) {
  Serial.print("Range: "); Serial.println(range);
  }

  // Some error occurred, print it out!
 
  if  ((status >= VL6180X_ERROR_SYSERR_1) && (status <= VL6180X_ERROR_SYSERR_5)) {
    Serial.println("System error");
  }
  else if (status == VL6180X_ERROR_ECEFAIL) {
    Serial.println("ECE failure");
  }
  else if (status == VL6180X_ERROR_NOCONVERGE) {
    Serial.println("No convergence");
  }
  else if (status == VL6180X_ERROR_RANGEIGNORE) {
    Serial.println("Ignoring range");
  }
  else if (status == VL6180X_ERROR_SNR) {
    Serial.println("Signal/Noise error");
  }
  else if (status == VL6180X_ERROR_RAWUFLOW) {
    Serial.println("Raw reading underflow");
  }
  else if (status == VL6180X_ERROR_RAWOFLOW) {
    Serial.println("Raw reading overflow");
  }
  else if (status == VL6180X_ERROR_RANGEUFLOW) {
    Serial.println("Range reading underflow");
  }
  else if (status == VL6180X_ERROR_RANGEOFLOW) {
    Serial.println("Range reading overflow");
  }
   
  delay(100);
}
Last edited by adafruit_support_carter on Fri Apr 10, 2020 4:26 pm, edited 1 time in total.
Reason: added [code] tags

lvangelis
 
Posts: 1
Joined: Wed Dec 11, 2013 4:10 pm

Re: Running two ToF Adafruit sensors in two seperate I2C cha

by adafruit_support_carter on Fri Apr 10, 2020 4:27 pm

Start simple. Set each one up individually and run the basic demo example from the library for each. Prove they each work separately before combing them.

adafruit_support_carter
 
Posts: 16820
Joined: Tue Nov 29, 2016 2:45 pm

Please be positive and constructive with your questions and comments.