WhiteSpace
Well-known member
I read a few weeks ago a thread about the TOF10120, which seemed a rather more useful proximity detector than the laser plus Hamamatsu S6986 that I initially tried. I then thought that it might be interesting to output the distance to a screen, and then even more interesting to have the sensor rotate in order to produce some kind of image of what's in front of a vehicle. I've learned a lot about stepper motors and multiple devices on i2c over the last few weeks, and had to delve back into trigonometry, last used a few decades ago for O-level maths.
It now seems to be working. There are some refinements still to come, but I thought others might be interested to see the progress so far.
In terms of set-up, I have a 28x2 at 64MHz, outputting the step codes to a TC4469 driver (the same chip I am using for my remote controlled vehicle). The TC4469 controls a very small bipolar stepper motor off ebay that does 0.18 degrees per step after the gearing (so 2000 steps per 360 degree rotation. The data sheet for the TC4469 has a set-up for a bipolar stepper (Fig. 5.1 here: http://ww1.microchip.com/downloads/en/DeviceDoc/21425C.pdf), but I couldn't get it to work and couldn't reconcile the two input lines with the logic in the truth table, so I found another diagram (Fig 24 here: http://www.t-es-t.hu/download/microchip/an907a.pdf) and used pins B.0 to B.3 to drive the 4 inputs of the TC4469. There seem to be a number of permutations of stepper codes - some driving one line at a time and others driving 2. I ended up with a full-step code that drives 2 lines at a time. I spent a long time getting the stepper codes, delay between steps, direction etc right. A set of 4 LEDs was useful for seeing what was happening. I also tried a slightly larger stepper with 1.25 degrees per step which was a better arrangement because it was faster, but after running happily for a while it became temperamental and kept sticking and jumping, so I parked it. It may be a dodgy contact somewhere that I will be able to track down and resolve.
Thanks to a couple of useful threads on the forum, particularly: addressing multiple i2c slaves from https://picaxe.com/docs/axe110_i2c.pdf and https://picaxeforum.co.uk/threads/i2c-devices-whats-the-preferred-way-to-control-multiple-devices.31622/#post-328259 I was able to set up both the SSD1306 display and the TOF10120.
The laser range sensor outputs a range up to 2000mm (limited in my case to 900mm in the interests of not exceeding the limits of the word variable during the calculations. The angle is known because each sensor reading corresponds to a specific step (or with this motor, the end of a known 5-step loop that covers 0.9 degrees). Range and angle are converted into x,y coordinates by two lookup tables that hold the sine and cosine of the angle corresponding to each of the 67 5-steps that cover the 60 degrees of a sweep. I'm assuming that a lookup table is quicker than going to scratchpad. x coordinates are measured from column 63 of the display, so coordinates to the left are deducted from 63. Y coordinates are divided by 8. The whole number gives the row and the remainder sets one of 8 byte patterns that lights the right dot in the row. It took quite a lot of trial and error to get it right. There may be a quicker way of addressing the right dot on the screen.
I attach the code as it currently stands.
It now seems to be working. There are some refinements still to come, but I thought others might be interested to see the progress so far.
In terms of set-up, I have a 28x2 at 64MHz, outputting the step codes to a TC4469 driver (the same chip I am using for my remote controlled vehicle). The TC4469 controls a very small bipolar stepper motor off ebay that does 0.18 degrees per step after the gearing (so 2000 steps per 360 degree rotation. The data sheet for the TC4469 has a set-up for a bipolar stepper (Fig. 5.1 here: http://ww1.microchip.com/downloads/en/DeviceDoc/21425C.pdf), but I couldn't get it to work and couldn't reconcile the two input lines with the logic in the truth table, so I found another diagram (Fig 24 here: http://www.t-es-t.hu/download/microchip/an907a.pdf) and used pins B.0 to B.3 to drive the 4 inputs of the TC4469. There seem to be a number of permutations of stepper codes - some driving one line at a time and others driving 2. I ended up with a full-step code that drives 2 lines at a time. I spent a long time getting the stepper codes, delay between steps, direction etc right. A set of 4 LEDs was useful for seeing what was happening. I also tried a slightly larger stepper with 1.25 degrees per step which was a better arrangement because it was faster, but after running happily for a while it became temperamental and kept sticking and jumping, so I parked it. It may be a dodgy contact somewhere that I will be able to track down and resolve.
Thanks to a couple of useful threads on the forum, particularly: addressing multiple i2c slaves from https://picaxe.com/docs/axe110_i2c.pdf and https://picaxeforum.co.uk/threads/i2c-devices-whats-the-preferred-way-to-control-multiple-devices.31622/#post-328259 I was able to set up both the SSD1306 display and the TOF10120.
The laser range sensor outputs a range up to 2000mm (limited in my case to 900mm in the interests of not exceeding the limits of the word variable during the calculations. The angle is known because each sensor reading corresponds to a specific step (or with this motor, the end of a known 5-step loop that covers 0.9 degrees). Range and angle are converted into x,y coordinates by two lookup tables that hold the sine and cosine of the angle corresponding to each of the 67 5-steps that cover the 60 degrees of a sweep. I'm assuming that a lookup table is quicker than going to scratchpad. x coordinates are measured from column 63 of the display, so coordinates to the left are deducted from 63. Y coordinates are divided by 8. The whole number gives the row and the remainder sets one of 8 byte patterns that lights the right dot in the row. It took quite a lot of trial and error to get it right. There may be a quicker way of addressing the right dot on the screen.
I attach the code as it currently stands.
Attachments
-
14.6 KB Views: 9