1744

Although designed as a give-away gadget for trade shows etc. this ruler loaded with RPi information can electronically measure distances of up to two meters.

Although designed as a give-away gadget for trade shows and similar events, this ruler can electronically measure distances up to 2 m with the help of a VL53L0X time-of-flight (ToF) sensor.

If you happen to have one of these rulers because you visited us in 2018 at electronica or at the WOTS you will have noticed that it has solder pads on it and space for two connectors. The ruler can be equipped with 22 LEDs (0805 package) with current limiting resistor (0805 package, 1kOhm will do), a 40-way RPi extension socket (16 mm high) and a 6-pin I2C header/socket (or wires, whatever you prefer).

Although useful all by itself, the RPi Ruler Gadget becomes a real high-tech gadget when you solder the LEDs on it, plug the ruler on an RPi and connect the ToF sensor.
 
180483 RPi Ruler Gadget prototype
The prototype of the RPi Ruler Gadget

Build the ruler

To make the bare PCB into an electronic ruler you have to solder an RPi extension connector on it and get yourself a VL53L0X-compatible module like this one.

 
VL53L0X break-out board
VL53L0X break-out board

The LEDs on the ruler are optional but give it a fun aspect. The software available below uses the LEDs as a distance scale.

The software was written on a Raspberry Pi 3 model B V1.2 but should work also on other RPis with a 40-pin extension connector. Connect the ruler before powering on the RPi.

Installation of the software on the RPi

  1. Download and install wiringPi 
  2. Download and unpack the VL53L0X driver STSW-IMG005 from ST, get it from the Get Software section.
  3. Download and unpack the Raspberry Pi adapter VL53L0X_rasp by Cassou (Mathieu Cassard)
  4. Download the Makefile below and copy it into the folder VL53L0X_rasp (overwrite the existing file).
  5. Download the file rpi_ruler.c below and place it in the folder VL53L0X_rasp/examples
  6. Supposing that you followed the steps above and that you put everything in your home directory, now do this:
cd VL53L0X_rasp
make API_DIR=~/VL53L0X_1.0.2/
make examples API_DIR=~/VL53L0X_1.0.2/
There should be no warnings or errors.
To run the RPi ruler program do:
./bin/rpi_ruler
If you connected a display to the RPi you should see measurements scrolling by. Waving your hand or an object in front of the sensor should result in a plausible distance in millimeters. Nothing in front of the sensor results in the value 8192 (out of range).

Notes

  • Use a 16-mm high (of higher) socket for the RPi extension connector because the ruler has to pass over the RPi's USB connector.
  • The VL53L0X sensor can be powered from 2.6 to 3.5 V. However, VL53L0X break-out modules tend to have an on-board LDO to allow them to be powered from 5 V. The I2C connector on the ruler only supplies 3.3 V. This is not a problem as many LDOs simply pass the voltage when it drops below their minimum input voltage. If 5 V is really necessary, it can be taken from the RPi extension connector.
  • Your VL53L0X sensor may have a protective film stuck on it. If it does, remove it before using it.
 
180483 RPi Ruler Gadget ToF sensor
RPi Ruler Gadget with VL53L0X ToF sensor

Component List

22x LED, 0805
22x resistor, 1 kΩ, 0805
1x 40-way (2x20) pinheader socket, 2.54 mm pitch, 16 mm high, f.i. Samtec ESQ-120-33-T-D
1x 6-way pin socket and mating header to connect to the VL53L0X module
1x VL53L0X module