Skip to content

Fun With Snap Circuits 8: I, Roverbot

February 10, 2012

1. A robot may not injure a human being or, through inaction, allow a human being to come to harm.

2. A robot must obey the orders given to it by human beings, except where such orders would conflict with the First Law.

3. A robot must protect its own existence as long as such protection does not conflict with the First or Second Laws.

–Isaac Asimov

It has been a while since I have updated Fun With Snap Circuits, but I have been busy with creating some Instructables. Also, my hack adding a grabber arm to the Spy Video Trakr  has been featured on several blogs:

Hack A Day:

http://hackaday.com/2011/11/03/bomb-disposal-robot-with-lego-gripper/#more-60341

Dangerous Prototypes:

http://dangerousprototypes.com/2011/10/22/spy-video-trakr-with-lego-robot-arm/

Hacked Gadgets:

http://hackedgadgets.com/2011/09/19/spy-video-trakr-claw-attachment-hack/

Build Lounge:

http://www.buildlounge.com/2011/09/20/spy-trakr-gets-a-claw/

So, in this blog post I have decided to introduce the subject of robotics using Snap Circuits. You will learn how to build a simple Snap Circuits programmable robot.


First, you will learn how to install the PICAXE Programming Editor (the PICAXE is the microcontroller, or computer brain for your Snap Circuits programmable robot, or Roverbot). Next, you will learn what a simple PICAXE program looks like and what it does. Then you will learn about the various parts and electronic components used to build  the Roverbot. You will then assemble the Roverbot. Finally you will learn how to program and test the Roverbot.

To build the Roverbot, I used parts from three different sets, the Snap Circuits Motion Detector, Snap Circuits Rover, and Snap Circuits Micro. Elenco does not currently have a Snap Circuits programmable robot product. I find this surprising since Elenco has developed the Snap Circuits Rover, which is a remote controlled rover and the Snap Circuits Micro that teaches you how program the PICAXE microcontroller and how to build circuits for the PICAXE, but Elenco has yet to develop a product that combines the PICAXE with the Snap Circuits Rover.

I designed the Roverbot to be easy to build completely out of Snap Circuits parts and easy to program.

The following are the Snap Circuits parts you will need to build the Roverbot (parts can be ordered separately from Elenco http://www.elenco.com/product/productlist/snap_circuits®; or C & S sales http://cs-sales.net/sncirepa.html):

Software CD from the Snap Circuits XP or Snap-Micro I kit (if you do not have either of these kits you can download the PICAXE Programming Editor from http://www.picaxe.com/Software/PICAXE/PICAXE-Programming-Editor/)

10 X 7 Plastic Base Grid
Snap Circuits Rover
9 volt Battery Block B5
Motor Control IC U8
8 Pin Socket U14 With PICAXE 08m Installed
4 1K Ohm Resistors R2
Slide Switch S1
USB Programming Cable
(You may substitute the Snap Circuits USB to DB9 Converter and the Snap Circuits DB9 Programming Cable if you do not have the USB Programming Cable)
Snap Circuits Micro Software CD
3 Single Snaps
9 Two Snap Conductors
1  Three Snap Conductor
2 Four Snap Conductors
1 Seven Snap Conductor
1 Orange Jumper Wire (Orange)
1 Yellow Jumper Wire (Yellow)
1 Green Jumper Wire (Green)
1 Purple Jumper Wire (Purple)
1 Gray Jumper Wire (Gray)
1 White Jumper Wire (White)

Installing The PICAXE Programming Editor
 
The PICAXE Programming Editor is the software you will use to program the PICAXE micro-controller installed on the Snap Circuits 8 Pin Socket U14 block (the PICAXE chip carrier). The software contains the flowcharting software, the editor that you can use to write BASIC programs and the compiler for the micro-controller.BASIC is an acronym that stands for Beginners All-purpose Symbolic Instruction Code. It was created way back in the 1960s as an easy to understand programming language to introduce students to computer programming.
 
What’s a compiler? Have you seen those geeky T-shirts that say “there are only 10 types of people in the world: those who understand binary, and those who don’t?” If you find yourself scratching your head instead of laughing hysterically, then you don’t understand binary. Computers, on the other hand, understand only binary. 1s and 0s. On and off.
 
I have heard of some people who can do binary code, or machine language in their heads, but the rest of us normal people would have a difficult time writing a computer program out of nothing but 1s and 0s. Instead we use a higher level language like BASIC to write software.
 
Have you ever been to a foreign country and didn’t know the language? You can hire a translator to translate what you say into the language that the locals can understand. That’s what a compiler does. Computers can’t understand BASIC so a compiler translates the software you write in BASIC into machine code, or the 1s and 0s that computers can understand.
 
Part needed for this step:
 
Software CD from the Snap Circuits XP or Snap-Micro I kit (if you do not have either of these kits you can order the CD from Elenco or download the PICAXE Programming Editor from http://www.picaxe.com/Software/PICAXE/PICAXE-Programming-Editor/)
 
Install the PICAXE Programming Editor from the Snap Circuits XP or Snap-Micro I software CD (Windows XP/Vista/7). The setup program will auto run when you put the CD in the drive. Click the large button that says “Install the PICAXE Programming Editor software.”
 
 
Insert the Snap Circuits USB Programming Cable into an empty USB port on your computer. Click on the PICAXE Programming Editor icon on your desktop to open the editor.
 
The Options dialog will automatically open (if the “Show options on startup” check box is checked). If it does not, go to View > Options. On the Mode tab, select 08M–this is your PICAXE microcontroller.
 
 
Click on the Serial Port tab and select the COM port where your USB Programming Cable is connected. Click the Ok button to go to the programming editor.
 
In the Programming editor click File and then click New Flowchart to start entering your flowchart.
 
 
This is what a PICAXE Programming Editor flowchart looks like. The flowchart in this example is very simple–can you guess what it does? It will turn a motor that is connected to pin 4 on the PICAXE for 10 seconds. We can take a look at how each step is processed.
 
The “start” terminator is ignored by the compiler, but is useful to you to easily locate the start of your program.
 
The “pause” process tells the PICAXE to wait 1000 miliseconds, or 1 second before proceeding to the next step in the program. When you tell the PICAXE to execute the program, you will notice a 1 second pause before anything happens.
 
The parallelogram flowchart symbol represents data, or input/output. It contains the command “high 4” and this command will set pin 4 high, which means the microcontroller will send voltage to that pin, or output current to that pin. If you have a motor connected to pin 4 then current from this pin will pass through the motor and the motor will begin to spin.
 

The “pause” process tells the PICAXE to wait 10000 miliseconds, or ten seconds. This means pin 4 will remain high for 10 seconds thus continuing to send current to the motor for ten seconds (the motor will spin for ten seconds).

The data flowchart symbol contains the command “low 4.” It tells the PICAXE to turn the pin off, or to output 0 volts. This will cut power to the pin and the motor connected to it will stop spinning.

If you want to see what the BASIC code looks like, you can click Flowchart and then click Convert Flowchart to BASIC. The code will look like the the following (Note: I added the in-code comments for clarity):

‘BASIC converted from flowchart:
‘C:\DOCUMENTS AND SETTINGS\DESKTOP\SNAPROVERBOT.CAD
‘Converted on 10/30/2011 at 20:53:11

main:
pause 1000     ‘Tells the PICAXE to wait 1000 miliseconds (1 second)
high 4                ‘Sets pin 4 high, which sends current to pin 4 (if there is a motor connected it will spin)
pause 10000   ‘Tells the PICAXE to wait 10000 miliseconds (10 seconds–motor will spin for 10 seconds)
low 4                  ‘Sets pin 4 low, or ouputs 0 volts. This cuts the power to the pin and the motor stops spinning.

 
The PICAXE Microcontroller
 
What’s this PICAXE thingy? The PICAXE is a micro-controller, or a computer on a microchip. It is the computer brain of your Roverbot. It’s not as powerful as the computer in your video game console, or your laptop computer, but it does have circuits for processing, memory, logic, input and output. You can find micro-controllers in many toys, your DVD player, your TV, your microwave oven, and nowadays even in your washing machine and dryer. In your microwave, for example, the micro-controller processes what you punch in on the keypad, outputs information on the display screen, controls the cooking time, the turntable, and the bell when your dinner has finished cooking.
The Snap Circuits block (U14) that serves as the PICAXE carrier is specially labeled to more easily identify the pins on the PICAXE microcontroller chip. Think of the chip as a square bug with eight legs. There is a notch in the top to help you orient the chip and a little dot marks leg 1. Legs and pins can sometimes get confusing, but on the U14 block the legs (and the corresponding snaps the legs are connected to) are labeled in red 1-8 going in the counterclockwise direction. The functions of each leg are labeled in blue.
 
Leg 1 (snap 1): This is the postive (+) voltage input. It can take from 3 volts to 5 volts. You will want to avoid putting more than 5 volts through the PICAXE since this might damage it.
 
Leg 2 (snap 2): S-In. Serial In pin–it is used to download your program to the PICAXE.
 
Leg 3 (snap 3): This pin 4! Luckily the snaps are labeled or the pin numbers could get confusing. Pin 4 can be used as an Input pin or an output pin. In the previous step this is the pin the program set to high to send current to the motor for ten seconds. then the program set the pin low to cut the power to stop the motor from spinning.
 
Leg 4 (snap 4): This is pin 3. It is an Input only pin.
 
Leg 5 (snap 5): This is pin 2. It can be used as an Input pin or an output pin.
 
Leg 6 (snap 6): This is pin 1. It can be used as an Input pin or an output pin.
 
Leg 7 (snap 7): This is pin 0. It is an Ouptut only pin. It is also the Serial Out pin. This pin will also be used when downloading your program to the PICAXE.

Leg 8 (snap 8): This is GND or Negative (-) for the PICAXE

 
Snap Circuits Rover
 
Now that you have installed the PICAXE Programming Editor and learned how to write a simple program, its time to starte building your robot. There are three basic parts that you need to build a robot: a power source, a brain (the PICAXE of course) and a means of locomotion.
The Snap Circuits Rover is one example of locomotion. It has advantages and disadvantages.Advantages:It is a ready-made vehicle. In other words, you don’t have to build a vehilce–it is already built for you.It has two motors, one on the right side and one on the left side. Each motor is connected to the front and rear wheels by a series of geers (the geering was added in to slow the Rover down rather than a need for extra torque) so that the right motor turns the right front and rear wheels, and the left motor turns the the left front and rear wheels. In the first picture You can see the front of the rover as well as the gears that connect the left side wheels to the left side motor.
 
It is designed to have the Snap Circuits base plate connected directly to it. It is also designed so that power and motor control are easily connected with Snap Circuits jumper wires. The following picture picture explains the function of each snap. on the back of the rover:
 

The rover has a battery compartment for six AA batteries to power the motors with 9 volts.Disanvantages:It is not designed to have attachments such a robotic grabber arm attached to it.You must be careful to design your circuit so that you do not accidently pass the 9 volts from the rover’s battery pack through the PICAXE microcontroller since this will most likely damage the PICAXE.
 
The Voltage Regulator
 
The simplest way to power the rover and power the PICAXE is to use two different power supplies that share a common ground. To power the PICAXE, you can use the Snap Circuits B5 block. The advantage to using this block is you can connect a standard 9 volt battery to the block and it will deliver a reliable 5 volts to the PICAXE through L7805 voltage regulator circuit (see circuit schematic). The B5 also has two 5 volt outputs–one to power the PICAXE and one that you can use to power another device.
Now you have a convenient way of powering your PICAXE with a reliable 5 volts from the B5 block. As a safety feature for the PICAXE, it would also be a good idea to keep the 9 volts from the rover separate from the PICAXE in case while you are building and testing the circuit something gets connected the wrong way. Thus for this build you will use an H-bridge. It has special circuitry inside it that will prevent the 9 volts from the rover’s battery pack from accidently passing through the PICAXE.
 
The H-bridge
 
This  is a simplified diagram of an H-bridgecircuit:
 The motor in the center is connected to 9 volts of power and ground by four switches (S1, S2, S3, and S4). With all four switches off, the motor will not get any power and the motor will not turn.
 
The switches can be turned on in pairs:
 
S1 and S4 or S3 and S2 to allow current to pass from the 9 volt batteries through the motor to negative or ground.
 
If you close switches S1 and S4, current will flow through the motor and it will turn in one direction.
 
If you close switches S3 and S2, current will flow through the motor and it will turn in the opposite direction.
 

The H-bridge is a very simple circuit. Unfortunately it would be impractical to use manual switches to drive a motor. Several companies make H-bridge integrated circuits (ICs) that are easy to use by simply applying power to a particular pin also called “setting the pin high” to drive the motor in one direction. Cutting the power to that pin and applying power to another pin will drive the motor in the opposite direction. The circuitry inside the H-bridge ICs is somewhat complicated, so most folks will choose to use an H-bridge IC rather than building the circuit themselves.

Above is the Snap Circuits Motor Control IC, or H-bridge. At the top of the figure you can see the electronic schematic of the Motor Control block. On the lower left you can see a picture of the block. The lower center shows the function of each snap for the block and on the lower right is a description of what each snap does.
 
Build the Circuit for the Roverbot
 
Build the circuit as shown in the diagram.
 
 
Parts needed:
 

10 X 7 Plastic Base Grid
Snap Circuits Rover
9 volt Battery Block B5
Motor Control IC U8
8 Pin Socket U14 With PICAXE 08m Installed
4 1K Ohm Resistors R2
Slide Switch S1
USB Programming Cable
(You may substitute the Snap Circuits USB to DB9 Converter and the Snap Circuits DB9 Programming Cable if you do not have the USB Programming Cable)
Snap Circuits Micro Software CD
3 Single Snaps
9 Two Snap Conductors
1  Three Snap Conductor
2 Four Snap Conductors
1 Seven Snap Conductor
1 Orange Jumper Wire (Orange)
1 Yellow Jumper Wire (Yellow)
1 Green Jumper Wire (Green)
1 Purple Jumper Wire (Purple)
1 Gray Jumper Wire (Gray)
1 White Jumper Wire (White)

Here’s what the roverbot will look like:

Program the Roverbot
 
Create this flowchart in the PICAXE Programming editor.


I’ve divided up each function into columns to make the flowchart easier to read.

 
In the first column under “start” are the commands to test the Roverbot’s left forward motor. This will cause the Roverbot to turn right.
 
Under the label “Test left backward” are the commands to turn the Roverbot’s left motor backwards. This will cause the Roverbot to turn left.
 
The next four columns are the commands to test the right motor turning forward and backward, then turn both left and right motors forward (Roverbot rolls forward), and finally turns both motors backwards (Roverbot rolls backwards).You can also convert the flowchart into BASIC program code.
 
Click Flowchart and then click Convert Flowchart to BASIC. The following is what the code will look like in BASIC (I added the comments in the code to describe what the code does):
 
‘BASIC converted from flowchart :
 
‘C:\DOCUMENTS AND SETTINGS\DESKTOP\SNAPROVERBOT.CAD
‘Converted on 10/30/2011 at 20:53:11
main:
‘Snap Rover programmable robot

‘Test left forward
  pause 1000
  high 0
  pause 2000
  low 0
‘Test left backward
  pause 1000
  high 1
  pause 2000
  low 1
‘Test right forward
  pause 1000
  high 2
  pause 2000
  low 2
‘Test right backward
  pause 1000
  high 4
  pause 2000
  low 4
‘Test forward
  pause 1000
  high 0
  high 2
  pause 2000
  low 0
  low 2
‘Test backward
  pause 1000
  high 1
  high 4
  pause 2000
  low 1
  low 4
‘End program
  stop
 
The code is very simple but should demonstrate how easy it is to program the Roverbot.
 
To run the program, make sure the Snap Circuits Slide Switch S1 is switched off else the program will execute while the program is still downloading to the PICAXE and may accidentally disconnect the programming cable as the Roverbot runs through the motor tests. Next, make sure that the Snap Circuits 9 volt Battery Block B5 is switched on or the program will not download to the PICAXE. Connect the Snap Circuits USB Programming Cable to your computer.
 
(Using the DB9 to USB cable):
1.  Connect the yellow snap to the S-In snap on the Snap Circuits 8 Pin Socket U14 block (the PICAXE chip carrier).
 
2.  Connect the red snap to the S-Out snap on the Snap Circuits 8 Pin Socket U14 block (the PICAXE chip carrier).
 
3.  Connect the black snap to the GND, or negative (-) snap on the 8 Pin Socket U14 block (the PICAXE chip carrier).
 
In the Programming Editor click PICAXE and then click Run. A status bar will display to show the progress of the download of the program to the PICAXE.Wait a minute or so after the program finished downloading, then place the Roverbot on the floor a safe distance from any obstacles. Then switch the Snap Circuits Slide Switch S1 to on. When you are ready to watch the motor tests, switch on the Snap Circuits 9 volt Battery Block B5 and watch the Roverbot perform the motor tests.
 
 
For further activities with you Roverbot, see my Instructable, Dance Dance Roverbot! Use a PICAXE 08M to create a simple, programmable, light activated, dancing robot out of Snap Circuits:
 
 
 
 
 
Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: