Top Topics

74*245 Motor Driver

H-Bridge Driver

Simple PWM Gen.

Handy Method Measuring RPM

Measuring RPM via Photo reflector

Introduction to Robotic

DC, Stepper,and Servo Motor

Related Link

Microcontroller Tutorial

Computer Interface
Tutorial

.............more links

 

 

 

BACK

Complete Circuit:

Using the BASIC Stamp II is very convenient because all of its I/O lines are interchangeable; the only reason we used the particular pins indicated in the schematic is because it made the wiring convenient. The Stamp's on-board voltage regulator allows it to run straight off of a 9-volt battery, and the LEGO motors are designed to run at 9V as well. The Stamp's regulated 5V output is used for the motor controller's logic power supply. The diagram does not show the Stamp's 12 I/O lines available for expansion.

4. BASIC Stamp II Software
(In this section, we go over the major features of the program. For more details, view the entire program. Note that the pin numbers used in the program correspond to the schematic diagram above.)

The BASIC Stamp makes serial I/O very straightforward with its serout instruction. A typical use of the instruction is:

serout MC_SOUT, 32, [$80, 0, LFWD, SPEED] 'Left motor forward at SPEED

The first value, MC_SOUT, specifies the serial output pin to use, which is P10 in our example. The second argument, 32, specifies the settings for the serial output; we use 32 because it specifies the baud rate to be 19,200, which is the maximum rate at which the motor controller can receive. The four values in square brackets are the values sent out over the serial line.

The first two values sent to the motor controller are always hex 80 (128 in decimal) and 0, which let the motor controller know that it is being issued a command. The third value specifies the motor number and direction. To help prevent mistakes with this third parameter, we defined constants for forward and backward for our two motors at the beginning of our program:

LFWD con 0
LBAK con 1
RFWD con 2
RBAK con 3

(Of course, which constant gets assigned which number depends on how your robot is wired up and what you call forward and reverse or left and right.) The final parameter in the 4-byte sequence is the speed at which the motor should run, where 0 stops the motor and 127 (7F hex) is full speed.

The main loop of the program is rather simple since the robot does not do much. For simplicity, we use the pause instruction to determine the time that the robot backs up or turns, but the BASIC Stamp could potentially be doing something more useful during that time.

loop: 'Go forward till bump something
serout MC_SOUT, 32, [$80, 0, LFWD, SPEED] 'Left and right motors forward at SPEED
serout MC_SOUT, 32, [$80, 0, RFWD, SPEED] '32 indicates 8 bits, no parity, non-inverted,
' buad rate 19200
if (RBUMP = 0) then rbumped 'If bumped, turn backward in appropo direction
if (LBUMP = 0) then lbumped
goto loop


rbumped: 'Turn backward right, then spin left in place for a random time
serout MC_SOUT, 32, [$80, 0, LBAK, SPEED] 'Turn backward for 1 sec
serout MC_SOUT, 32, [$80, 0, RBAK, SLOWSPEED]
pause 1000

serout MC_SOUT, 32, [$80, 0, LBAK, SPEED] 'Spin in place for random time, TURNTIME
serout MC_SOUT, 32, [$80, 0, RFWD, SPEED]
random TURNTIME
pause (TURNTIME*5) + 250 'pause between 0.25 and 1.5 seconds

goto loop


lbumped: 'Turn backward left, then spin right in place for a random time
serout MC_SOUT, 32, [$80, 0, LBAK, SLOWSPEED]
serout MC_SOUT, 32, [$80, 0, RBAK, SPEED]
pause 1000

serout MC_SOUT, 32, [$80, 0, LFWD, SPEED]
serout MC_SOUT, 32, [$80, 0, RBAK, SPEED]
random TURNTIME
pause (TURNTIME*5) + 250

goto loop

For more details, view the entire program. Note that the pin numbers used in the program correspond to the schematic diagram above.

5. Results and Conclusion
This project shows how easy it is to use the Pololu motor controller with a BASIC Stamp II. While the robot we built is certainly very simple, it is still a fun project that is especially appropriate as a first robot. Since the motor controller only requires two I/O lines, there is plenty of room for expansion. In sample project 3 (coming soon), we'll make the robot more interesting by adding on our IR beacon to allow the robot to chase another robot.

BACK