Thursday, April 30, 2009

Take Charge of your Scribbler Robot's IR Capabilities

The Scribbler Robot represents a great value to the robotics enthusiast. It's affordable and comes completely assembled with a built-in Parallax BASIC Stamp 2, drive motors and a host of on-board sensors. It comes preprogrammed with seven simple routines to demonstrate its sensors and motors. Software and a serial cable are included so it can be programmed in PBasic and it offers a simple GUI that lets children use it to draw patterns on paper as it rolls along. Although it has been used in a few introductory college courses, I believe that Scribbler has been largely dismissed as a "kiddie" robot. It is similar in many ways to its popular kit-based brother, the Boe-Bot, except that the Scribbler's sensors and I/Os are hard-wired. It is just as programmable and a good match for this project.

Scribbler's built-in IR sensor has a fixed, calibrated aperture that can receive and track external IR signals. Scribbler's "set and forget" hardware motor drivers are easier to program than Boe-Bot's servos, which require continuous software pulsing. Scribbler's circular shape and low profile are superior for maneuvering and docking. Finally, Scribbler's hard-wired sensors won't vibrate loose or get knocked out of alignment.

For Phase 1 of this project, we'll use a TV remote control to drive and steer Scribbler around, and track toward the remote control beam. This is great fun and only requires an infrared remote and an hour of programming; no robot modifications are necessary. In Phase 2 we'll build a simple charger that Scribbler can locate and dock with using its on-board sensors. This will require minor robot mods and some electromechanical construction, but I have kept things as simple as possible so that you can get similar results. I'll call out the specific items I used so you can duplicate my hardware if desired.

There is a wealth of online information on programming Scribbler and BASIC Stamps, and much of the programming info written for Boe-Bot applies to Scribbler as well. Andy Lindsay, who works in Parallax's education division, is a genius, and his books "What's a Microcontroller" and "Robotics with the Boe-Bot" are required reading for any robot enthusiast. The links below provide the information that we hunger for.

Primary Scribbler download page:
BASIC Stamp Editor download:
Infra-Red (IR) with the Boe-Bot:
Robotics with the Boe-Bot:
What's a Microcontroller?:


Like many more expensive robots, Scribbler's differential drive isn't perfect. Electromechanical variations between the two motors, fluctuating battery voltage and the lack of wheel encoders all can cause each wheel to turn at slightly varying rates, so the robot's software must be periodically recalibrated to go (mostly) straight. It will generally tend to steer left or right somewhat, and perhaps not consistently. Fortunately, the robot can still track to an IR source using its IR sensor. Further, it can distinguish between multiple IR sources, so Scribbler could consistently navigate from A to B to C with line-of-sight restrictions. The single IR sensor senses the presence of an IR signal, but not its direction. As a result, our simplified tracking routine is as follows:
signal detected = drive forward, signal not detected = turn until signal detected


Scribbler reads IR control pulses on a carrier frequency of ~39 kHz. Low intensity signals (like our charger beacon) have line-of-sight restrictions, while most remote controls emit high energy signals that reflect off walls and ceilings for thorough coverage in a room. We'll control the robot using SONY television IR codes. You'll want a nice big universal remote configured as such for several reasons. First, you want large buttons for good control ergonomics. Ideally, get one with control buttons styled as four obvious directional arrows: forward, reverse, left and right. Next, you need to broadcast a strong IR signal that the robot detects easily through its tiny forward-facing aperture. Finally, we want a strong TV remote IR signal to significantly overpower our charger beacon's continuous low-intensity signal. I used Radio Shack Remote No. 15-2142.


Using the PBasic editor, program the robot with the program listed for the Scribbler Hack in the downloadable source code, click here. You will also find Scribbler I/O declarations listed there.
Scribbler I/O Declarations

LedRight PIN 8
LedCenter PIN 9
LedLeft PIN 10
Speaker PIN 11
MotorRight PIN 12
MotorLeft PIN 13
ObsTxRight PIN 14
ObsTxLeft PIN 15
LightRight PIN 0
LightCenter PIN 1
LightLeft PIN 2
LineEnable PIN 3
LineRight PIN 4
LineLeft PIN 5
ObsRx PIN 6 Stall PIN 7

Now you can drive the robot around with the IR remote buttons shown in the diagram. This program monitors the wheels' stall sensor on pin 7 and tries to stop the robot if it hits something. This sensor is most reliable at full speed. If you run the PBasic editor with the robot hooked up to your serial port, the IR command codes received will display in a DEBUG window. Use these codes to modify the software to use different buttons if desired.

You'll also need to calibrate your robot's straight-line driving ability by changing the numbers in the "fwd" and "bwd" subroutines. Their pulsout commands drive the left motor (on pin 13) and right motor (on pin 12). Values are 3000 for full speed forward, 2000 for stop, and 1000 for full speed reverse. Proportional numbers give proportional speeds. Ideally, pulsout 13, 3000 and pulsout 12, 3000 would drive the robot straight forward. But if your robot curves left, you need to slow down your right motor. In this case, you might try pulsout 13, 3000 and pulsout 12, 2900 then adjust as necessary.


The most interesting aspect of this program is having Scribbler follow your IR remote beam. Press the MUTE button, and the 3 green LEDs light to indicate TRACKING mode. It drives forward any time it senses a MUTE signal. When no MUTE signal is detected, the robot circles left. The remote's intense IR signal overwhelms Scribbler's IR sensor unless you point it away from the robot. Press & hold MUTE while you lead the robot around the room by aiming the remote at the floor or wall. Different features around your room will reflect the IR beam differently, and it is interesting to see how sensitive your robot is to the reflections. Your remote will "time out" after 30-60 seconds of holding the mute button, so release and press again. Pressing the STOP button will end tracking mode, as will a motor stall condition.

To make the robot track directly toward your remote, you must reduce the intensity of the IR signal. The easiest way is to cover your remote's IR LED with a layer or two of black electrical tape and poke a small hole in it. Of course, you'll have to trigger tracking mode by pointing your reduced-output remote directly at the robot's IR sensor.


To download the PHASE 2 software click here (zip file). The download is also available at the end of the article (page 2).


In phase two of this project, I will show you how to create a docking station and how to modify the Scribbler so that it will self-dock and charge its batteries. This material, which was not included in the printed article, is laid out below. You'll need an AC adapter to provide 14-18 volts DC, no load voltage. First choice is an old transformer-based "wall wart" rated at 12 volts, ~ 500 mA that actually puts out over 12 volts. New switching-type units (required by law) are more efficient, but regulated to 12.0 volts and may not charge our six batteries fully. Adapt and overcome! Scrounge around in your drawers; find an adapter from an old cordless drill or answering machine, or use an RC car battery charger. Use a multimeter to verify the no-load output is 14--18 volts.

Charger IR Beacon

Figure 3

The Charger IR Beacon emits a low-intensity IR signal for the Scribbler to home in on. Build the LM556 timer circuit shown in Figure 3 above; all parts are available at Radio Shack or equivalent. (I used a small copper PC board, half of RS # 276-148.) Construction is not critical, but keep your wiring short and neat. Use a socket for the LM556 IC, and use a multi-turn 10K pot RS #271-343. The LM556 has two timer/oscillator circuits; one will generate a 39 kHz carrier frequency (critical), and the other will pulse the carrier at about 1.35 kHz (non-critical). To calibrate your circuit, you'll need a multimeter or scope that counts frequency. Temporarily ground pin 6 to pin 7 on the LM556 timer, and then adjust the 10K pot to obtain a 39 kHz signal at output pin 9. In use, this pulsing signal will be sent out of two IR LEDs, aimed horizontally about 30 degrees apart for good coverage as you can see in the photo of the beacon circuit board in Figure 4.

Figure 4
Beacon circuit board. Two IR LEDs are aimed horizontally angled slightly apart for good coverage.

You can adjust the LEDs' series resistors to suit your environment. I got a detection range of 10+ feet using 82 ohm resistors. Lower resistances emit stronger signals that can be tracked from farther away, but they may reflect off various surfaces and give false signals. Scribbler will use the PBasic COUNT command to identify your particular beacon, so you must calibrate your software to recognize your beacon signal. Once your beacon is working, aim your Scribbler at it while attached to the serial port and run this one-line program to view the pulse rate of your particular beacon.

aaa:COUNT 6,15, B0:DEBUG ? B0:GOTO aaa

My beacon's pulse rate was 18-19. Your exact values may be different, but the important thing is that your results should be steady, not varying by more than +/- one unit. You'll use this range of numbers to calibrate your tracking software.

If you don't have access to a frequency counter to adjust the pot to 39 kHz, you can try the following procedure, assuming that your beacon is built and functioning properly otherwise: run that same one-line program above, which counts the IR pulses received. With your Scribbler connected to your PC and the DEBUG screen displayed, let your robot see the working beacon and adjust the beacon's 10K trimpot until you see numbers displayed in the DEBUG window in the range of 15-24. Adjusting the pot won't change the values displayed, but will tune the beacon's carrier frequency to match the robot's IR sensor. Find the pot's range of adjustment that works, and center the pot in this range.

My original plan was to hack a $5 remote control into a continuous IR beacon. That would be simple, fast and cheap. Phase 1 clearly demonstrates that Scribbler can track a handheld IR remote. True, but I haven't found a remote yet that doesn't auto-shut off after 30-60 seconds. A battery preserving routine for when we sit on the remotes? At least one remote lost its life before I figured that out.

If you're familiar with 555/556 circuits, notice the 1N914 diode between pins 1 and 2. Without it, the modulation duty cycle is 50% and Scribbler's IR detector can't see it for more than a second. The diode drops the duty cycle under 50%, which Scribbler can continuously detect. I lost sleep figuring that out!

No comments:

Post a Comment