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

Technical Support
Staff 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

Technical Support
Staff 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.
 

hippy

Technical Support
Staff member
These sensors are just $1.60 now:
Wow - I recall they were quite expensive when they first arrived, and it seemed unimaginable that interfacing to them would come down to just a couple of lines of I2C code.

Could you perhaps test how well they work through transparent plastic, whether it can determine distance of objects through that ?

I was thinking that putting them behind a hole in a panel could make them useful as 'touch sensors'.
 

steliosm

Senior Member
According to the datasheet it is a 940nm wavelength, which is in infrared zone. Plastics that are infrared transmitting should be fine.

If you need to sense touch, using it as a proximity sensor, you could also consider the TCRT5000 sensor (ir transmitter/receiver pair).
 

erco

Senior Member
Wow - I recall they were quite expensive when they first arrived, and it seemed unimaginable that interfacing to them would come down to just a couple of lines of I2C code.
The ones I have came from that AE Wanzai store link, ten pcs were $19.84 shipped total. An Arduino would need a library download plus 5K of program space to do what Picaxe does in 24 bytes! Whenever Rev Ed makes a new chip (!), please consider adding a LASER command (like ULTRA) to the firmware to work seamlessly with these.
 

erco

Senior Member
Could you perhaps test how well they work through transparent plastic, whether it can determine distance of objects through that ?
No go on that. I tried plexiglas, clear food container, thin clear package blister material, a clear poly bag, even eyeglass lenses. Sensor measures distance properly to each one.
 

papaof2

Senior Member
I have a media cabinet with glass doors - that glass passes the IR from various remote controls to the equipment inside the cabinet so perhaps it's a matter of finding the "right" clear plastic (nm range passed)? I guess the actual color of the plastic may be immaterial if the plastic is "transparent" to IR...
 

erco

Senior Member
I'm sure some of the laser light goes through, but all that matters here is that clear plastic reflects sufficient energy to be detected by the sensor.
 

erco

Senior Member
Conversely, there are visibly opaque materials (red polystyrene for instance) that allows IR to pass through with almost no attenuation. Most materials will transmit, absorb and/or reflect some portion of visible and IR wavelengths.

Getting back to touch sensors, the laser beam from this sensor is very narrow. If you HAD to use this as a touch sensor, aim the laser to shine through a small (1/4") hole in any material so nothing is reflected until a finger blocks the hole.
 

hippy

Technical Support
Staff member
Getting back to touch sensors, the laser beam from this sensor is very narrow. If you HAD to use this as a touch sensor, aim the laser to shine through a small (1/4") hole in any material so nothing is reflected until a finger blocks the hole.
That was my thoughts, even a smaller hole. It's nice to be able to add something to stop grime, dust and even furniture polish getting in. A plastic insert can give a nice flush and professional finish when one wants something which looks good -

Code:
----------------. .----. .----------------
                | |    | |
----------------' |    | `----------------
            ______|    |______
           |__________________|
                   ____
                  /    \
                 /      \
                |        |
That said, I've found a sewing needle size hole in a case with a LED behind it looks great if you don't need wide angle viewing. From even a few inches away the hole is invisible until the LED is turned on. Easy to do for small plastic cases.
 

erco

Senior Member
Edit: Keith's first post mentions detecting transparent plastic: "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."




Try it, but my tests don't indicate that a clear plastic plug will work. I suggested a hole. A HOLE hole. Also, there is some offset between the laser and sensor. Misalignment is more critical at shorter distances, so parallax error might require a slit instead of a hole.

There are plenty of better-suited dedicated touch sensors, but your mention of the LED reminded me of the touch-sense use of LEDs.


Some people have used LEDs as sensors and display: https://forums.parallax.com/discussion/86035/led-touch-sensor/p1
 
Last edited:
Top