should detect the PropBOE connected to your
computer. If it doesn’t, check the connection and
be sure power is applied to the PropBOE. Its
green power indicator should glow.
4. Compile the program by choosing Run->Compile
Current->Load EEPROM (or press F11).
LISTING 3 - !ReadADC.spin
OBJ
system : “Propeller Board of Education”
pst : “Parallax Serial Terminal Plus”
adc : “PropBOE ADC”
time : “Timing”
Important! The program in Listing 1 requires the
use of several object libraries which add important
functionality. These libraries — provided by Parallax —
are included with the program download on the SERVO
website. If any of these object libraries are missing, the
program will not compile or run. Also take note of the
indentation used in Spin programs. It’s important. The
indenting is how Spin keeps track of program blocks,
like if conditional tests and repeating loops.
VAR
The program is automatically compiled and
uploaded to the PropBOE. Upon successful compilation,
the program runs automatically. Assuming everything
has been connected properly, the motors should turn in
various directions as the robot goes through its motion
routines.
Fully test the robot by first disconnecting the USB
cable from the PropBOE and temporarily unplugging the
nine volt battery. Place the robot on flat ground and
plug the nine volt battery back in. The robot should go
through its motion routines: forward, backward, turn
right, turn left, and stop. If one or both motors turn in
the wrong direction, remove power and flip the
terminal wiring from the affected motor on the H-bridge.
The best surfaces for testing are tile, wood, or a
kitchen table. Carpet is acceptable as long as it has a
very low nap. If the bot appears to struggle as it’s
moving along, relocate it to ride over a smoother
surface.
long ad0
long ad1
PUB Go
system.Clock(80_000_000)
repeat
ad0 := adc.In(0)
ad1 := adc.In(1)
Display
time.Pause(50)
PUB Display
pst.Home
pst.Str(String(“ad0=”))
pst.Dec(ad0)
pst.Str(String(“, ad1=”))
pst.Dec(ad1)
pst.ClearEnd
Using Light to Control
Your Robot
Listing 2 shows how to
control the Beginner Bot using
a flashlight by shining the light
into the photocell eyes. As
with the previous program
example, Listing 2 also makes
use of object libraries. You
need these files — which are
listed at the top of the
program — in order for the
project to compile.
The program tells the
microcontroller to read the
value from both photocells.
A series of if conditional logic
tests determine if there’s
enough light to follow, and if
so, in what direction the robot
should travel.
Note the threshold value which is used to set the
boundary between dark and light. I’ve set the
light/dark threshold to 900 — out of a range of 0-1023
— as a starting point. Try higher or lower values to see
what works best with your particular CdS cells.
When both cells receive light over the threshold, the
robot drives forward. When only one cell receives light
over the threshold, the robot turns in the direction of
the light. If neither cell receives light over the threshold,
the robot stops.
Upload the program in Listing 2. Remove the
programming cable when transfer is complete. Move to
FIGURE 6. Spring-loaded leaf switch used as a
contact bumper. When the switch closes, the
PropBOE registers it as a collision.
SERVO 12.2011 51