Line following with QTR-8RC Infra Red Reflectance Sensor Array

stan74

Senior Member
That's a nice sensor, stan74. Digital output and you can break it into two 4-sensor boards, per http://www.robotshop.com/en/pololu-qtr-8rc-infrared-sensor-array.html

Properly wired, you can quickly read all 8 sensors with a single pinsb/pinsc command. That uses 8 input pins directly, otherwise you could use an 8 to 3 line encoder like a SN74LS348 and use just 3 input pins.
I was thinking of 74HC150 or DM74151A. £4 and bother..use 8 lines I think. It's a simple sensor. I used LDRs the same way.
 

stan74

Senior Member
You had more luck than me. I can't get even 1 sensor to do anything.
Code:
[color=Black]main:[/color]
[color=Purple]pinc.4[/color][color=DarkCyan]=[/color][color=Navy]1 [/color][color=Green]; charge cap[/color]
[color=Blue]pauseus [/color][color=Navy]20[/color]
[color=Purple]temp1[/color][color=DarkCyan]=[/color][color=Navy]0[/color]
[color=Blue]input c.4 [/color][color=Green];drain cap[/color]
[color=Blue]do while [/color][color=Purple]pinc.4[/color][color=DarkCyan]=[/color][color=Navy]1
      [/color][color=Blue]inc [/color][color=Purple]temp1[/color]
[color=Blue]loop
sertxd ([/color][color=Black]#[/color][color=Purple]temp1[/color][color=Black],[/color][color=Blue]cr[/color][color=Black],[/color][color=Blue]lf)
goto [/color][color=Black]main[/color]
http://www.hobbytronics.co.uk/qtr-8rc-sensor?utm_source=google&utm_medium=googleshopping&utm_campaign=googlebase&gclid=Cj0KEQiAtK3DBRCBxt-Yxduq5p4BEiQAbFiaPbzGVBIJ41UlQmfQ_4Xn3MdTIs0JcM7PvXaEZ9mgIgkaAlOa8P8HAQ
 

Rick100

Senior Member
You had more luck than me. I can't get even 1 sensor to do anything.
Hello Stan,

I think you need an 'output c.4' before the 'pinc.4=1' line. I would run the processor as fast as possible and use a word variable for the counter during your initial testing.

This thread is very interesting. The basic problem appears to be a slow stepper motor that's losing an unknown number of steps, and a slow loop for updating the 'position' of that motor.

Good luck,
Rick
 

erco

Senior Member
You had more luck than me. I can't get even 1 sensor to do anything.
Did you try reading the digital output? From your link: Each sensor provides a separate digital I/O-measurable output.

You can also feed analog input signal into a Picaxe input pin and use it like a comparator.

 

edmunds

Senior Member
Stan,

I have some of these sensors somewhere in the drawer, but I have forgotten what they are, so I don't have a data sheet at hand. If I remember correctly, they are just a photodiode and a phototransistor in one package. If that is the case, what are you trying to do? Just pwm the led and read the phototransistor with ADC. Or digital if you 'calibrate' it before for the light level you have.


Good luck,

Edmunds

EDIT: Here is the data sheet.
 
Last edited:

stan74

Senior Member
If I scope the pins I can see the period change from black to white but using the code scopeing the pins wouldn't trigger..probably my 1st attempt is wrong.I used ldrs this way,ages ago.
Code:
[color=Green];6 sensor,dual continuous servo line follower[/color]
[color=Navy]#picaxe [/color][color=Black]20m2[/color]
[color=Blue]setfreq m32
symbol [/color][color=Black]lservo[/color][color=DarkCyan]=[/color][color=Blue]b.2
symbol [/color][color=Black]rservo[/color][color=DarkCyan]=[/color][color=Blue]b.3
symbol [/color][color=Black]reflec[/color][color=DarkCyan]=[/color][color=Purple]w0[/color]
[color=Blue]symbol [/color][color=Black]counter[/color][color=DarkCyan]=[/color][color=Purple]b2[/color]

[color=Navy]#define [/color][color=Black]setval [/color][color=Navy]2000[/color]
[color=Green];servo lservo,170 ;default speed
;servo rservo,170[/color]
[color=Black]main:

counter[/color][color=DarkCyan]=[/color][color=Navy]1[/color]
[color=Blue]do
      [/color][color=Purple]pinsc[/color][color=DarkCyan]=[/color][color=Black]counter
      [/color][color=Blue]pauseus [/color][color=Navy]20
      [/color][color=Black]reflec[/color][color=DarkCyan]=[/color][color=Navy]0
      [/color][color=Purple]dirsc[/color][color=DarkCyan]=[/color][color=Black]counter
      [/color][color=Blue]do while [/color][color=Purple]pinsc[/color][color=DarkCyan]=[/color][color=Navy]1
            [/color][color=Blue]inc [/color][color=Black]reflec
      [/color][color=Blue]loop
      if [/color][color=Black]reflec[/color][color=DarkCyan]<[/color][color=Black]setval [/color][color=Blue]then
            if [/color][color=Black]counter[/color][color=DarkCyan]=[/color][color=Navy]1 [/color][color=Blue]then servopos [/color][color=Black]lservo,[/color][color=Navy]179[/color][color=Black]:[/color][color=Blue]servopos [/color][color=Black]rservo,[/color][color=Navy]161[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main [/color][color=Green];sensor 0
            [/color][color=Blue]elseif [/color][color=Black]counter[/color][color=DarkCyan]=[/color][color=Navy]2 [/color][color=Blue]then servopos [/color][color=Black]lservo,[/color][color=Navy]176[/color][color=Black]:[/color][color=Blue]servopos [/color][color=Black]rservo,[/color][color=Navy]164[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main [/color][color=Green];sensor 1
            [/color][color=Blue]elseif [/color][color=Black]counter[/color][color=DarkCyan]=[/color][color=Navy]4 [/color][color=Blue]then servopos [/color][color=Black]lservo,[/color][color=Navy]173[/color][color=Black]:[/color][color=Blue]servopos [/color][color=Black]rservo,[/color][color=Navy]167[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main [/color][color=Green];sensor 2
            [/color][color=Blue]elseif [/color][color=Black]counter[/color][color=DarkCyan]=[/color][color=Navy]8 [/color][color=Blue]then servopos [/color][color=Black]lservo,[/color][color=Navy]167[/color][color=Black]:[/color][color=Blue]servopos [/color][color=Black]rservo,[/color][color=Navy]173[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main [/color][color=Green];sensor 3
            [/color][color=Blue]elseif [/color][color=Black]counter[/color][color=DarkCyan]=[/color][color=Navy]16 [/color][color=Blue]then servopos [/color][color=Black]lservo,[/color][color=Navy]164[/color][color=Black]:[/color][color=Blue]servopos [/color][color=Black]rservo,[/color][color=Navy]176[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main [/color][color=Green];sensor 4  
            [/color][color=Blue]elseif [/color][color=Black]counter[/color][color=DarkCyan]=[/color][color=Navy]32 [/color][color=Blue]then servopos [/color][color=Black]lservo,[/color][color=Navy]161[/color][color=Black]:[/color][color=Blue]servopos [/color][color=Black]rservo,[/color][color=Navy]179[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main [/color][color=Green];sensor 5        
            [/color][color=Blue]endif
      endif
      [/color][color=Black]counter[/color][color=DarkCyan]=[/color][color=Black]counter[/color][color=DarkCyan]+[/color][color=Black]counter[/color]
[color=Blue]loop until [/color][color=Black]counter[/color][color=DarkCyan]=[/color][color=Navy]64[/color]
[color=Blue]servopos [/color][color=Black]lservo,[/color][color=Navy]170[/color][color=Black]:[/color][color=Blue]servopos [/color][color=Black]rservo,[/color][color=Navy]170[/color]
[color=Blue]goto [/color][color=Black]main[/color]
 

stan74

Senior Member
Spotted errors but motors start slow then go fast.
Code:
[color=Green];6 sensor,dual continuous servo line follower[/color]
[color=Navy]#picaxe [/color][color=Black]20m2[/color]
[color=Blue]setfreq m32
symbol lservo[/color][color=DarkCyan]=[/color][color=Blue]b.2
symbol rservo[/color][color=DarkCyan]=[/color][color=Blue]b.3
symbol [/color][color=Purple]reflec[/color][color=DarkCyan]=[/color][color=Purple]w0[/color]
[color=Blue]symbol [/color][color=Purple]counter[/color][color=DarkCyan]=[/color][color=Purple]b2[/color]

[color=Navy]#define [/color][color=Black]setval [/color][color=Navy]2000[/color]
[color=Blue]servo lservo[/color][color=Black],[/color][color=Navy]170 [/color][color=Green];default speed[/color]
[color=Blue]servo rservo[/color][color=Black],[/color][color=Navy]170[/color]
[color=Black]main:[/color]

[color=Purple]counter[/color][color=DarkCyan]=[/color][color=Navy]1[/color]
[color=Blue]do
      [/color][color=Purple]dirsc[/color][color=DarkCyan]=[/color][color=Purple]counter [/color][color=Green];make pin output
      [/color][color=Purple]pinsc[/color][color=DarkCyan]=[/color][color=Purple]counter [/color][color=Green];make pin high
      [/color][color=Blue]pauseus [/color][color=Navy]20 [/color][color=Green];charge cap
      [/color][color=Purple]reflec[/color][color=DarkCyan]=[/color][color=Navy]0
      [/color][color=Blue]reverse c.0[/color][color=Black],[/color][color=Blue]c.1[/color][color=Black],[/color][color=Blue]c.2[/color][color=Black],[/color][color=Blue]c.3[/color][color=Black],[/color][color=Blue]c.4[/color][color=Black],[/color][color=Blue]c.5 [/color][color=Green];make pin input to discharge cap
      [/color][color=Blue]do while [/color][color=Purple]pinsc[/color][color=DarkCyan]=[/color][color=Navy]1
            [/color][color=Blue]inc [/color][color=Purple]reflec
      [/color][color=Blue]loop [/color][color=Green];time discharge
      [/color][color=Blue]if [/color][color=Purple]reflec[/color][color=DarkCyan]<[/color][color=Black]setval [/color][color=Blue]then
            if [/color][color=Purple]counter[/color][color=DarkCyan]=[/color][color=Navy]1 [/color][color=Blue]then servopos lservo[/color][color=Black],[/color][color=Navy]179[/color][color=Black]:[/color][color=Blue]servopos rservo[/color][color=Black],[/color][color=Navy]161[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main [/color][color=Green];sensor 0
            [/color][color=Blue]elseif [/color][color=Purple]counter[/color][color=DarkCyan]=[/color][color=Navy]2 [/color][color=Blue]then servopos lservo[/color][color=Black],[/color][color=Navy]176[/color][color=Black]:[/color][color=Blue]servopos rservo[/color][color=Black],[/color][color=Navy]164[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main [/color][color=Green];sensor 1
            [/color][color=Blue]elseif [/color][color=Purple]counter[/color][color=DarkCyan]=[/color][color=Navy]4 [/color][color=Blue]then servopos lservo[/color][color=Black],[/color][color=Navy]173[/color][color=Black]:[/color][color=Blue]servopos rservo[/color][color=Black],[/color][color=Navy]167[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main [/color][color=Green];sensor 2
            [/color][color=Blue]elseif [/color][color=Purple]counter[/color][color=DarkCyan]=[/color][color=Navy]8 [/color][color=Blue]then servopos lservo[/color][color=Black],[/color][color=Navy]167[/color][color=Black]:[/color][color=Blue]servopos rservo[/color][color=Black],[/color][color=Navy]173[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main [/color][color=Green];sensor 3
            [/color][color=Blue]elseif [/color][color=Purple]counter[/color][color=DarkCyan]=[/color][color=Navy]16 [/color][color=Blue]then servopos lservo[/color][color=Black],[/color][color=Navy]164[/color][color=Black]:[/color][color=Blue]servopos rservo[/color][color=Black],[/color][color=Navy]176[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main [/color][color=Green];sensor 4  
            [/color][color=Blue]elseif [/color][color=Purple]counter[/color][color=DarkCyan]=[/color][color=Navy]32 [/color][color=Blue]then servopos lservo[/color][color=Black],[/color][color=Navy]161[/color][color=Black]:[/color][color=Blue]servopos rservo[/color][color=Black],[/color][color=Navy]179[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main [/color][color=Green];sensor 5        
            [/color][color=Blue]endif
      endif
      [/color][color=Purple]counter[/color][color=DarkCyan]=[/color][color=Purple]counter[/color][color=DarkCyan]+[/color][color=Purple]counter[/color]
[color=Blue]loop until [/color][color=Purple]counter[/color][color=DarkCyan]=[/color][color=Navy]64[/color]
[color=Blue]servopos lservo[/color][color=Black],[/color][color=Navy]170[/color][color=Black]:[/color][color=Blue]servopos rservo[/color][color=Black],[/color][color=Navy]170[/color]
[color=Blue]goto [/color][color=Black]main[/color]
 
Last edited:

stan74

Senior Member
Thanks Edmunds but it's like erco said. Built in capacitor so make port high,wait for cap to charge,make port input and time it discharge ie logic 0.
Capture.PNG
 

stan74

Senior Member
I don't like signed numbers in picaxe basic, checking the high bit to see if it's negative and some expressions are awkward with the left to right maths. These would be useful ( ). 65532+3 isn't 0... Zero is a positive number :)
I wouldn't attempt this without a scope. The sensors see a 1cm black line at 5mm and there's about 1mS difference between black and white. Moving the sensor 1mm up or down and the results change but all sensors change the same. 6 or 128 sensors is rubbish if you can't get reliable data. Here is some simple code I'm using. I didn't notice any speed change moving the sensors over a line.Maybe fit 6 leds to see what's happening.
Code:
[color=Green];6 sensor,dual continuous servo line follower[/color]
[color=Navy]#picaxe [/color][color=Black]20m2[/color]
[color=Blue]setfreq m32
symbol lservo[/color][color=DarkCyan]=[/color][color=Blue]b.2
symbol rservo[/color][color=DarkCyan]=[/color][color=Blue]b.3
symbol [/color][color=Purple]reflec[/color][color=DarkCyan]=[/color][color=Purple]w0[/color]
[color=Blue]symbol [/color][color=Purple]counter1[/color][color=DarkCyan]=[/color][color=Purple]b2[/color]
[color=Blue]symbol [/color][color=Purple]temp1[/color][color=DarkCyan]=[/color][color=Purple]b3[/color]
[color=Navy]#define [/color][color=Black]chargetime [/color][color=Navy]20
#define [/color][color=Black]setval [/color][color=Navy]7000[/color]
[color=Blue]servo lservo[/color][color=Black],[/color][color=Navy]164 [/color][color=Green];default speed[/color]
[color=Blue]servo rservo[/color][color=Black],[/color][color=Navy]164[/color]
[color=Black]main:[/color]


[color=Green];sensor 2[/color]
[color=Blue]high c.2 [/color][color=Green]; charge cap[/color]
[color=Blue]pauseus [/color][color=Black]chargetime[/color]
[color=Purple]reflec[/color][color=DarkCyan]=[/color][color=Navy]0[/color]
[color=Blue]input c.2 [/color][color=Green];drain cap[/color]
[color=Blue]do while [/color][color=Purple]pinc.2[/color][color=DarkCyan]=[/color][color=Navy]1
      [/color][color=Blue]inc [/color][color=Purple]reflec[/color]
[color=Blue]loop
if [/color][color=Purple]reflec[/color][color=DarkCyan]>[/color][color=Black]setval [/color][color=Blue]then servopos lservo[/color][color=Black],[/color][color=Navy]160[/color][color=Black]:[/color][color=Blue]servopos rservo[/color][color=Black],[/color][color=Navy]168[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main:[/color][color=Blue]endif[/color]
[color=Green];
;sensor 3[/color]
[color=Blue]high c.3 [/color][color=Green]; charge cap[/color]
[color=Blue]pauseus [/color][color=Black]chargetime[/color]
[color=Purple]reflec[/color][color=DarkCyan]=[/color][color=Navy]0[/color]
[color=Blue]input c.3 [/color][color=Green];drain cap[/color]
[color=Blue]do while [/color][color=Purple]pinc.3[/color][color=DarkCyan]=[/color][color=Navy]1
      [/color][color=Blue]inc [/color][color=Purple]reflec[/color]
[color=Blue]loop
if [/color][color=Purple]reflec[/color][color=DarkCyan]>[/color][color=Black]setval [/color][color=Blue]then servopos lservo[/color][color=Black],[/color][color=Navy]168[/color][color=Black]:[/color][color=Blue]servopos rservo[/color][color=Black],[/color][color=Navy]160[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main:[/color][color=Blue]endif[/color]
[color=Green];
;sensor 1[/color]
[color=Blue]high c.1 [/color][color=Green]; charge cap[/color]
[color=Blue]pauseus [/color][color=Black]chargetime[/color]
[color=Purple]reflec[/color][color=DarkCyan]=[/color][color=Navy]0[/color]
[color=Blue]input c.1 [/color][color=Green];drain cap[/color]
[color=Blue]do while [/color][color=Purple]pinc.1[/color][color=DarkCyan]=[/color][color=Navy]1
      [/color][color=Blue]inc [/color][color=Purple]reflec[/color]
[color=Blue]loop
if [/color][color=Purple]reflec[/color][color=DarkCyan]>[/color][color=Black]setval [/color][color=Blue]then servopos lservo[/color][color=Black],[/color][color=Navy]156[/color][color=Black]:[/color][color=Blue]servopos rservo[/color][color=Black],[/color][color=Navy]172[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main:[/color][color=Blue]endif [/color]
[color=Green];
;sensor 4[/color]
[color=Blue]high c.4 [/color][color=Green]; charge cap[/color]
[color=Blue]pauseus [/color][color=Black]chargetime[/color]
[color=Purple]reflec[/color][color=DarkCyan]=[/color][color=Navy]0[/color]
[color=Blue]input c.4 [/color][color=Green];drain cap[/color]
[color=Blue]do while [/color][color=Purple]pinc.4[/color][color=DarkCyan]=[/color][color=Navy]1
      [/color][color=Blue]inc [/color][color=Purple]reflec[/color]
[color=Blue]loop
if [/color][color=Purple]reflec[/color][color=DarkCyan]>[/color][color=Black]setval [/color][color=Blue]then servopos lservo[/color][color=Black],[/color][color=Navy]172[/color][color=Black]:[/color][color=Blue]servopos rservo[/color][color=Black],[/color][color=Navy]156[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main:[/color][color=Blue]endif [/color]
[color=Green];
;sensor 0[/color]
[color=Blue]high c.0 [/color][color=Green]; charge cap[/color]
[color=Blue]pauseus [/color][color=Black]chargetime[/color]
[color=Purple]reflec[/color][color=DarkCyan]=[/color][color=Navy]0[/color]
[color=Blue]input c.0 [/color][color=Green];drain cap[/color]
[color=Blue]do while [/color][color=Purple]pinc.0[/color][color=DarkCyan]=[/color][color=Navy]1
      [/color][color=Blue]inc [/color][color=Purple]reflec[/color]
[color=Blue]loop
if [/color][color=Purple]reflec[/color][color=DarkCyan]>[/color][color=Black]setval [/color][color=Blue]then servopos lservo[/color][color=Black],[/color][color=Navy]152[/color][color=Black]:[/color][color=Blue]servopos rservo[/color][color=Black],[/color][color=Navy]174[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main:[/color][color=Blue]endif [/color]
[color=Green];
;sensor 5[/color]
[color=Blue]high c.5 [/color][color=Green]; charge cap[/color]
[color=Blue]pauseus [/color][color=Black]chargetime[/color]
[color=Purple]reflec[/color][color=DarkCyan]=[/color][color=Navy]0[/color]
[color=Blue]input c.5 [/color][color=Green];drain cap[/color]
[color=Blue]do while [/color][color=Purple]pinc.5[/color][color=DarkCyan]=[/color][color=Navy]1
      [/color][color=Blue]inc [/color][color=Purple]reflec[/color]
[color=Blue]loop
if [/color][color=Purple]reflec[/color][color=DarkCyan]>[/color][color=Black]setval [/color][color=Blue]then servopos lservo[/color][color=Black],[/color][color=Navy]174[/color][color=Black]:[/color][color=Blue]servopos rservo[/color][color=Black],[/color][color=Navy]152[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main:[/color][color=Blue]endif [/color]
[color=Green];[/color]
[color=Blue]servopos lservo[/color][color=Black],[/color][color=Navy]164[/color][color=Black]:[/color][color=Blue]servopos rservo[/color][color=Black],[/color][color=Navy]164[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main[/color]
 

Rick100

Senior Member
Did you try reading the digital output? From your link: Each sensor provides a separate digital I/O-measurable output.

You can also feed analog input signal into a Picaxe input pin and use it like a comparator.
It looks like there are 2 versions of this sensor. The RC version has the capacitor:
https://www.pololu.com/product/961
The A version gives an analog output voltage:
https://www.pololu.com/product/960

It looks like the analog version would be more Picaxe friendly. According to the section "Interfacing with the QTR-8A Outputs" in the link, it might work as a simple digital input.
 

stan74

Senior Member
How does the capacitor charge when the port goes high,5V each end?

The typical sequence for reading a sensor is:

Turn on IR LEDs (optional)
Set the I/O line to an output and drive it high
Allow at least 10 us for the 10 nF capacitor to charge
Make the I/O line an input (high impedance)
Measure the time for the capacitor to discharge by waiting for the I/O line to go low
Turn off IR LEDs (optional)
These steps can typically be executed in parallel on multiple I/O lines.

To make your programming life easier, Pololu have made library functions for the Arduino and AVR, and sample code is available below.

With a strong reflectance, the discharge time can be as low as several dozen microseconds; with no reflectance, the discharge time can be up to a few milliseconds. The exact time of the discharge depends on your microcontroller&#8217;s I/O line characteristics. Meaningful results can be available within 1 ms in typical cases (i.e. when not trying to measure subtle differences in low-reflectance scenarios), allowing up to 1 kHz sampling of all 8 sensors. If lower-frequency sampling is sufficient, substantial power savings can be realized by turning off the LEDs. For example, if a 100 Hz sampling rate is acceptable, the LEDs can be off 90% of the time, lowering average current consumption from 100 mA to 10 mA.

Capture.PNG
 

stan74

Senior Member
I've commented a routine that should do what the long code does. Doesn't work though. Screen shots of sensor on black and white.
Values are erratic depending on distance.
osc2.jpgosc1.jpg
Code:
[color=Green];6 sensor,dual continuous servo line follower[/color]
[color=Navy]#picaxe [/color][color=Black]20m2[/color]
[color=Blue]setfreq m32
symbol lservo[/color][color=DarkCyan]=[/color][color=Blue]b.2
symbol rservo[/color][color=DarkCyan]=[/color][color=Blue]b.3
symbol [/color][color=Purple]reflec[/color][color=DarkCyan]=[/color][color=Purple]w0[/color]
[color=Blue]symbol [/color][color=Purple]portpin[/color][color=DarkCyan]=[/color][color=Purple]b2[/color]

[color=Navy]#define [/color][color=Black]chargetime [/color][color=Navy]20
#define [/color][color=Black]setval [/color][color=Navy]7000[/color]
[color=Blue]servo lservo[/color][color=Black],[/color][color=Navy]164 [/color][color=Green];default speed[/color]
[color=Blue]servo rservo[/color][color=Black],[/color][color=Navy]164[/color]
[color=Black]main:[/color]
[color=Green];do ; test c.0 to c.5
;     pinsc=portpin ; charge cap
;     pauseus chargetime
;     reflec=0
;     pinsc= -portpin ; discharge cap
;     if reflec>setval then
;           select case portpin
;           case 1
;                 servopos lservo,170:servopos rservo,158:goto main ;go right fastest
;           case 2
;                 servopos lservo,168:servopos rservo,160:goto main ;go right faster
;           case 3
;                 servopos lservo,166:servopos rservo,162:goto main ;go right slow
;           case 4      
;                 servopos lservo,162:servopos rservo,166:goto main ;go left slow
;           case 5
;                 servopos lservo,160:servopos rservo,168:goto main ;go left faster 
;           case 6
;                 servopos lservo,158:servopos rservo,170:goto main ;go left fastest
;           endselect   
;     endif       
;     portpin=portpin+portpin ; next pin
;loop until portpin=64
;servopos lservo,164:servopos rservo,164:goto main
;
;sensor 2[/color]
[color=Blue]high c.2 [/color][color=Green]; charge cap[/color]
[color=Blue]pauseus [/color][color=Black]chargetime[/color]
[color=Purple]reflec[/color][color=DarkCyan]=[/color][color=Navy]0[/color]
[color=Blue]input c.2 [/color][color=Green];drain cap[/color]
[color=Blue]do while [/color][color=Purple]pinc.2[/color][color=DarkCyan]=[/color][color=Navy]1
      [/color][color=Blue]inc [/color][color=Purple]reflec[/color]
[color=Blue]loop
if [/color][color=Purple]reflec[/color][color=DarkCyan]>[/color][color=Black]setval [/color][color=Blue]then servopos lservo[/color][color=Black],[/color][color=Navy]166[/color][color=Black]:[/color][color=Blue]servopos rservo[/color][color=Black],[/color][color=Navy]162[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main:[/color][color=Blue]endif [/color][color=Green];go right slow
;sensor 3[/color]
[color=Blue]high c.3 [/color][color=Green]; charge cap[/color]
[color=Blue]pauseus [/color][color=Black]chargetime[/color]
[color=Purple]reflec[/color][color=DarkCyan]=[/color][color=Navy]0[/color]
[color=Blue]input c.3 [/color][color=Green];drain cap[/color]
[color=Blue]do while [/color][color=Purple]pinc.3[/color][color=DarkCyan]=[/color][color=Navy]1
      [/color][color=Blue]inc [/color][color=Purple]reflec[/color]
[color=Blue]loop
if [/color][color=Purple]reflec[/color][color=DarkCyan]>[/color][color=Black]setval [/color][color=Blue]then servopos lservo[/color][color=Black],[/color][color=Navy]162[/color][color=Black]:[/color][color=Blue]servopos rservo[/color][color=Black],[/color][color=Navy]166[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main:[/color][color=Blue]endif [/color][color=Green];go left slow
;sensor 1[/color]
[color=Blue]high c.1 [/color][color=Green]; charge cap[/color]
[color=Blue]pauseus [/color][color=Black]chargetime[/color]
[color=Purple]reflec[/color][color=DarkCyan]=[/color][color=Navy]0[/color]
[color=Blue]input c.1 [/color][color=Green];drain cap[/color]
[color=Blue]do while [/color][color=Purple]pinc.1[/color][color=DarkCyan]=[/color][color=Navy]1
      [/color][color=Blue]inc [/color][color=Purple]reflec[/color]
[color=Blue]loop
if [/color][color=Purple]reflec[/color][color=DarkCyan]>[/color][color=Black]setval [/color][color=Blue]then servopos lservo[/color][color=Black],[/color][color=Navy]168[/color][color=Black]:[/color][color=Blue]servopos rservo[/color][color=Black],[/color][color=Navy]160[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main:[/color][color=Blue]endif [/color][color=Green];go right faster
;sensor 4[/color]
[color=Blue]high c.4 [/color][color=Green]; charge cap[/color]
[color=Blue]pauseus [/color][color=Black]chargetime[/color]
[color=Purple]reflec[/color][color=DarkCyan]=[/color][color=Navy]0[/color]
[color=Blue]input c.4 [/color][color=Green];drain cap[/color]
[color=Blue]do while [/color][color=Purple]pinc.4[/color][color=DarkCyan]=[/color][color=Navy]1
      [/color][color=Blue]inc [/color][color=Purple]reflec[/color]
[color=Blue]loop
if [/color][color=Purple]reflec[/color][color=DarkCyan]>[/color][color=Black]setval [/color][color=Blue]then servopos lservo[/color][color=Black],[/color][color=Navy]160[/color][color=Black]:[/color][color=Blue]servopos rservo[/color][color=Black],[/color][color=Navy]168[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main:[/color][color=Blue]endif [/color][color=Green];go left faster   
;sensor 0[/color]
[color=Blue]high c.0 [/color][color=Green]; charge cap[/color]
[color=Blue]pauseus [/color][color=Black]chargetime[/color]
[color=Purple]reflec[/color][color=DarkCyan]=[/color][color=Navy]0[/color]
[color=Blue]input c.0 [/color][color=Green];drain cap[/color]
[color=Blue]do while [/color][color=Purple]pinc.0[/color][color=DarkCyan]=[/color][color=Navy]1
      [/color][color=Blue]inc [/color][color=Purple]reflec[/color]
[color=Blue]loop
if [/color][color=Purple]reflec   [/color][color=DarkCyan]>[/color][color=Black]setval [/color][color=Blue]then servopos lservo[/color][color=Black],[/color][color=Navy]170[/color][color=Black]:[/color][color=Blue]servopos rservo[/color][color=Black],[/color][color=Navy]158[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main:[/color][color=Blue]endif [/color][color=Green];go right fastest
;
;sensor 5[/color]
[color=Blue]high c.5 [/color][color=Green]; charge cap[/color]
[color=Blue]pauseus [/color][color=Black]chargetime[/color]
[color=Purple]reflec[/color][color=DarkCyan]=[/color][color=Navy]0[/color]
[color=Blue]input c.5 [/color][color=Green];drain cap[/color]
[color=Blue]do while [/color][color=Purple]pinc.5[/color][color=DarkCyan]=[/color][color=Navy]1
      [/color][color=Blue]inc [/color][color=Purple]reflec[/color]
[color=Blue]loop
if [/color][color=Purple]reflec[/color][color=DarkCyan]>[/color][color=Black]setval [/color][color=Blue]then servopos lservo[/color][color=Black],[/color][color=Navy]158[/color][color=Black]:[/color][color=Blue]servopos rservo[/color][color=Black],[/color][color=Navy]170[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main:[/color][color=Blue]endif [/color][color=Green];go left fastest  
;[/color]
[color=Blue]servopos lservo[/color][color=Black],[/color][color=Navy]164[/color][color=Black]:[/color][color=Blue]servopos rservo[/color][color=Black],[/color][color=Navy]164[/color][color=Black]:[/color][color=Blue]goto [/color][color=Black]main[/color]
 

erco

Senior Member
Bypass those crap caps. Connect a resistor (100K-1meg, experiment) from each output pin to Vcc (alt: across each cap) to make a simple voltage divider. Ana!og signal out. Read it as a digital input. Calibrate to your line & lighting conditions by picking the right resistor value.
 

stan74

Senior Member
Oops. I redid the commented code.it's still iffy.
Code:
[color=Green];do ; test c.0 to c.5
;     pinsc=portpin ; charge cap
;     pauseus chargetime
;     reflec=0
;     pinsc= -portpin ; discharge cap
;     do while pinsc=1
;           inc reflec
;     loop
;     if reflec>setval then
;           select case portpin
;           case 1
;                 servopos lservo,170:servopos rservo,158:goto main ;go right fastest
;           case 2
;                 servopos lservo,168:servopos rservo,160:goto main ;go right faster
;           case 3
;                 servopos lservo,166:servopos rservo,162:goto main ;go right slow
;           case 4      
;                 servopos lservo,162:servopos rservo,166:goto main ;go left slow
;           case 5
;                 servopos lservo,160:servopos rservo,168:goto main ;go left faster 
;           case 6
;                 servopos lservo,158:servopos rservo,170:goto main ;go left fastest
;           endselect   
;     endif       
;     portpin=portpin+portpin ; next pin
;loop until portpin=64
;servopos lservo,164:servopos rservo,164:goto main[/color]
 
Last edited:

stan74

Senior Member
Bypass those crap caps. Connect a resistor (100K-1meg, experiment) from each output pin to Vcc (alt: across each cap) to make a simple voltage divider. Ana!og signal out. Read it as a digital input. Calibrate to your line & lighting conditions by picking the right resistor value.
I thought about modding it but too tiny then realised I could use the extra output holes. How DOES the cap charge when the pin goes high though? Looks like it's discharging.

View attachment 20735
 

erco

Senior Member
You're right, the cap is discharging when the pin is high, steady state there's 0V across the cap.
 

stan74

Senior Member
erco,I modded 1 output with 120 K resistor and adc shows a stable b/w difference so I'll mod the other 5 outs and see if it works the servos. Yeah,I should put the resistors next to the 20m2,not solder.
Calibrate what?
 

erco

Senior Member
ADC x8 is way slow & ponderous, besides, do you have 6-8 ADC pins to spare?

"Calibrate" means choose your resistor to adjust the voltage swing from black to white so it easily spans that 1.2V high/low transition voltage so you can read all sensors with one quick PINSB or PINSC command. Quick & dirty. If you don't do it, I will, but then I'll be the rockstar.
 

stan74

Senior Member
I tried just checking the logic levels and it doesn't see black lines < 1cm wide above that 2 sensors see it. Height matters..haven't thrown together a chassis but it seems to work. https://youtu.be/r1CjVHje56E
main:
reflec=pinsb
if reflec=3 then servopos lservo,176:servopos rservo,157:goto main:endif ;right fastest
if reflec=6 then servopos lservo,172:servopos rservo,160:goto main:endif ;right faster
if reflec=12 then servopos lservo,166:servopos rservo,166:goto main:endif ;right slow
;if reflec=8 then servopos lservo,166:servopos rservo,168:goto main:endif ;left slow
if reflec=24 then servopos lservo,160:servopos rservo,172:goto main:endif ;left faster
if reflec=48 then servopos lservo,157:servopos rservo,176:goto main:endif ;left fastest
servopos lservo,166:servopos rservo,166:goto main ; no pins lit
 

erco

Senior Member
Height is absolutely critical. Manufacturer Pololu makes two versions. This -8RC board has the max recommended distance (height) of 0.375", but 0.125" is recommended. The other (no cap) board is the -8RA version which has a lesser max recommended height of 0.250" but also 0.125" recommended. Without any optics/lenses, these sensors really need to be almost scraping on the ground.
 

stan74

Senior Member
Grease spots didn't seem to bother it. Cobbled together a chassis but the meccano wheels have sod all traction,they don't correct,just wheel spin and it's going pure slow anyway.I'll glue some other wheels to the servo arms but then I'll have to move the sensors. Bollards. I think it'll work ok from what it's trying to do. Like Scalectrix..or a train set but without the track. (I used to put 3 in 1 oil on the bends of scalectrix tracks :) )SAM_1384.JPG
 
Last edited:

stan74

Senior Member
Just thinking erco, I got some ldrs and you got a result,I'm not impressed with the array.I got 5x 99p ir sensors and I know you think they're rubbish but they pick up a thin line accurately up to 2" and there's a pot that actually does something.Quite nice really. Something vaguer like ldrs might work better,they're not really slow but ambient light is a problem.
I don't think I'll use dc motors and drivers after using a continuous servo, no palaver except servo hogs the picaxe. Any 12g metal gear digital continuous should be ok. Is digital worth the extra cost?
 

erco

Senior Member
Oh, I hate LDRs, but if you please call them photocells, I love 'em. I get 20 for 99 cents on Ebay! At that ridiculous price, every project should have a dozen photocells. I've made several photocell-based line followers, that pizza box bot was one, and here's another. You should be able to see a page or two of this subscription digital magazine (SERVO) I write for: http://servo.texterity.com/servo/201601/?folio=36&pg=40#pg40 I used two photocells in series as a voltage divider to follow the line, just using a single ADC input pin on an 08M2 robot. Neither terribly fast nor ultra-stable, but a good demonstration of pinimalism (minimal pin use).

 
Last edited:

erco

Senior Member
stan74, please post your video in Robotics, we need content there! Start a new thread or add it to another, as you see fit. Consider adding some detail: code and photos. Maybe your credit card info if you like.
 

stan74

Senior Member
The seller has responded to you and offered another solution to resolve this issue.

Seller's message:
'Dear friend,Sorry for the inconvenience.I contacted my post office , they said that the item delay because of the customs and the human factor during the post way , could you help me to wait one more week ? If you still can not receive a week later, I can refund or resend to you as you want .How about this ?Your understanding will be highly appreciate. Best regards .'

If you're satisfied with this solution, please let the seller know by sending a message in the Resolution Center. If you don't want to accept this offer, we encourage you to contact the seller and offer a solution that you'd be happy with.

You can also view the details of this request in the Resolution Centre.

GP2Y0A21YK0F Sharp IR Analog Distance Sensor Distance 10CM-80CM Cable Arduino F
GP2Y0A21YK0F Sharp IR Analog Distance Sensor Distance 10CM-80CM Cable Arduino F
Item # 272041590764
Sale price: £2.94
Quantity: 2
Sale date: 08-Nov-16 19:43:31 GMT
Seller: chips-fans
Case #: 5123382313
Case opened: 27-Dec-16 23:22:08 GMT
View purchased item
 

AllyCat

Senior Member
Hi,

Yes, most (Chinese) sellers are sufficiently concerned about theie "5 star" reputation (because it keeps their sellers' fees lower) that they will offer an immediate refund or re-send. That's presumably based on the premise that most buyers are honest (or at least more reliable than Post from China to UK). My experience is that you may need to wait 6 weeks, but then accept a refund (even if you then re-order from the same seller).

Now, some sellers are actually sending a "Personnal Message" (at the time of purchase) to contact them directly, rather than via the resolution centre if there are any issues. I can see their reasoning, but personally find the number of emails generated by a single purchase (Acknowledgement, Paypal receipt, Confirmation, Order dispatched, and PM "question", etc.) to be getting ridiculous and tend to downgrade them to 4 stars on "communication".


On the topic from another thread, it can be difficult to decide in which section of the forum to post. Nearly everything "happens" in the Active section, which I suspect is all that most members read (including me most of the time). It has the advantage that nearly everybody will see the post, but that any "mistakes" will soon disappear from view (that late December thread had already fallen to about the fourth page until I resurrected it).

However, if a project is considered to be reasonably "finished" then it makes sense to post it into the relevant section of the forum (for me it's mainly the "Code Snippetts") because I know at least I will be able to find it again, even if (as usual) the forum search can't. :(

Cheers, Alan.
 

stan74

Senior Member
True Alan,can't find porthcawl with the forum search but google finds links in the forum,at leasts word matches. Bresenhams line draw and negative numbers was a good example of crossed lines. I reckon it was a valid post but that was me not realising 2 vars were words not bytes. Comes from learning basic on unclear spectrum-all numbers were 32 bit signed...so you didn't have to bother.
Int rnd because rnd was.123456789.......
 
Top