Tiny Collision Detector

BaldwinK

New Member
The HC-SR04 ultrasonic units are easy to program, requiring just a trigger pulse before timing the echo. But they can be difficult to hide in smaller models. Of course clever design can make one a feature – like Petoi’s Nybble:

nybble.jpg

Another rangefinder is the tiny VL53LOX

VL53.jpg

At only 25mm x 11mm this unit has a lot going for it and is almost as simple to program. It communicates via the i2c bus so has internal registers to address. For a single unit we start by setting up the link:

hi2csetup i2cmaster, 82, i2cfast, i2cbyte

Then to trigger a cycle we set a bit in register 0x00:

hi2cout 0x00,(0x01) ;trigger

Then the distance in mm will be ready in registers 0x1E, 0x1F :

hi2cin 0x1E,(b3,b2) ;read range in mm

To convert from the two input bytes to word value w3:

w3 = b3
w3 = w3 * 256
w3 = w3 | b2


And that’s how to program it!

Features and Issues

Life is never that simple of course but you can certainly get to see a screen of range numbers very quickly.

The ultrasonic sensors use a wide cone of sound so will not be too picky on size of target; they won’t care about light levels but can give a lot of false echoes.

This IR sensor might be disturbed by light levels but won’t give false readings due to target size or shape. However it has a very narrow cone of light and might just miss the target altogether if not accurately directed at it.

Like all complex electronics it hates RFI noise and can down tools in a certain situations. I have found a few filtering techniques but remember logic won’t help you. Best avoid noise.

Notice in the photo the orange tab protecting the chip apertures. Remove it if you don’t want unexplained variations of range!

Application

Wheeled vehicles require front and back sensors to prevent them running into things. If the sensors also provide distance information then this can be used for proportional deceleration. In this simple case only one sensor is in use at one time. So we can use the XSHUT pin to shutdown the other device.

I retrofitted two VL53LOX boards to a G-scale tram built 8 years ago, controlled by a Picaxe 14M2 to run at scale speed with on-board batteries:


RFI noise from the brushed motor knocked out one sensor and affected the other. I have ordered four more from China to see how they compare on this front. The recommended 220nF green capacitor has no impact, nor does earthed braiding. Three turns through a ferrite ring helped the most. Sifting errors and occasionally resetting the chips makes it workable.

The cone of ultrasound was a problem for another batch of trams fitted with radios and programmed to move around each other. The project worked fine on the bench but the trams would not move on the track. The sound reflected back from the sleepers - so the sensors had to be angled up at 45 degrees - severely impacting on their range and making them visible. For that write up see:

https://picaxeforum.co.uk/threads/model-trams-share-networks.27763/

The cone of IR light is much tighter and the beam crosses the sleepers without issue. However, the buffer stops may not be seen as the sensor gets closer because they are set at different heights. Surprisingly, fitting a piece of transparent plastic between the cross piece and the rails solves this problem.

sensor.jpg

The tiny sensor is mounted just above the safety fender and would disappear if painted black.


Addressing More Sensors

The VL53LOX has a soft i2c address at register 0x8A. It will initialise with address 0x27 but can be overwritten. So as not to reprogram all chips with the same new address, the others must be shut down.

San Francisco Cable Car.bas
 

Attachments

hippy

Senior Member
hi2cin 0x1E,(b3,b2) ;read range in mm

To convert from the two input bytes to word value w3:

w3 = b3
w3 = w3 * 256
w3 = w3 | b2
You should be able to avoid the conversion maths by reading the distance into 'w3' directly, knowing that 'w3' is formed from two bytes 'b7:b6' ...
Code:
hi2csetup i2cmaster, 82, i2cfast, i2cbyte
hi2cout 0x00,(0x01)
hi2cin 0x1E,(b7,b6)
sertxd("distance=",#w3,"mm",cr,lf)
Do you have a link to the VL53LOX datasheet or page you figured all this out from. That's a fantastic achievement as, when I had looked at what was available, it was impenetrable, and it seemed impossible to achieve what you have done so simply and elegantly.
 

BaldwinK

New Member
Thanks Hippy for making the code even simpler - logical of course!

I didn't want Picaxe users to miss out on this tiny unit by making things too complicated.

I have previously used careful language (to avoid a lawsuit maybe) when investigating the device. I posted the register map and my analysis (c and c++) here:


I also tacked an answer to the 'erco-laser range finder' thread but missed the Buzby thread.
 

hippy

Senior Member
I have previously used careful language (to avoid a lawsuit maybe) when investigating the device. I posted the register map and my analysis (c and c++) here:
https://www.robotrebels.org/index.php?topic=914.0
Excellent sleuthing and I expect many people will be grateful for your efforts and will benefit from that.

It is amazing, and somewhat amusing, that all those thousands of line of code for the API can be distilled down to just three lines of PICAXE code and be usable.
 

stan74

Senior Member
I got it working with picaxe code converted by mmotte on gcb forum. I submitted it. Converting picaxe to gcb is difficult for me.
The idea was for a robot but the latency is a factor. Registers can be set to speed things or accuracy.
 
Top