TIMEOUT ARDUINO UNO VL53LOX

Hi there,

i hope i post my issue correctly here in a new thread. Equipment:
-Arduino UNO Board
-VL53LOX TOF sensor
-LCD Display 16x2
-Support Board for the LCD display
-Breadboard

My problem is that the serial monitor shows constantly timeouts through the whole emasurement when my code is corretly compiled and booted on the Arduino Board. I dont get any error status and basically everything works. But here comes the problem sometimes the distance measurement works, sometimes not. When its not working, the LCD Display shows -1mm distance constantly. The Serial Monitor shows TIMEOUT.

I used a new TOF sensor, a new Arduino Uno Board, checked everything for shacky wires, checked the correct setted Board and Port and dont get any wiser through other Posts in this forum or in the internet. I checked to use the correct libraries and worked exactly after the instruction of Robojax

Link:Display VL53L0X distance as bargraph on LCD - Robojax

My Code:
/*
*

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see https://www.gnu.org/licenses/.
/
/

*

This is Arduino code to measure distance with VL53L0X and display it on LCD1602 with I2C module
Distance is displayed in mm (millimetre) or cm (centimetre).

Original Laser Sensor source source: GitHub - adafruit/Adafruit_VL53L0X: Arduino library for Adafruit VL53L0X
Modified by Ahmad Shamshiri for Robojax.com
Date Modified: June 28, 2018 at 19:06 in Ajax, Ontario, Canada

Pin connection

VL53L0X Pin Arduino Pin
VCC 5V
GND GND
SDA A4 or SDA if available
SCL A5 or SCL if available
GPIO1 leave it unconnected
XSHUT unconnected

*/
#include <Wire.h>
#include <VL53L0X.h>
VL53L0X sensor;
#define maxDistance 500

int VCC2= 13;// 2nd VCC for laser sensor

#include <LiquidCrystal_I2C.h>
byte lcdNumCols = 16; // -- number of columns in the LCD
byte lcdLine = 2; // -- number of line in the LCD
// Set the LCD address to 0x26/0x3F for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, lcdNumCols, lcdLine);// use I2C Scanner to find the address: 0x27 or something like that

#include <LcdBarGraphRobojax.h>
LcdBarGraphRobojax rjx(&lcd, 16, 0, 0); // -- creating 16 character long bargraph starting at char 0 of line 0 (see video)

void setup()
{

Serial.begin(9600);
pinMode(VCC2, OUTPUT);// set pin 13 HIGH for extra 5V
digitalWrite(VCC2, HIGH);// make pin 13 HIGH so we have extra 5V

Wire.begin();

sensor.init();
sensor.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)).
sensor.startContinuous();

// initialize the LCD,
lcd.init();
lcd.clear();
lcd.print("Robojax");
lcd.setCursor (0,1);
lcd.print("Bargraph VL53L0X");
lcd.backlight(); // Turn on the blacklight and print a message.
// -- do some delay: some time I've got broken visualization

delay(2000);
lcd.clear();// clear the screen from previous value

}

void loop()
{
int distance=sensor.readRangeContinuousMillimeters();
if (maxDistance<distance){
distance=0;
}
// int distance =sensor.startContinuous(100);
rjx.clearLine(1);// clear line 1 to display fresh voltage value

// -- draw bar graph from the analog value read
rjx.drawValue( distance, maxDistance);
// -- do some delay: frequent draw may cause broken visualization
//delay(100);

lcd.setCursor (0,1); // go to start of 2nd line
lcd.print("Dist.:");
lcd.setCursor (7,1); // go to start of 2nd line
lcd.print(distance);
lcd.print("mm");

if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }

Serial.println();
delay(500);
}

Can someone help me :frowning: ??

Disconnect the display and test the VL53LOX in isolation using the demo sketch that comes with the library.

It worked , the serial monitor shows the correct distance values. So how is it that with the LCD it isnt working ?

Does your VL53L0X breakout board use 3.3V or 5V I2C signals?

How about your LCD?

How is it all wired? (schematic diagram)

wvmarle:
Does your VL53L0X breakout board use 3.3V or 5V I2C signals?

How about your LCD?

How is it all wired? (schematic diagram)

-> 5v I2C for TOF sensor
-> Pin 13 for additionally 5V programmed on HIGH
-> Attached picture of wiring

ARahmani:
-> Pin 13 for additionally 5V programmed on HIGH

Output pins are NOT power supply pins.

Where you need 5V connect it to the 5V pin. All of them.

I deleted the programm code for pin 13 and also put the wires for ground and power supplay on the breadboard. It runs perfectly and i dont get any Timeouts any more. Im embarassed somehow i didnt came on this idea on my own and shocked that this kinda "wrong" wiring is sold for money on Robojax.com

Thank you for helping that quick mate!

Indeed, pretty horrible. Especially the part where they pick pin 13. Or did they? This is part of the code posted on that web site you link to:

int VCC2= 2;// 2nd VCC for laser sensor

[...]

void setup()
{

Serial.begin(9600);
  pinMode(VCC2, OUTPUT);// set pin 13 HIGH for extra 5V
  digitalWrite(VCC2, HIGH);// make pin 13 HIGH so we have extra 5V

So the comment is wrong! VCC2 is set to pin 2, not pin 13 as the comment suggests. Had you stuck to pin 2 it would have probably have worked just fine. It should work at any pin except 0, 1, 13, A6 and A7.... (0, 1 are connected to the Serial interface; 13 to the built-in LED and A6/A7 are analog input only). That built-in LED is probably messing up the pin voltage.

So - why is it a bad idea? Pins can deliver a good amount of current: 20 mA continuous, peaks of 40 mA. But they are meant for delivering low current signals, not as power source. That built-in LED no doubt pulls down the voltage at the pin low enough to mess up with the sensor's regulator and/or its I2C communications.

Now why would you do it? Sometimes there is a very good reason to power down a sensor, e.g. to prevent the sensor from interfering with another or saving power. Been there done that, and will do it again when needed. Just be VERY aware of what you're doing, and the pitfalls that you may encounter (supply voltage drop, ground lift and unstable voltage due to the internal resistance, phantom powering through I/O pins, insufficient current available).

Why does robojax do it here? Really, it's beyond me. The comments point quite strongly to the typical "I've ran out of 5V and/or ground connections!" beginner's mistake, not realising you can happily connect several wire to a single pin. Anyone writing learning resources (and knows how to deal with LCD displays and make it do interesting things) I expect to be at a higher level than that. Something basic as getting comments right can also go a long way - so that's another tip for you, the moment you spot comments not matching the code it's usually (but not always, so do investigate) the comments that are wrong.

wvmarle:
Indeed, pretty horrible. Especially the part where they pick pin 13. Or did they? This is part of the code posted on that web site you link to:

So the comment is wrong! VCC2 is set to pin 2, not pin 13 as the comment suggests. Had you stuck to pin 2 it would have probably have worked just fine. It should work at any pin except 0, 1, 13, A6 and A7.... (0, 1 are connected to the Serial interface; 13 to the built-in LED and A6/A7 are analog input only). That built-in LED is probably messing up the pin voltage.

So - why is it a bad idea? Pins can deliver a good amount of current: 20 mA continuous, peaks of 40 mA. But they are meant for delivering low current signals, not as power source. That built-in LED no doubt pulls down the voltage at the pin low enough to mess up with the sensor's regulator and/or its I2C communications.

Now why would you do it? Sometimes there is a very good reason to power down a sensor, e.g. to prevent the sensor from interfering with another or saving power. Been there done that, and will do it again when needed. Just be VERY aware of what you're doing, and the pitfalls that you may encounter (supply voltage drop, ground lift and unstable voltage due to the internal resistance, phantom powering through I/O pins, insufficient current available).

Why does robojax do it here? Really, it's beyond me. The comments point quite strongly to the typical "I've ran out of 5V and/or ground connections!" beginner's mistake, not realising you can happily connect several wire to a single pin. Anyone writing learning resources (and knows how to deal with LCD displays and make it do interesting things) I expect to be at a higher level than that. Something basic as getting comments right can also go a long way - so that's another tip for you, the moment you spot comments not matching the code it's usually (but not always, so do investigate) the comments that are wrong.

Thank you for your effort! I got it