Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Vl53l0x

Hi guys, im working with the VL53L0X and i try to send the measure of the sensor by RF module but i cant read the same value can anyone help me. this is my code

#include <Wire.h>
#include <VL53L0X.h>
#include <SPI.h>
#include <RF24.h>
VL53L0X sensor;
RF24 radio(7, 8); // CE, CSN
const byte identificacion[6] = "11011";
int n_Samples = 5; // numero de muestras para promediar
 
#define LONG_RANGE // Aumenta sensibilidad, +rango, -precision
//#define HIGH_SPEED // Mayor velocidad, menor precision
//#define HIGH_ACCURACY // Alta precision, menor velocidad


void setup() 
{
   Serial.begin(9600);
   Wire.begin();
  //Serial.begin (9600); 
  sensor.init();
  sensor.setTimeout(500);
  radio.begin();
  radio.openWritingPipe(identificacion);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
 //###### Parametros Medida simple ##########
#if defined LONG_RANGE
// Limite de la tasa de retorno (por defecto 0.25 MCPS)
 sensor.setSignalRateLimit(0.1);
// Periodo de pulso laser (por defecto 14 y 10 PCLKs)
 sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18);
 sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14);
#endif
 
#if defined HIGH_SPEED
// reduce tiempo estimado a 20 ms (por defecto 33 ms)
 sensor.setMeasurementTimingBudget(20000);
#elif defined HIGH_ACCURACY
// incrementa tiempo estimado a 200 ms
 sensor.setMeasurementTimingBudget(200000);
#endif
}
void loop() 
{float DISTANCIA = getDISTANCIA (n_Samples);
 
 if (sensor.timeoutOccurred()) {
 Serial.println(" TIME OUT");
 }else {
 if (DISTANCIA< 2) Serial.println("1");
 else if (DISTANCIA>220) Serial.println("3");
 else { 
 Serial.println(DISTANCIA, 0); // distancia en cm y 1 decimal
 //Serial.println(" cm"); 
 }
 }
 
 
 float b= radio.write("&DISTANCIA", 0);
  Serial.println(b);
 
  delay(300); // Un segundo (1000 milisegundos) de espera entre envío y envío
}
float getDISTANCIA(int n) { // hacemos "n" mediciones
 
 float SUMA_n = 0;
 for (int i = 0; i < n; i++) { 
 SUMA_n += sensor.readRangeSingleMillimeters();
 }
 return( SUMA_n /n /10); // Promedio en centimetros
}

Just to clarify, are you saying that your VL53L0X sensor is working correctly, but the readings you are receiving on the other end of your system with an RF module are not matching? If so, I suspect the problem is with your RF module or your implementation of the RF24 library. We did not write that library, so we can only be of limited help. Also, it looks like you only posted the program for your transmitter side of the system; it’s possible the problem is with the code on the receiver side.

I am not very familiar with the RF24 library, but the two lines from your code that I copied below seem suspect to me:

  float b= radio.write("&DISTANCIA", 0);
  Serial.println(b);

Can you explain what those should be doing?

Brandon