Dear All,
We use 4 VL53L0x sensor in our robot . VL53L0x are controlled by Arduino mega and give us digital signal to our main card. When we take huge power from gel battery , VL53l0x were shutdown and do not read anything .Our code Below
#include <Wire.h>
#include <VL53L0X.h>
//#define XSHUT_pin6 not required for address change
#define solXSHUT_pini 19
#define onsolXSHUT_pini 18
#define onsagXSHUT_pini 16
#define sagXSHUT_pini 17
#define sol10 4
#define sol75 5
#define onsol 6
#define onsag 8
#define sag75 7
#define sag10 9
//ADDRESS_DEFAULT 0b0101001 or 41
//#define onsagSensor_newAddress 41 not required address change
#define onsolSensorAdresi 42
#define sagSensorAdresi 43
#define solSensorAdresi 44
VL53L0X onsagSensor;
VL53L0X onsolSensor;
VL53L0X sagSensor;
VL53L0X solSensor;
/********* Mesafe parametreleri **********/
const int ENGELMESAFE_ON = 500;
const int ENGELMESAFE_YAN = 100;
const int ENGELMESAFE_YAN_DONUS = 500;
int engeller[] = {0, 0, 0, 0, 0, 0};
void setup()
{ /*WARNING*/
//Shutdown pins of VL53L0X ACTIVE-LOW-ONLY NO TOLERANT TO 5V will fry them
pinMode(onsagXSHUT_pini, OUTPUT);
pinMode(onsolXSHUT_pini, OUTPUT);
pinMode(sagXSHUT_pini, OUTPUT);
pinMode(solXSHUT_pini, OUTPUT);
Serial.begin(9600);
Wire.begin();
//Change address of sensor and power up next one
pinMode(solXSHUT_pini, INPUT);
delay(10);
solSensor.setAddress(solSensorAdresi);
pinMode(sagXSHUT_pini, INPUT);
delay(10);
sagSensor.setAddress(sagSensorAdresi);
pinMode(onsolXSHUT_pini, INPUT);
delay(10);
onsolSensor.setAddress(onsolSensorAdresi);
pinMode(onsagXSHUT_pini, INPUT);
delay(10);
onsagSensor.init();
onsolSensor.init();
sagSensor.init();
solSensor.init();
onsagSensor.setTimeout(500);
onsolSensor.setTimeout(500);
sagSensor.setTimeout(500);
solSensor.setTimeout(500);
// Start continuous back-to-back mode (take readings as
// fast as possible). To use continuous timed mode
// instead, provide a desired inter-measurement period in
// ms (e.g. sensor.startContinuous(100)).
onsagSensor.startContinuous();
onsolSensor.startContinuous();
sagSensor.startContinuous();
solSensor.startContinuous();
/**** tanimlar *****/
pinMode(onsag, OUTPUT);
pinMode(onsol, OUTPUT);
pinMode(sag10, OUTPUT);
pinMode(sol10, OUTPUT);
pinMode(sag75, OUTPUT);
pinMode(sol75, OUTPUT);
digitalWrite(onsol, LOW);
digitalWrite(onsag, LOW);
digitalWrite(sag10, LOW);
digitalWrite(sol10, LOW);
digitalWrite(sag75, LOW);
digitalWrite(sol75, LOW);
}
void loop()
{
//sensorler okurken hatalı okumasına onlem olarak 2 defa okunuyor
int engellerOkuma1[] = {0, 0, 0, 0, 0, 0}; // sol10,sol75,onSol,onSag,sag75,sag10
int engellerOkuma2[] = {0, 0, 0, 0, 0, 0};
//ILK OKUMA
int solMesafe = solSensor.readRangeContinuousMillimeters();
//delay(5);
int onsolMesafe = onsolSensor.readRangeContinuousMillimeters();
//delay(5);
int onsagMesafe = onsagSensor.readRangeContinuousMillimeters();
//delay(5);
int sagMesafe = sagSensor.readRangeContinuousMillimeters();
// delay(1);
//
//
Serial.print("solM_1: ");
Serial.print(solMesafe);
Serial.print("\t onsolM_1: ");
Serial.print(onsolMesafe);
Serial.print("\t onsagM_1: ");
Serial.print(onsagMesafe);
Serial.print("\t sagM_1: ");
Serial.println(sagMesafe);
if (solMesafe > 0 && solMesafe < ENGELMESAFE_YAN)
engellerOkuma1[0] = 1; //sol10
if (solMesafe > ENGELMESAFE_YAN && solMesafe < ENGELMESAFE_YAN_DONUS)
engellerOkuma1[1] = 1; //sol75
if (onsolMesafe > 0 && onsolMesafe < ENGELMESAFE_ON)
engellerOkuma1[2] = 1; //onSol
if (onsagMesafe > 0 && onsagMesafe < ENGELMESAFE_ON)
engellerOkuma1[3] = 1; //onSag
if (sagMesafe > ENGELMESAFE_YAN && sagMesafe < ENGELMESAFE_YAN_DONUS)
engellerOkuma1[4] = 1; //sag75
if (sagMesafe > 0 && sagMesafe < ENGELMESAFE_YAN)
engellerOkuma1[5] = 1; //sag10
solMesafe = solSensor.readRangeContinuousMillimeters();
//delay(5);
onsolMesafe = onsolSensor.readRangeContinuousMillimeters();
//delay(5);
onsagMesafe = onsagSensor.readRangeContinuousMillimeters();
//delay(5);
sagMesafe = sagSensor.readRangeContinuousMillimeters();
//delay(5);
//
// Serial.print("solM_2: ");
// Serial.print(solMesafe);
// Serial.print("\t onsolM_2: ");
// Serial.print(onsolMesafe);
// Serial.print("\t onsagM_2: ");
// Serial.print(onsagMesafe);
// Serial.print("\t sagM_2: ");
// Serial.println(sagMesafe);
if (solMesafe > 0 && solMesafe < ENGELMESAFE_YAN)
engellerOkuma2[0] = 1; //sol10
if (solMesafe > 0 && solMesafe < ENGELMESAFE_YAN_DONUS)
engellerOkuma2[1] = 1; //sol75
if (onsolMesafe > 0 && onsolMesafe < ENGELMESAFE_ON)
engellerOkuma2[2] = 1; //onSol
if (onsagMesafe > 0 && onsagMesafe < ENGELMESAFE_ON)
engellerOkuma2[3] = 1; //onSag
if (sagMesafe > 0 && sagMesafe < ENGELMESAFE_YAN_DONUS)
engellerOkuma2[4] = 1; //sag75
if (sagMesafe > 0 && sagMesafe < ENGELMESAFE_YAN)
engellerOkuma2[5] = 1; //sag10
// Serial.print("engeller: [");
for (int j = 0; j < 6; j++)
{
if (engellerOkuma1[j] == engellerOkuma2[j])
{
engeller[j] = engellerOkuma1[j];
// Serial.print(engeller[j]);
// Serial.print(" , ");
}
else
{
engeller[j] = 0; //bence 0 yani engel yok olmali
}
}
digitalWrite(sol10, engeller[0]);
digitalWrite(sol75, engeller[1]);
digitalWrite(onsol, engeller[2]);
digitalWrite(onsag, engeller[3]);
digitalWrite(sag75, engeller[4]);
digitalWrite(sag10, engeller[5]);
}