Tengo una consulta estoy utilizando una raspberry pi pico con cuatro sensores VL53l0x para un micro ratón pero por alguna extraña razón no lee la comunicación i2C si no está conectado a la computadora necesito ayuda urgente tengo que entregar esto el lunes
He trasladado su tema de una categoría de idioma inglés del foro a la categoría International > Español @eljorjais67.
En adelante por favor usar la categoría apropiada a la lengua en que queráis publicar. Esto es importante para el uso responsable del foro, y esta explicado aquí la guía "How to get the best out of this forum".
Este guía contiene mucha información útil. Por favor leer.
De antemano, muchas gracias por cooperar.
Por favor muestre el diagrama de conexión y el código.
#include "Adafruit_VL53L0X.h"
//declaracion de pines del L293D
int LED_V = 28;
int LED_R = 27;
int velocidad_1 = 21;
int input_1_1 = 20;
int input_1_2 = 19;
//MOTOR 2
int velocidad_2 = 18;
int input_2_1 =16;
int input_2_2 =17;
// address we will assign if dual sensor is present
#define LOX1_ADDRESS 0x30
#define LOX2_ADDRESS 0x31
#define LOX3_ADDRESS 0x32
#define LOX4_ADDRESS 0x33
// set the pins to shutdown
#define SHT_LOX1 2
#define SHT_LOX2 3
#define SHT_LOX3 12
#define SHT_LOX4 13
// objects for the vl53l0x
Adafruit_VL53L0X lox1 = Adafruit_VL53L0X();
Adafruit_VL53L0X lox2 = Adafruit_VL53L0X();
Adafruit_VL53L0X lox3 = Adafruit_VL53L0X();
Adafruit_VL53L0X lox4 = Adafruit_VL53L0X();
// this holds the measurement
VL53L0X_RangingMeasurementData_t measure1;
VL53L0X_RangingMeasurementData_t measure2;
VL53L0X_RangingMeasurementData_t measure3;
VL53L0X_RangingMeasurementData_t measure4;
/*
Reset all sensors by setting all of their XSHUT pins low for delay(10), then set all XSHUT high to bring out of reset
Keep sensor #1 awake by keeping XSHUT pin high
Put all other sensors into shutdown by pulling XSHUT pins low
Initialize sensor #1 with lox.begin(new_i2c_address) Pick any number but 0x29 and it must be under 0x7F. Going with 0x30 to 0x3F is probably OK.
Keep sensor #1 awake, and now bring sensor #2 out of reset by setting its XSHUT pin high.
Initialize sensor #2 with lox.begin(new_i2c_address) Pick any number but 0x29 and whatever you set the first sensor to
*/
void setID() {
// entra a reinicio
digitalWrite(SHT_LOX1, LOW);
digitalWrite(SHT_LOX2, LOW);
digitalWrite(SHT_LOX3, LOW);
digitalWrite(SHT_LOX4, LOW);
delay(10);
// sale de reinicio
digitalWrite(SHT_LOX1, HIGH);
digitalWrite(SHT_LOX2, HIGH);
digitalWrite(SHT_LOX3, HIGH);
digitalWrite(SHT_LOX4, HIGH);
delay(10);
// activating LOX1 and resetting LOX2
digitalWrite(SHT_LOX1, HIGH);
digitalWrite(SHT_LOX2, LOW);
digitalWrite(SHT_LOX3, LOW);
digitalWrite(SHT_LOX4, LOW);
// initing LOX1
if(!lox1.begin(LOX1_ADDRESS)) {
Serial.println(F("Failed to boot first VL53L0X"));
while(1);
}
delay(10);
// activating LOX2
digitalWrite(SHT_LOX2, HIGH);
delay(10);
//initing LOX2
if(!lox2.begin(LOX2_ADDRESS)) {
Serial.println(F("Failed to boot second VL53L0X"));
while(1);
}
// activating LOX3
digitalWrite(SHT_LOX3, HIGH);
delay(10);
//initing LOX3
if(!lox3.begin(LOX3_ADDRESS)) {
Serial.println(F("Failed to boot third VL53L0X"));
while(1);
}
// activating LOX4
digitalWrite(SHT_LOX4, HIGH);
delay(10);
//initing LOX4
if(!lox4.begin(LOX4_ADDRESS)) {
Serial.println(F("Failed to boot fourd VL53L0X"));
while(1);
}
}
void read_dual_sensors() {
lox1.rangingTest(&measure1, false); // pass in 'true' to get debug data printout!
lox2.rangingTest(&measure2, false); // pass in 'true' to get debug data printout!
lox3.rangingTest(&measure3, false); // pass in 'true' to get debug data printout!
lox4.rangingTest(&measure4, false); // pass in 'true' to get debug data printout!
// print sensor one reading
Serial.print(F("1: "));
if(measure1.RangeStatus != 4) { // if not out of range
Serial.println(measure1.RangeMilliMeter-5);
} else {
Serial.print(F("Out of range"));
}
Serial.print(F(""));
// print sensor two reading
Serial.print(F("2: "));
if(measure2.RangeStatus != 4) {
Serial.print(measure2.RangeMilliMeter-7);
} else {
Serial.print(F("Out of range"));
}
Serial.println();
// print sensor three reading
Serial.print(F("3: "));
if(measure3.RangeStatus != 4) {
Serial.print(measure3.RangeMilliMeter-8);
} else {
Serial.print(F("Out of range"));
}
Serial.println();
// print sensor four reading
Serial.print(F("4: "));
if(measure4.RangeStatus != 4) {
Serial.print(measure4.RangeMilliMeter-25);
} else {
Serial.print(F("Out of range"));
}
Serial.println();
Serial.println();
}
void setup() {
Serial.begin(115200);
pinMode(LED_V,OUTPUT);
pinMode(LED_R,OUTPUT);
// wait until serial port opens for native USB devices
while (! Serial) { delay(1); }
pinMode(SHT_LOX1, OUTPUT);
pinMode(SHT_LOX2, OUTPUT);
pinMode(SHT_LOX3, OUTPUT);
pinMode(SHT_LOX4, OUTPUT);
Serial.println(F("Shutdown pins inited..."));
digitalWrite(SHT_LOX1, LOW);
digitalWrite(SHT_LOX2, LOW);
digitalWrite(SHT_LOX3, LOW);
digitalWrite(SHT_LOX4, LOW);
Serial.println(F("Both in reset mode...(pins are low)"));
Serial.println(F("Starting..."));
setID();
}
void loop() {
read_dual_sensors();
delay(10);
if(200 < measure4.RangeMilliMeter){
digitalWrite(28,HIGH);
}
else{
digitalWrite(28,LOW);
}
}
Estas dos líneas en setup() le dicen al programa que espere hasta que se conecte el USB. Si el USB no se conecta, el programa esperará para siempre.
Muchas gracias si funcionó
Moderador:
Por favor, lee las Normas del foro y edita tu código/error usando etiquetas de código.
Ve a edición, luego selecciona todo el código que has publicado, lo cortas y click en (<CODE/>)
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
