When I try using the CircuitPython code, I get an error saying the wrong device is found. When I try using the Arduino code, it won't work at all and instead turns the QTPY into a flash drive. Here is the code I am currently using:
Code: Select all
#include <Arduino.h>
#include <Wire.h>
#include <vl53l4cd_class.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
#include <stdlib.h>
#define DEV_I2C Wire
#define SerialPort Serial
#ifndef LED_BUILTIN
#define LED_BUILTIN 13
#endif
#define LedPin LED_BUILTIN
// Components.
VL53L4CD sensor_vl53l4cd_sat(&DEV_I2C, A1);
/* Setup ---------------------------------------------------------------------*/
void setup()
{
// Led.
pinMode(LedPin, OUTPUT);
// Initialize serial for output.
SerialPort.begin(115200);
SerialPort.println("Starting...");
// Initialize I2C bus.
DEV_I2C.begin();
// Configure VL53L4CD satellite component.
sensor_vl53l4cd_sat.begin();
// Switch off VL53L4CD satellite component.
sensor_vl53l4cd_sat.VL53L4CD_Off();
//Initialize VL53L4CD satellite component.
sensor_vl53l4cd_sat.InitSensor();
// Program the highest possible TimingBudget, without enabling the
// low power mode. This should give the best accuracy
sensor_vl53l4cd_sat.VL53L4CD_SetRangeTiming(200, 0);
// Start Measurements
sensor_vl53l4cd_sat.VL53L4CD_StartRanging();
}
void loop()
{
uint8_t NewDataReady = 0;
VL53L4CD_Result_t results;
uint8_t status;
char report[64];
do {
status = sensor_vl53l4cd_sat.VL53L4CD_CheckForDataReady(&NewDataReady);
} while (!NewDataReady);
//Led on
digitalWrite(LedPin, HIGH);
if ((!status) && (NewDataReady != 0)) {
// (Mandatory) Clear HW interrupt to restart measurements
sensor_vl53l4cd_sat.VL53L4CD_ClearInterrupt();
// Read measured distance. RangeStatus = 0 means valid data
sensor_vl53l4cd_sat.VL53L4CD_GetResult(&results);
snprintf(report, sizeof(report), "Status = %3u, Distance = %5u mm, Signal = %6u kcps/spad\r\n",
results.range_status,
results.distance_mm,
results.signal_per_spad_kcps);
SerialPort.print(report);
}
//Led off
digitalWrite(LedPin, LOW);
}