QT PY ESP32-S2 with VL53L1X sensor

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ctmorrison
 
Posts: 75
Joined: Tue Jan 10, 2012 12:18 pm

QT PY ESP32-S2 with VL53L1X sensor

Post by ctmorrison »

I've had the subject sensor working with my QT PY ESP32-S2 when using CircuitPython. However, I decided to move to Arduino due to familiarity and now can't get the darn QT PY to talk to the sensor. I'm doing something wrong, but haven't a clue. I've tried several libraries and even the VL53L1X_simpletest.ino program without success. With the following program (a start on my final program), I never get past the serial print "we're past Wire.begin()" statement. Suggestions? (BTW, the two devices are connected via an Adafruit STEMMA cable and as I said, they worked under CircuitPython)

Code: Select all

#include <Adafruit_VL53L1X.h>
#include <ComponentObject.h>
#include <RangeSensor.h>
#include <vl53l1x_class.h>
#include <vl53l1x_error_codes.h>
#include <Adafruit_NeoPixel.h>

#define IRQ_PIN 2
#define XSHUT_PIN 3

Adafruit_VL53L1X vl53 = Adafruit_VL53L1X(XSHUT_PIN, IRQ_PIN);

// How many internal neopixels do we have? some boards have more than one!
#define NUMPIXELS        1

Adafruit_NeoPixel pixels(NUMPIXELS, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);

int unoccupiedOutput = A0; //this controls the relay for unoccupied output
int occupiedOutput = A1; //this controls the relay for occupied output
int setupButton = A2; //this is the input for the setup button
int pot = A3; //this is the input for the potentiometer
int occupiedStatus = SDA; //this reads the status of the relay
int energizeTime = 250; //this is the length of time we energize the relay in milliseconds
int spaceStatusPeriod = 500; //this is how long the PIXEL will be lit to show space status
int sleepPeriod = 150000; //duration of sleep between runs of the program (sleep period in milliseconds)

void setup() {
  Serial.begin(115200);
  delay(5000);
  Serial.println("setup started");
  pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
  pixels.setBrightness(20); // not so bright
  //let set the relay output pin modes
  pinMode(unoccupiedOutput,OUTPUT); //changes relay to unoccupied
  pinMode(occupiedOutput,OUTPUT);//changes relay to occupied
  pinMode(occupiedStatus,INPUT_PULLDOWN); //this pin tells us the status of the relay.  It's like retained memory this pin is the potentiometer
  Wire.begin();
  Serial.println("we're past Wire.begin()");
  if (!vl53.begin(0x29, &Wire)) {
    Serial.println("we're in the !vl53.begin if statement");
    Serial.print(F("Error on init of VL sensor: "));
    Serial.println(vl53.vl_status);
    delay(2000);
    while (1)       delay(10);
  }
  Serial.println(F("VL53L1X sensor OK!"));

  Serial.print(F("Sensor ID: 0x"));
  Serial.println(vl53.sensorID(), HEX);

  if (! vl53.startRanging()) {
    Serial.print(F("Couldn't start ranging: "));
    Serial.println(vl53.vl_status);
    while (1)       delay(10);
  }
  Serial.println(F("Ranging started"));

  // Valid timing budgets: 15, 20, 33, 50, 100, 200 and 500ms!
  vl53.setTimingBudget(50);
  Serial.print(F("Timing budget (ms): "));
  Serial.println(vl53.getTimingBudget());
}

// the loop routine runs over and over again forever:
void loop() {
  // say hi
  Serial.println("Hello!");
  
  // set color to red/green/blue
  pixels.fill(0xFF0000);
  pixels.show();
  digitalWrite(A0,HIGH);
  delay(1000); // wait half a second

  // turn off
  pixels.fill(0x000000);
  pixels.show();
  digitalWrite(A0,LOW);
  delay(1000); // wait half a second

    // set color to red/green/blue
  pixels.fill(0x00FF00);
  pixels.show();
  digitalWrite(A1,HIGH);
  delay(1000); // wait half a second

  // turn off
  pixels.fill(0x000000);
  pixels.show();
  digitalWrite(A1,LOW);
  delay(1000); // wait half a second

  int16_t distance;

  // if (vl53.dataReady()) {
  //   // new measurement for the taking!
  //   distance = vl53.distance();
  //   if (distance == -1) {
  //     // something went wrong!
  //     Serial.print(F("Couldn't get distance: "));
  //     Serial.println(vl53.vl_status);
  //     return;
  //   }
  //   Serial.print(F("Distance: "));
  //   Serial.print(distance);
  //   Serial.println(" mm");

  //   // data is read out, time for another reading!
  //   vl53.clearInterrupt();
  // }
}

User avatar
ctmorrison
 
Posts: 75
Joined: Tue Jan 10, 2012 12:18 pm

Re: QT PY ESP32-S2 with VL53L1X sensor

Post by ctmorrison »

I believe I may have found the issue. My PCB has 3.3 VDC connected to SDA when an input changes. I'm guessing this ruined the VL53L1X sensor. Dumb on my part to use it as an input when I'm using I2C even via STEMMA.

User avatar
ctmorrison
 
Posts: 75
Joined: Tue Jan 10, 2012 12:18 pm

Re: QT PY ESP32-S2 with VL53L1X sensor

Post by ctmorrison »

Well....it seems STEMMA uses SDA1 and SCL1, not SDA and SCL, I may not have goofed up my sensor. What do I need to do to my code in order to use a STEMMA interface and not the SDA and SCL ports on the QT PY? Please offer some guidance!

User avatar
ctmorrison
 
Posts: 75
Joined: Tue Jan 10, 2012 12:18 pm

Re: QT PY ESP32-S2 with VL53L1X sensor

Post by ctmorrison »

Ignore all this. I finally read somewhere that STEMMA uses Wire1 and with that one change to the program, it appears to be working now.

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”