techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: One wheel quicker/more powerful than the other

Fri Oct 18, 2013 9:23 pm

ZacharyI123 wrote:The soldering is fine. What are the mistakes on the board? Do I need to change what/where I solder or connect it up?
The mistake is in the assembly guide that says set jumpers for 3V3 when using on Pi which is wrong, set them for 5V and the reference voltage to 5V as well (by jumpers)
ZacharyI123 wrote:Connections for the quick2wire

I will connect the 5v power pin to the Pi's 5v pin and the GND pin to the Pi's GND pin. Is this right?
Yes
ZacharyI123 wrote:What do I connect the 3V3 to?
Nothing PCF8591 works fine off 5V when connected to Pi, have done this on a few circuits already that are in use on Pis.
ZacharyI123 wrote: Can you point out in the picture what I connect to the GPIO? Which GPIO pins in specific?
SCL to SCL on GPIO connector (pin 5) and SDA to SDA on GPIO connector (pin 3)
ZacharyI123 wrote:Connections to the integrated circuit:

The VCC goes to the Pi's 5v pin? The GND pin goes to the GND on the Pi?
Yes
ZacharyI123 wrote: What do I do with the other two pins?
Print out the datasheet and look at Page 4 Basic Circuit shows how to set it up, pin 4 (Go) drives the illumination and pin 2 is the output (Vo) to connect to one of the ADC inputs.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

User avatar
ZacharyI123
Posts: 263
Joined: Sun Jun 17, 2012 1:09 pm
Location: Ilford, Essex
Contact: Website

Re: One wheel quicker/more powerful than the other

Sat Oct 19, 2013 6:46 am

Quick2Wire connections
In this picture:
https://www.modmypi.com/image/cache/dat ... 0x800.jpeg

I will connect the +5 power pin on the top to the Pi's 5v pin.

Do I connect the Pi's GND to one of the AGND pins (if so, which one?) or the GND on the left?

Which Pins on the quick2wire should be connected with the Pi's GPIO?
Which GPIO pins do I connect them to?

Integrated circuit connections
In this picture: http://t.co/drQTFUXqWF

I will connect the Vcc pin to the Pi's 5v pin.

What do I connect the Vo pin to?

Should I connect the GND pin to one if the AGND pins on quick2wire (if so, which one?) or to the Pi's GND?

On the tech sheet, they use the GLout to drive an LED. I will need to use an LED to light up the floor so the integrated circuit can see if there is a black line or not. Should I use GLout to drive my LED? How would I use it to drive my LED (would I need another power supply, would I need a resistor, what direction is the current)? Or, is that the analogue output that I need to read? If so, what do I connect it to, in the picture of the Quick2Wire board?

My code

I have realised that it is using digital inputs (0 or 1) when it says 'pin.value'
How can I get an analogue input in my code?
Don't be mean, I'm only thirteen 8-)

User avatar
ZacharyI123
Posts: 263
Joined: Sun Jun 17, 2012 1:09 pm
Location: Ilford, Essex
Contact: Website

Re: One wheel quicker/more powerful than the other

Sat Oct 19, 2013 9:17 am

techpaul wrote:
ZacharyI123 wrote:The soldering is fine. What are the mistakes on the board? Do I need to change what/where I solder or connect it up?
The mistake is in the assembly guide that says set jumpers for 3V3 when using on Pi which is wrong, set them for 5V and the reference voltage to 5V as well (by jumpers)
ZacharyI123 wrote:Connections for the quick2wire

I will connect the 5v power pin to the Pi's 5v pin and the GND pin to the Pi's GND pin. Is this right?
Yes
ZacharyI123 wrote:What do I connect the 3V3 to?
Nothing PCF8591 works fine off 5V when connected to Pi, have done this on a few circuits already that are in use on Pis.
ZacharyI123 wrote: Can you point out in the picture what I connect to the GPIO? Which GPIO pins in specific?
SCL to SCL on GPIO connector (pin 5) and SDA to SDA on GPIO connector (pin 3)
ZacharyI123 wrote:Connections to the integrated circuit:

The VCC goes to the Pi's 5v pin? The GND pin goes to the GND on the Pi?
Yes
ZacharyI123 wrote: What do I do with the other two pins?
Print out the datasheet and look at Page 4 Basic Circuit shows how to set it up, pin 4 (Go) drives the illumination and pin 2 is the output (Vo) to connect to one of the ADC inputs.
Ignore my last post. Would you mind if I drew a circuit diagram and uploaded it here, and you checked it?
And can you change my code so the if statement is comparing analog inputs not digital ones?

Thanks for all the help!
Don't be mean, I'm only thirteen 8-)

User avatar
ZacharyI123
Posts: 263
Joined: Sun Jun 17, 2012 1:09 pm
Location: Ilford, Essex
Contact: Website

Re: One wheel quicker/more powerful than the other

Sat Oct 19, 2013 9:21 am

Ignore that about the code as well. It is an analogue input, but it's out of 1. What does 1 mean (current? voltage? how much?)?
Don't be mean, I'm only thirteen 8-)

User avatar
ZacharyI123
Posts: 263
Joined: Sun Jun 17, 2012 1:09 pm
Location: Ilford, Essex
Contact: Website

Re: One wheel quicker/more powerful than the other

Sat Oct 19, 2013 9:36 am

techpaul wrote:
ZacharyI123 wrote:The soldering is fine. What are the mistakes on the board? Do I need to change what/where I solder or connect it up?
The mistake is in the assembly guide that says set jumpers for 3V3 when using on Pi which is wrong, set them for 5V and the reference voltage to 5V as well (by jumpers)
ZacharyI123 wrote:Connections for the quick2wire

I will connect the 5v power pin to the Pi's 5v pin and the GND pin to the Pi's GND pin. Is this right?
Yes
ZacharyI123 wrote:What do I connect the 3V3 to?
Nothing PCF8591 works fine off 5V when connected to Pi, have done this on a few circuits already that are in use on Pis.
ZacharyI123 wrote: Can you point out in the picture what I connect to the GPIO? Which GPIO pins in specific?
SCL to SCL on GPIO connector (pin 5) and SDA to SDA on GPIO connector (pin 3)
ZacharyI123 wrote:Connections to the integrated circuit:

The VCC goes to the Pi's 5v pin? The GND pin goes to the GND on the Pi?
Yes
ZacharyI123 wrote: What do I do with the other two pins?
Print out the datasheet and look at Page 4 Basic Circuit shows how to set it up, pin 4 (Go) drives the illumination and pin 2 is the output (Vo) to connect to one of the ADC inputs.
Let's say I have set it up like this: https://www.modmypi.com/image/cache/dat ... 0x800.jpeg
Do I need to connect something with both IDCs on the boards?

I connect 3 integrated circuits like this:
Vcc -> Pi's 5v pin
GND -> Pi's GND
Vo -> Quick2Wire's AIN0 & AIN1 & AIN2
GLout -> Like so: http://t.co/oNicQQoEeL Vin being the Pi's 3v output and a 330 ohm resistor

And I used code like this:

Code: Select all

import sys
from time import sleep
from quick2wire.parts.pcf8591 import *
from quick2wire.i2c import I2CMaster
with I2CMaster() as i2c:
    adc = PCF8591(i2c, FOUR_SINGLE_ENDED)
    left_photodiode = adc.single_ended_input(0)
    centre_photodiode = adc.single_ended_input(1)
    right_photodiode = adc.single_ended_input(2)

    while True:
        if (left_photodiode.value<right_photodiode.value and left_photodiode.value<centre_photodiode.value):
            power right wheel
        if (centre_photodiode.value<right_photodiode.value and centre_photodiode.value<left_photodiode.value):
            power middle wheel
        if (right_photodiode.value<left_photodiode.value and right_photodiode.value<centre_photodiode.value):
            power right wheel
Will this work?
Don't be mean, I'm only thirteen 8-)

User avatar
joan
Posts: 15040
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: One wheel quicker/more powerful than the other

Sat Oct 19, 2013 9:42 am

You can get a module quite a bit cheaper (if you are prepared to wait a couple of weeks).

I have one of these http://www.ebay.co.uk/itm/111165769199

Works fine and has temperature and light sensors built in.

User avatar
ZacharyI123
Posts: 263
Joined: Sun Jun 17, 2012 1:09 pm
Location: Ilford, Essex
Contact: Website

Re: One wheel quicker/more powerful than the other

Sat Oct 19, 2013 9:49 am

joan wrote:You can get a module quite a bit cheaper (if you are prepared to wait a couple of weeks).

I have one of these http://www.ebay.co.uk/itm/111165769199

Works fine and has temperature and light sensors built in.
Thanks for the tip! But the setup and code in my previous post, will that work after assembling both boards and installing the oython api (doing this:https://github.com/quick2wire/quick2wire-gpio-admin then this:https://github.com/quick2wire/quick2wire-python-api)?
Don't be mean, I'm only thirteen 8-)

User avatar
joan
Posts: 15040
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: One wheel quicker/more powerful than the other

Sat Oct 19, 2013 10:01 am

I'm not familiar enough with Python or the modules you are using to be sure.

The code looks about right though.

For comparison this is the code I use in a working Arduino line follower.

Code: Select all

void sketch1()
{
   int Ref=500;
   int Left,Right;

   Left  = analogRead(ZX03_L); // Read value from left sensor
   Right = analogRead(ZX03_R); // Read value from right sensor

   if (Left>Ref && Right>Ref)
   {
      // Both sensors detect white surface
      Motor(150, 150); // Forward(150);
   }
   else if (Left<Ref && Right<Ref)
   {
      // both sensors detects black line
      Motor(-250, 250); // Spin_Left(250);
      Motor(-250, 250); // Spin_Left(250);
   }
   else if (Left<Ref)
   {
      // Left sensor detects black line
      Motor(-250, 250); // Spin_Left(250);
   }
   else if (Right<Ref)
   {
      // Right sensor detects black line
      Motor(250, -250); // Spin_Right(250);
   }
}

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: One wheel quicker/more powerful than the other

Sat Oct 19, 2013 10:38 am

ZacharyI123 wrote:Let's say I have set it up like this: https://www.modmypi.com/image/cache/dat ... 0x800.jpeg
Do I need to connect something with both IDCs on the boards?
See private message on this subject, basically the two IDCs are I2C bus connectors with same pinout only use one, the setup above is an expesive way to test it, a few femal to feamle jumper wires like breadboard users have would do the job.
I connect 3 integrated circuits like this:
Vcc -> Pi's 5v pin
GND -> Pi's GND
Vo -> Quick2Wire's AIN0 & AIN1 & AIN2
GLout -> Like so: http://t.co/oNicQQoEeL Vin being the Pi's 3v output and a 330 ohm resistor
NO use a LED per device as the LED driving pin of the device allows the device to take two internals readings with and without controlled illumination to work out the difference between background illumination and when illuminated.
And I used code like this:
Needs major mods as you are trying to code before design, always design your software first even with pencil and paper as to what is done in which order, before coding. Some of the problems are
  • You can fill an array with three readings of ADC in one call to read three adjacent channels on PCF8591,
  • You do not error trap for PCF8591 not connected
  • You only read ADC once you need to read at beginning of EACH time round the while True loop. To get the new level to check
  • No checks for readings making no sense e.g. if all read almost maximum value what does that mean, or if all read 0 what does that mean, if all readings the same what does that mean
  • Your if statements look wrong as you only check for things being less than something else with no apparent logic to it, and what is 'middle wheel', also if should be if...elif construction as your code could power left the power right then power middle if you have an error reading of other logic error
You need to sit down with pencil and paper and first work out what are you doing, so if you have 3 sensors, and you are following a BLACK line on WHITE paper, what do you expect the sensors to be saying when on line, off line left or right, nowhere near line, and error readings. Then work out the steps and if... eilf statements to perform the logic
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

User avatar
ZacharyI123
Posts: 263
Joined: Sun Jun 17, 2012 1:09 pm
Location: Ilford, Essex
Contact: Website

Re: One wheel quicker/more powerful than the other

Sat Oct 19, 2013 12:15 pm

techpaul wrote:
ZacharyI123 wrote:Let's say I have set it up like this: https://www.modmypi.com/image/cache/dat ... 0x800.jpeg
Do I need to connect something with both IDCs on the boards?
See private message on this subject, basically the two IDCs are I2C bus connectors with same pinout only use one, the setup above is an expesive way to test it, a few femal to feamle jumper wires like breadboard users have would do the job.
I connect 3 integrated circuits like this:
Vcc -> Pi's 5v pin
GND -> Pi's GND
Vo -> Quick2Wire's AIN0 & AIN1 & AIN2
GLout -> Like so: http://t.co/oNicQQoEeL Vin being the Pi's 3v output and a 330 ohm resistor
NO use a LED per device as the LED driving pin of the device allows the device to take two internals readings with and without controlled illumination to work out the difference between background illumination and when illuminated.
And I used code like this:
Needs major mods as you are trying to code before design, always design your software first even with pencil and paper as to what is done in which order, before coding. Some of the problems are
  • You can fill an array with three readings of ADC in one call to read three adjacent channels on PCF8591,
  • You do not error trap for PCF8591 not connected
  • You only read ADC once you need to read at beginning of EACH time round the while True loop. To get the new level to check
  • No checks for readings making no sense e.g. if all read almost maximum value what does that mean, or if all read 0 what does that mean, if all readings the same what does that mean
  • Your if statements look wrong as you only check for things being less than something else with no apparent logic to it, and what is 'middle wheel', also if should be if...elif construction as your code could power left the power right then power middle if you have an error reading of other logic error
You need to sit down with pencil and paper and first work out what are you doing, so if you have 3 sensors, and you are following a BLACK line on WHITE paper, what do you expect the sensors to be saying when on line, off line left or right, nowhere near line, and error readings. Then work out the steps and if... eilf statements to perform the logic
I will use three separate LEDs (one for each integrated circuit) like in the circuit diagram (Fig.4 on the tech sheet). What is Vin? Can I use the Pi's 3V pin as Vin? Should I put a 330ohm resistor next to the LED to protect it?

CODE:
I will read the ADC in my while loop now. I am assuming the PCF8591 is connected correctly. I will change my if statement so they say this:

If the left photodiode value is less than the right and less than the centre then power the right wheel.
If the right photodiode value is less than the left and less than the centre then power the left wheel.
Else power both.

I know that if they aren't over the line, it won't work. I assume that the photodiode with the black line (or most of the black line) will have the lowest value. Is this true or is it the other way round?

Once I have that working, I will add statements for error readings.
Don't be mean, I'm only thirteen 8-)

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: One wheel quicker/more powerful than the other

Sat Oct 19, 2013 12:40 pm

ZacharyI123 wrote:I will use three separate LEDs (one for each integrated circuit) like in the circuit diagram (Fig.4 on the tech sheet). What is Vin?
There is no Vin, there is Vcc use 5V, and Vo (output) you connect to one of the ADC inputs
Can I use the Pi's 3V pin as Vin?
you do not need 3V3 for anything involving the detectors or ADC
Should I put a 330ohm resistor next to the LED to protect it?
NO the chip does that
CODE:
I will read the ADC in my while loop now. I am assuming the PCF8591 is connected correctly. I will change my if statement so they say this:
else if all same STOP (major problem).
ELSE
If the left photodiode value is less than the right and less than the centre then power the right wheel.
Then ELSE
If the right photodiode value is less than the left and less than the centre then power the left wheel.
Else power both.
How close same or less than is you will have to find by experiment dont expect a count of 1 difference to be anything more than noise
I know that if they aren't over the line, it won't work. I assume that the photodiode with the black line (or most of the black line) will have the lowest value. Is this true or is it the other way round?
Normally black will be lowest value
Once I have that working, I will add statements for error readings.
Right I am now off to do a computer network and reinstall servers....
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

User avatar
ZacharyI123
Posts: 263
Joined: Sun Jun 17, 2012 1:09 pm
Location: Ilford, Essex
Contact: Website

Re: One wheel quicker/more powerful than the other

Sat Oct 19, 2013 12:54 pm

techpaul wrote:
ZacharyI123 wrote:I will use three separate LEDs (one for each integrated circuit) like in the circuit diagram (Fig.4 on the tech sheet). What is Vin?
There is no Vin, there is Vcc use 5V, and Vo (output) you connect to one of the ADC inputs
Can I use the Pi's 3V pin as Vin?
you do not need 3V3 for anything involving the detectors or ADC
Should I put a 330ohm resistor next to the LED to protect it?
NO the chip does that
CODE:
I will read the ADC in my while loop now. I am assuming the PCF8591 is connected correctly. I will change my if statement so they say this:
else if all same STOP (major problem).
ELSE
If the left photodiode value is less than the right and less than the centre then power the right wheel.
Then ELSE
If the right photodiode value is less than the left and less than the centre then power the left wheel.
Else power both.
How close same or less than is you will have to find by experiment dont expect a count of 1 difference to be anything more than noise
I know that if they aren't over the line, it won't work. I assume that the photodiode with the black line (or most of the black line) will have the lowest value. Is this true or is it the other way round?
Normally black will be lowest value
Once I have that working, I will add statements for error readings.
Right I am now off to do a computer network and reinstall servers....
Thanks! I'm nearly there thanks to you :D
Just one more quick question, I still don't get how to connect an LED to the GLout.

I took this picture from the tech sheet: http://t.co/oNicQQoEeL

I don't need the switch, but I will still have a wire in parallel to the LED, this is right, isn't it?

Also, what should I use for Vin in the picture?
Don't be mean, I'm only thirteen 8-)

User avatar
ZacharyI123
Posts: 263
Joined: Sun Jun 17, 2012 1:09 pm
Location: Ilford, Essex
Contact: Website

Re: One wheel quicker/more powerful than the other

Sat Oct 19, 2013 1:06 pm

Also, the component you recommended should be used with an infrared led and detects ir light.

Is http://uk.farnell.com/sharp/is471fe/pho ... dp/9707840 also sensitive to visible light?
Don't be mean, I'm only thirteen 8-)

User avatar
exartemarte
Posts: 376
Joined: Sat Mar 03, 2012 3:51 pm
Location: Middle England
Contact: Website

Re: One wheel quicker/more powerful than the other

Sat Oct 19, 2013 1:23 pm

Line sensing is not a demanding application and can be accomplished with quite cheap, simple hardware. The level of control and precision provided by Schmitt triggers with adjustable thresholds is very nice but is not, in my opinion, strictly necessary. A project using very simple, home-brew infra-red reflective sensors is described here. The sensor, consisting of three components on a piece of Veroboard is shown below.

Image

The active components are an IR LED and an IR phototransistor, both of them bog-standard, low-cost components that can bought almost anywhere (ours were from ESR Electronics, with whom I have no other connection). Note that a fourth component is necessary - the phototransistor needs a series resistor. In the original application this requirement was conveniently met by a 10K pull-down resistor already fitted on the (Picaxe) controller board, but it would be a simple enough matter to add a 10K resistor to the sensor board.

The phototransistor conducts when it is illuminated. If the collector is connected to +5v and the emitter taken to ground via 10K, then the output (taken from the junction between the transistor and the resistor) will go high when the transistor is illuminated. Alternatively if the emitter is connected to ground and the collector taken to +5v via the 10K resistor, then the output will go low when the transistor is illuminated. The output actually varies according to the level of illumination, relying on the Schmitt trigger in the microcontroller input to provide clean switching.

Some form of light-screen between LED and phototransistor is desirable: we used a plastic tube, but other arrangements such as metal foil or copper-clad board can be used.

In electronic design terms this is an admittedly crude approach, relying on the characteristics of other devices, such as the microcontroller input circuitry, for part of its functionality, but it's cheap, simple and it works. As well as projects of my own, dozens of these sensors were used in successful student projects. The same device was used, as an analogue sensor, to measure light levels in another project described here, and it has also been used with a striped wheel to count pulses, enabling calculation of speed of rotation or distance travelled.

User avatar
ZacharyI123
Posts: 263
Joined: Sun Jun 17, 2012 1:09 pm
Location: Ilford, Essex
Contact: Website

Re: One wheel quicker/more powerful than the other

Sat Oct 19, 2013 1:31 pm

exartemarte wrote:Line sensing is not a demanding application and can be accomplished with quite cheap, simple hardware. The level of control and precision provided by Schmitt triggers with adjustable thresholds is very nice but is not, in my opinion, strictly necessary. A project using very simple, home-brew infra-red reflective sensors is described here. The sensor, consisting of three components on a piece of Veroboard is shown below.

Image

The active components are an IR LED and an IR phototransistor, both of them bog-standard, low-cost components that can bought almost anywhere (ours were from ESR Electronics, with whom I have no other connection). Note that a fourth component is necessary - the phototransistor needs a series resistor. In the original application this requirement was conveniently met by a 10K pull-down resistor already fitted on the (Picaxe) controller board, but it would be a simple enough matter to add a 10K resistor to the sensor board.

The phototransistor conducts when it is illuminated. If the collector is connected to +5v and the emitter taken to ground via 10K, then the output (taken from the junction between the transistor and the resistor) will go high when the transistor is illuminated. Alternatively if the emitter is connected to ground and the collector taken to +5v via the 10K resistor, then the output will go low when the transistor is illuminated. The output actually varies according to the level of illumination, relying on the Schmitt trigger in the microcontroller input to provide clean switching.

Some form of light-screen between LED and phototransistor is desirable: we used a plastic tube, but other arrangements such as metal foil or copper-clad board can be used.

In electronic design terms this is an admittedly crude approach, relying on the characteristics of other devices, such as the microcontroller input circuitry, for part of its functionality, but it's cheap, simple and it works. As well as projects of my own, dozens of these sensors were used in successful student projects. The same device was used, as an analogue sensor, to measure light levels in another project described here, and it has also been used with a striped wheel to count pulses, enabling calculation of speed of rotation or distance travelled.
But I don't know how sensitive the phototransistor should be. It might conduct even with he black line under it because the black line reflects a bit of light, or maybe the white isn't bright enough to trigger it. Also, what if two of the transistor are off (meaning they both have the black line underneath)? With analogue inputs, I can work out which has more of the black line underneath.
Don't be mean, I'm only thirteen 8-)

User avatar
exartemarte
Posts: 376
Joined: Sat Mar 03, 2012 3:51 pm
Location: Middle England
Contact: Website

Re: One wheel quicker/more powerful than the other

Sat Oct 19, 2013 2:51 pm

ZacharyI123 wrote: But I don't know how sensitive the phototransistor should be. It might conduct even with he black line under it because the black line reflects a bit of light, or maybe the white isn't bright enough to trigger it. Also, what if two of the transistor are off (meaning they both have the black line underneath)? With analogue inputs, I can work out which has more of the black line underneath.
Well, two sensors over the line is a logical condition that your program must deal with. If you are just using two sensors then both of them over the line means you are on track and there is no need to steer. If one of them goes off the track then you need to steer to get back it back on - which way depends on which of the sensors is off the track.

However, if you have an analogue input available (there aren't any on the Pi) then you can use the sensor as an analogue sensor - as I did in the second of the projects linked above. (You still need the 10K resistor.) It distinguishes quite happily between black, red and white which is what was required, and would also serve to measure how far over the line your sensor is. You would experiment to find the maximum and minimum levels corresponding to white and black.

You make a fair point, though, about the blackness of the black and the whiteness of the white. Ours consisted of black laser printed tracks on white paper. As I recall, we experimented with values for the LED current-limiting resistor (which is the only variable thing on the board!) until we got reliable switching between background and track, and settled on 330R for the ones we used on projects. (That's not what's in the picture, but that was probably an early prototype!) The level of ambient light has a small effect, too - ideally the sensor is under a board or a chassis which provides reasonable shade: you would get the same problem with any light sensor.

These days you can get basically the same thing, but smaller and, of course, more expensive, ready built from Pololu or Sparkfun, or from HobbyTronics or TechnoBots in the UK.

User avatar
ZacharyI123
Posts: 263
Joined: Sun Jun 17, 2012 1:09 pm
Location: Ilford, Essex
Contact: Website

Re: One wheel quicker/more powerful than the other

Sat Oct 19, 2013 5:42 pm

exartemarte wrote:
ZacharyI123 wrote: But I don't know how sensitive the phototransistor should be. It might conduct even with he black line under it because the black line reflects a bit of light, or maybe the white isn't bright enough to trigger it. Also, what if two of the transistor are off (meaning they both have the black line underneath)? With analogue inputs, I can work out which has more of the black line underneath.
Well, two sensors over the line is a logical condition that your program must deal with. If you are just using two sensors then both of them over the line means you are on track and there is no need to steer. If one of them goes off the track then you need to steer to get back it back on - which way depends on which of the sensors is off the track.

However, if you have an analogue input available (there aren't any on the Pi) then you can use the sensor as an analogue sensor - as I did in the second of the projects linked above. (You still need the 10K resistor.) It distinguishes quite happily between black, red and white which is what was required, and would also serve to measure how far over the line your sensor is. You would experiment to find the maximum and minimum levels corresponding to white and black.

You make a fair point, though, about the blackness of the black and the whiteness of the white. Ours consisted of black laser printed tracks on white paper. As I recall, we experimented with values for the LED current-limiting resistor (which is the only variable thing on the board!) until we got reliable switching between background and track, and settled on 330R for the ones we used on projects. (That's not what's in the picture, but that was probably an early prototype!) The level of ambient light has a small effect, too - ideally the sensor is under a board or a chassis which provides reasonable shade: you would get the same problem with any light sensor.

These days you can get basically the same thing, but smaller and, of course, more expensive, ready built from Pololu or Sparkfun, or from HobbyTronics or TechnoBots in the UK.
Which phototransistor did you use? It has to be a phototransistor that is 0 when it's over black paper lit up by a white LED and 1 when it's over white paper lit up by a white LED.
Don't be mean, I'm only thirteen 8-)

User avatar
exartemarte
Posts: 376
Joined: Sat Mar 03, 2012 3:51 pm
Location: Middle England
Contact: Website

Re: One wheel quicker/more powerful than the other

Sat Oct 19, 2013 11:24 pm

ZacharyI123 wrote: Which phototransistor did you use? It has to be a phototransistor that is 0 when it's over black paper lit up by a white LED and 1 when it's over white paper lit up by a white LED.
I think you have misunderstood how a phototransistor works. For what it's worth, I use the 3mm standard phototransistor and LED at the top of the ESR Infra-red Devices page (follow this link, then click on Infra-red LEDs), but really they all work in much the same way. I chose these because they are cheap, not because of anything special about the way they work. I use infra-red rather than white light devices because they are less susceptible to ambient light. The downside is that you can't see infra-red with the naked eye, but you can usually see it through a digital camera if you need to check whether your infra-red LED is working.

Whether you get a 0 or 1 when it's over white paper depends on how the phototransistor is wired up and how your program handles the input - it is not to do with the "type" of the photransistor. This is how I do it:

Image

In the diagram above the 0V line connects to 0V on your controller and the output line connects to one of the inputs (which could be either analogue or digital, but on the Pi you only have digital). If you're using a Pi the +V line should be connected to 3.3V. This is what happens:

The phototransistor and the 10K resistor form a potential divider. The voltage at the output depends on the amount of infra-red light falling on the phototransistor.

When the amount of light reflected back to the phototransistor is low (because it's over black) the output voltage is also low - below the threshold of your digital input which therefore registers it as a 0.

When the light reflected back to the phototransistor is high (because it's over white) the output voltage is also high - above the threshold of your digital input which therefore registers it as a 1.

Don't forget you also have an infra-red LED, with a 330R series resistor, illuminating the track below the phototransistor. The LED can safely be connected to +5V.

When students complained that their sensors were not working the problem was invariably that they had wired them up wrongly, or were driving them from controller outputs and had forgotten to switch them on in their programs.

I hope this makes sense to you.

User avatar
ZacharyI123
Posts: 263
Joined: Sun Jun 17, 2012 1:09 pm
Location: Ilford, Essex
Contact: Website

Re: One wheel quicker/more powerful than the other

Sun Oct 20, 2013 6:40 am

exartemarte wrote:
ZacharyI123 wrote: Which phototransistor did you use? It has to be a phototransistor that is 0 when it's over black paper lit up by a white LED and 1 when it's over white paper lit up by a white LED.
I think you have misunderstood how a phototransistor works. For what it's worth, I use the 3mm standard phototransistor and LED at the top of the ESR Infra-red Devices page (follow this link, then click on Infra-red LEDs), but really they all work in much the same way. I chose these because they are cheap, not because of anything special about the way they work. I use infra-red rather than white light devices because they are less susceptible to ambient light. The downside is that you can't see infra-red with the naked eye, but you can usually see it through a digital camera if you need to check whether your infra-red LED is working.

Whether you get a 0 or 1 when it's over white paper depends on how the phototransistor is wired up and how your program handles the input - it is not to do with the "type" of the photransistor. This is how I do it:

Image

In the diagram above the 0V line connects to 0V on your controller and the output line connects to one of the inputs (which could be either analogue or digital, but on the Pi you only have digital). If you're using a Pi the +V line should be connected to 3.3V. This is what happens:

The phototransistor and the 10K resistor form a potential divider. The voltage at the output depends on the amount of infra-red light falling on the phototransistor.

When the amount of light reflected back to the phototransistor is low (because it's over black) the output voltage is also low - below the threshold of your digital input which therefore registers it as a 0.

When the light reflected back to the phototransistor is high (because it's over white) the output voltage is also high - above the threshold of your digital input which therefore registers it as a 1.

Don't forget you also have an infra-red LED, with a 330R series resistor, illuminating the track below the phototransistor. The LED can safely be connected to +5V.

When students complained that their sensors were not working the problem was invariably that they had wired them up wrongly, or were driving them from controller outputs and had forgotten to switch them on in their programs.

I hope this makes sense to you.
I see! So I could do it how you do, and keep switching resistor until the sensetivety is right, or I could put an infra-red LED where my white led it and the phototransistor where my LDR is.

This would be the setup:

3V3 -> 330 ohm resistor -> Infra-red LED -> GND
3V3 -> 680 ohm resistor -> phototransistor -> 4.3 micro-farrad capacitor-> GND
GPIO pin -> positive of capacitor

This is what my code would do:

Set the GPIO pin to a low output and wait (discharging the capacitor)
Turn it into a input and start a timer
Stop the timer when the input becomes 1
That counter would give me an analogue inout (sort of!)
I could then compare the analogue input to the analogue input of my duplicates of the same circuit in different positions on the car and decide which motors to power appropriately.

What is the advantage of a phototransistor over an LDR?
Don't be mean, I'm only thirteen 8-)

User avatar
exartemarte
Posts: 376
Joined: Sat Mar 03, 2012 3:51 pm
Location: Middle England
Contact: Website

Re: One wheel quicker/more powerful than the other

Sun Oct 20, 2013 12:08 pm

ZacharyI123 wrote:
I see! So I could do it how you do, and keep switching resistor until the sensetivety is right, or I could put an infra-red LED where my white led it and the phototransistor where my LDR is.

This would be the setup:

3V3 -> 330 ohm resistor -> Infra-red LED -> GND
3V3 -> 680 ohm resistor -> phototransistor -> 4.3 micro-farrad capacitor-> GND
GPIO pin -> positive of capacitor

This is what my code would do:

Set the GPIO pin to a low output and wait (discharging the capacitor)
Turn it into a input and start a timer
Stop the timer when the input becomes 1
That counter would give me an analogue inout (sort of!)
I could then compare the analogue input to the analogue input of my duplicates of the same circuit in different positions on the car and decide which motors to power appropriately.

What is the advantage of a phototransistor over an LDR?
What you are describing is a method for getting an analogue reading from a digital port, which is not what I was suggesting.

There is a point that needs clarifying: I understood from your earlier posts that you are steering left or right by switching the appropriate motor off - is that correct? If that is what you are doing then there is no point in getting an analogue value because there is nothing your program can do with it. If you are steering by stopping one motor then you can't steer a lot or a little - all you can do is steer or not steer.

Consider this:

Image

This buggy has two simple, digital (ie on/off) sensors, one to either side of the track. If the vehicle is on track then both sensors are over white and the vehicle just drives forward. If one sensor strays onto the black then the program detects that and stops the motor on that side. This makes the vehicle steer so that the sensor moves back onto the white; when it's over the white the vehicle is back on track and the program switches both motors on again. It's simple, but it works.

Now, that is what I thought we were talking about and is why I suggested those simple digital sensors in my first post.

If that is not what you want to do - if you want to use analogue measurements and differential steering using pwm - then that is a whole different ball game and you will need an algorithm to relate extent of deviation to amount of steering.

If you haven't built a line-follower before then I suggest you build a simple one, like the one above, to start with. Then when you're confident in in your programming, wiring and the operation of your sensors, you can move on to more sophisticated things.

There is also a halfway-house approach, where you use an array of simple digital sensors, say four or six, to get an indication of how far you have deviated from the track, and use pwm speed control to steer a lot or a little as appropriate. I would make that my second project.

Personally I wouldn't bother with analogue sensors for line following, although some people do.

--

The benefits of using a phototransistor rather than an LDR in this sort of application are:
It is faster
It is more sensitive
It is directional
If you use an infra-red phototransistor it is less affected by ambient light
It is smaller, and probably cheaper.

User avatar
ZacharyI123
Posts: 263
Joined: Sun Jun 17, 2012 1:09 pm
Location: Ilford, Essex
Contact: Website

Re: One wheel quicker/more powerful than the other

Sun Oct 20, 2013 12:35 pm

exartemarte wrote:
ZacharyI123 wrote:
I see! So I could do it how you do, and keep switching resistor until the sensetivety is right, or I could put an infra-red LED where my white led it and the phototransistor where my LDR is.

This would be the setup:

3V3 -> 330 ohm resistor -> Infra-red LED -> GND
3V3 -> 680 ohm resistor -> phototransistor -> 4.3 micro-farrad capacitor-> GND
GPIO pin -> positive of capacitor

This is what my code would do:

Set the GPIO pin to a low output and wait (discharging the capacitor)
Turn it into a input and start a timer
Stop the timer when the input becomes 1
That counter would give me an analogue inout (sort of!)
I could then compare the analogue input to the analogue input of my duplicates of the same circuit in different positions on the car and decide which motors to power appropriately.

What is the advantage of a phototransistor over an LDR?
What you are describing is a method for getting an analogue reading from a digital port, which is not what I was suggesting.

There is a point that needs clarifying: I understood from your earlier posts that you are steering left or right by switching the appropriate motor off - is that correct? If that is what you are doing then there is no point in getting an analogue value because there is nothing your program can do with it. If you are steering by stopping one motor then you can't steer a lot or a little - all you can do is steer or not steer.

Consider this:

Image

This buggy has two simple, digital (ie on/off) sensors, one to either side of the track. If the vehicle is on track then both sensors are over white and the vehicle just drives forward. If one sensor strays onto the black then the program detects that and stops the motor on that side. This makes the vehicle steer so that the sensor moves back onto the white; when it's over the white the vehicle is back on track and the program switches both motors on again. It's simple, but it works.

Now, that is what I thought we were talking about and is why I suggested those simple digital sensors in my first post.

If that is not what you want to do - if you want to use analogue measurements and differential steering using pwm - then that is a whole different ball game and you will need an algorithm to relate extent of deviation to amount of steering.

If you haven't built a line-follower before then I suggest you build a simple one, like the one above, to start with. Then when you're confident in in your programming, wiring and the operation of your sensors, you can move on to more sophisticated things.

There is also a halfway-house approach, where you use an array of simple digital sensors, say four or six, to get an indication of how far you have deviated from the track, and use pwm speed control to steer a lot or a little as appropriate. I would make that my second project.

Personally I wouldn't bother with analogue sensors for line following, although some people do.

--

The benefits of using a phototransistor rather than an LDR in this sort of application are:
It is faster
It is more sensitive
It is directional
If you use an infra-red phototransistor it is less affected by ambient light
It is smaller, and probably cheaper.
Ok. The reason I was going to use an analogue input is so that if two or three of the transistors say they have the line underneath (GPIO reading of 0), I can work out which has more of the line underneath. Does the phototransistor vary its resistance? If that's true then I can use it as a digital input for the line follower, but in other projects I can use it as an analogue input. Would the circuit I mentioned previously work with a phototransistor?

I think for the line follower, I'll use this: http://uk.rs-online.com/web/p/phototransistors/6655362/
Because it has quite a small half viewing angle (24 °) which means it'll focus more on the floor and, it's infra-red so I can get it to work in the dark without it lighting up anything and it won't get distracted by other lights.
Don't be mean, I'm only thirteen 8-)

User avatar
exartemarte
Posts: 376
Joined: Sat Mar 03, 2012 3:51 pm
Location: Middle England
Contact: Website

Re: One wheel quicker/more powerful than the other

Sun Oct 20, 2013 1:36 pm

There is a circuit here that will do what you want, with an explanation of how to use it. You could build the circuit yourself using the components I suggested (from ESR) or buy the buy the Pololu unit ready built (from HobbyTronics in the UK).

That pretty much exhausts the advice I have to offer. What you need to do now is take stock of the advice you been given by a number of people and decide what you are going to do. Let us know how you get on!

Return to “Automation, sensing and robotics”