Pizazz Low Cost Robotic Vehicle for Raspberry Pi

pz01

Pizazz – A Robot Vehicle for your Pi, Complete with Sensors and Optional WiFi

Specification

All true robots need some form of input sensors and outputs as well as motors, so we have created this ultra-cheap but full featured robot for your Raspberry Pi. Just look at some of the features:

  • Crystal Clear Pizazz chassis in 3mm acrylic plate
  • 2 pre-wired 48:1 geared motors, complete with noise suppression capacitors
  • No soldering, glueing or adhesive pads etc. All items simply plug or screw together
  • Fully assembled MicRoCon2 controller board – Optional Extended Header if required (select during purchase)
  • Low drop out voltage regulator to safely power your Pi and keep the power separate from the motors. No requirement for two separate battery packs
  • Custom designed 4tronix ultrasonic and LED PCB for easy fitting of the ultrasonic distance sensor and provide 4  individually controllable output LEDs
  • LEDs can be driven directly using Python or ScratchGPIO commands
  • InfraRed line sensors with adjustable positions
  • Wifi dongle (optional)
  • 6-cell battery holder
  • On-Off switch
  • All the wires, screws and mountings required
  • We also offer an optional SD card pre-loaded with ScratchGPIO, VNC, Python and example files in Pyhon and ScratchGPIO so you can get going straight-away
  • All you need to provide is the Raspberry Pi and the batteries

Links to Get you Started

Assembling Pizazz Robot for Raspberry Pi

Pizazz Assembly Instructions

NB. Click on any image to enlarge

1. First check you have all the parts

pz03b

  • Main acrylic chassis plate with pre-wired battery pack and switch
  • Two motors with attached wires and noise suppression capacitors
  • 2 Wheels
  • Bag containing front caster wheel and mountings
  • 2 x line sensors
  • MicRoCon robotics controller board (assembled)
  • Ultrasonic and LED board (assembled)
  • 2 x 3-way 20cm jumper leads
  • 2 x 2-way 30cm jumper leads
  • 4-way 30cm jumper lead

 

2. Fit battery holder to chassis

step2

  • Remove the brown protective paper from the acrylic chassis plate
  • Push the switch into the hole until it clicks into place
  • Use 2 countersunk 12mm M3 screws and nuts to fit the battery holder. Ensure that the head of the screws lies flat inside the holder so that batteries fit in properly

 

3. Attach the motors

step3a

You require:

  • 4 x Motor mounts, after removing the brown protective paper
  • 4 x M3 30mm screws
  • 4 x M3 nuts
  • 2 x Motors

step3b

  • Mount the motors on tyhe bottom of the chassis plate (opposite side to battery holder)
  • For each motor, insert one motor mount through the slot in the top and the other sits in the slot on the edge of the chassis plate
  • Mount each motor with the wires on the outside as shown in the photo above
  • Push the 30mm screws in from the outside and attach the nuts on the insert
  • Make sure the motors a fitted flush to the chassis plate and do not move around

 

4. Fit the mounts for the Raspberry Pi

step4a

You will need:

  • 2 x 10mm hex spacers
  • 2 x M3 6mm pan head screws (to mount the spacer to the chassis plate)
  • 2 x M3 6mm countersunk screws (to mount the Pi to the spacers)

step4b

View from underneath showing the Pi mounted (don’t mount it now as you will need to remove for the next step)

 

5. Mount the Caster Wheel

step5a

You will need:

  • 4 x 10mm hex pillar (brass)
  • 8 x M3 8mm screws (pan head)

step5b

  • Screw the 4 pillars onto the bottom of the chassis plate using the holes shown above
  • Screw the wheel assembly into the pillars

 

6. Mount the Raspberry Pi and MicRoCon

step4b

  • Mount the Raspberry Pi to the pillars, using the countersunk M3 6mm screws
  • Push the wires from the switch/battery holder and the 2 motors through the holes in the chassis plate as shown

step6b

  • Push the MicRoCon onto the GPIO header of the Raspberry Pi. **Be very careful to ensure the pins are all correctly aligned **
  • Connect the battery wires to the front terminal block as shown: Red to Vin and Black to Gnd
  • Connect the left and right motors to the side terminal blocks. Note the colours of wires in the photo above:
    • Black is nearest the rear on the left side
    • Red is nearest the rear on the right side
  • If you wire these differently, then you will have to change all the example code for it to work correctly

 

7. Mount the ultrasonic Board

step7a

You will need:

  • Ultrasonic and LED board (assembled). Note that you probably have Blue, Green, White LEDs and no Red LED. this is intentional
  • 2 x M3 6mm screws (pan head)
  • 2 x M3 nuts

step7b

  • Screw the ultrasonic board into the top of the chassis plate, using the hole positions shown

 

8. Fit the Line Follower Sensors

step8a

You will need:

  • 2 x line follower sensors (with adjustable sensitivity)
  • 2 x 25mm hex pillars
  • 4 x M3 6mm screws (pan head)

step8b

  • Use the holes nearer the middle of the line follower sensors
  • Arrange the sensors so the LEDs are pointing downwards
  • The terminal pins should be pointing towards the rear of the chassis

 

 9. Wire in the Ultrasonic Board

step9a

  • Use the 30cm 4-way cable
  • Connect:
    • Brown to Gnd
    • Red to Echo
    • Orange to Trig
    • Yellow to Vcc

step9b

  • Use the 2 x 30cm 2-way cables
  • Connect:
    • Green to LED1
    • Blue to LED2
    • Violet to LED3
    • Grey to LED4

step9c

  • On the MicRoCon ultrasonic connector, connect:
    • Brown to Gnd
    • Red to Echo
    • Orange to Ping
    • Yellow to 5V
  • On the “Sig” pins next to the ultrasonic connector, connect:
    • Blue to 18 (physical GPIO pin 18)
    • Green to 22 (this is physical GPIO pin 22)
  • On the “Sig” pins on the 3V3 block of 4 x 3-way pins, connect:
    • Violet to 11 (physical pin 11)
    • Grey to 07 (physical pin 7)

 

Step 10. Wire in the Line Followers

step10a

  • Left Line follower (shown from underneath, so it appears on the right in the photo), connect:
    • Yellow to Gnd
    • Green to V+
    • Blue to S (Signal)
  • Right Line follower, connect:
    • Brown to Gnd
    • Red to V+
    • Orange to S (Signal)

step10b

  • Right Line Follower sensor cable, connect to Pin 12 connections:
    • Brown to Gnd
    • Red to 3V3
    • Orange to Sig
  • Left Line Follower sensor cable, connect to Pin 13 connections:
    • Yellow to Gnd
    • Green to 3V3
    • Blue to Sig

11. Attach the Wheels – All Finished!

step11

NB. When pushing the wheels onto the motors, you MUST hold the motor and not the chassis, otherwise you are likely to break the motor mounts.

Now you can add the batteries, plug in your SD card and start programming

 

Simple Raspberry Pi Traffic Lights

Using Breadboard, LED & Resistors to Create a Traffic Light

Click on any image to enlarge

Fritzing Diagram

tl04

PiCard:

picard02

 

Assembling Hardware

Pop the PiCard pinout display over the GPIO pins on your Raspberry Pi ® making sure that pin 2 is in the corner of the board. This allows you to easily see where to plug the wires.

Push the LEDs and resistors (cut the legs shorter on the resistors first) into the breadboard as shown. LEDs have a positive and a negative leg. Positive leg on the right above is longer. Make sure you plug them in the correct way round or they will not work.

  • Connect resistor on Red LED to pin 7
  • Connect resistor on Amber LED to pin 11
  • Connect resistor on Green LED to pin 13
  • Connect negative leg of Red LED to pin 6
  • Connect negative leg of Amber LED to pin 14
  • Connect negative leg of Green LED to pin20
  • Connect one side of switch to pin 22
  • Connect other side of switch to pin 25

 

Completed Traffic Lights

tl03b

 

Programming

To light the LEDs you need to make the corresponding GPIO pin High. Make the pin low to turn off the light.

  • Red is on pin 7
  • Amber is on pin 11
  • Green is on pin 13

To read the switch you need to read on pin 22. A High value (‘1’) when the switch is up (not pressed) and a Low value (‘0’) when the switch is pressed.

 

Python Examples

Download the example code from here and place it in your home directory on the Raspberry Pi.Then you can run it by typing:

sudo python TrafficKit01.py

This will light the LEDs in the well know traffic light sequence. Now try to edit the code to make it do something different.

You can download the second demo example from here and run it with:

sudo python TrafficKit02.py

This will light the LEDs in sequence but will also check the button occasionally and force it to the Red if the button is pressed

 

ScratchGPIO Examples

You will need to first install ScratchGPIO if you haven’t already. Go to SimpleSi’s page

Within ScratchGPIO you can switch the Red LED on with

Switch it off again with

Similarly you can use the other pins for the Yellow and Green LEDs. A complete Traffic Light Sequence is shown here:

traffic

You can download this from here

 

 

 

 

Battery Power Issues for Small Robots on Raspberry Pi

Summary

When using a robotics controller board with small DC motors on Raspberry Pi, you need to consider how you will power it in such a way as to minimise cost, weight, complexity and maximise flexibility, reliability and power.

These two sets of requirements are not necessarily mutually inclusive. In this article, I discuss three options and try to give the pros and cons objectively and factually:

  1. Power the Pi and the Motors directly from the same 5V power source
  2. Power the Pi from a 5V power source and the Motors from a separate power source (voltage to suit)
  3. Use a voltage to suit the Motors and a regulator to create the 5V for the Pi

For all of this we are assuming the use of small DC motors like these:

gearmotor06

At 6V, these require 120mA running, but stall current can be as high as 500mA

 

1. Powering Pi & Motors from Same 5V Power Source

This is not recommended.

Pros:

  1. You can use a simple 5V USB power source

Cons:

  1. Pi will suffer when the motor takes excess current. Simply starting the motor could generate enough of a glitch to cause a problem: network interface is likely to be lost first
  2. When the battery voltage gets too low the motors will just go slower, but the Pi will stop and can easily corrupt the SD card
  3. With an inductive load – even using flyback diodes – the spikes on the 5V line can cause serious problems and potentially damage the Pi

 

2. Powering Pi & Motors from Completely Separate Power Source

This is a highly safe solution – recommended in many scenarios

Pros:

  1. You can use exactly the right power source for both components: 5V USB power for the Pi, any voltage/current source for the Motors
  2. No wasted energy (heat) so nothing gets hotter than it needs to
  3. Can design smaller control boards as no need for voltage regulator, associated components or heatsink
  4. Easier to support as no issues with regulators

Cons:

  1. You need two sources of power 5V
  2. More expensive solution as you need the same batteries as solution 3, plus something like a USB power bank
  3. Heavier solution – small models may not be able to take the 2 sets of batteries

 

3. Powering Motors from Battery Pack and use 5V Regulator for the Pi

This solution is recommended in some scenarios

Pros:

  1. Only a single battery source needs to be used
  2. Only one battery pack to recharge or switch on and off
  3. Reduces weight and overall product cost

Cons:

  1. When the power gets too low, the Pi will stop and potentially corrupt the SD card
  2. Regulators get hot. At least, linear regulators get hot – switching regulators (see Mo-Pi) are a lot more efficient. Typically 90% or so.

 

4. How Hot do Regulators Get and Why?

This is the killer question and is the main reason that I recommend using separate power supplies (Option 2 above) in many situations.

Linear regulators take an input voltage (say 7.2V nominal for 6 rechargeable cells) and output a fixed voltage (5V for our Raspberry Pi). To do this, they effectively act as a resistor which automatically varies to keep the output voltage constant. We all know Ohm’s law: V = I x R. The power (heat) of the resistor is easily given as V x I. So if the input voltage is 7.2V, the output voltage is 5V and the current used by the Pi is 0.7A, then the power dissipated by the regulator is: (7.2-5.0) * 0.7 = 1.54W

Now 1.5W doesn’t sound very much, but unless you have some way of dissipating that heat, the temperature will only increase. For small input voltages of 7.2V and less, you may be able to do without a heatsink. However, to dissipate this heat properly you should use a heatsink. We generally use a small one that is rated at 21°C / W. This means that thermal equilibrium is reached at a temperature of 21°C above ambient temperature for every Watt that is dissipated. For the 1.54W above, this means that the temperature of the regulator and heatsink would be 32°C above the ambient temperature. This is warm, but is acceptable and definitely within the relevant British Standards.

The problems come when a) the input voltage is a lot higher than 7.2V, or b) the Pi takes a lot more power than 0.7A. So you should:

  • Keep the input voltage down to something reasonable. We recommend 6 cells of rechargeable batteries as a maximum (ie. 7.2V nominal)
  • Note that the regulator needs some voltage “headroom” to work with. Some require a minimum input voltage of 2.5V above the output voltage (eg. 7805) so that means you have to put in more volts and thus generate more heat. (we use the L4940V5 which has a minimum input voltage of 6V)
  • Do not overload the 5V (or 3.3V) on the Pi with lots of directly powered addons
  • Use a heatsink if planning on using for extended periods (ie. more than a few minutes minutes at a time)

Finally, the power taken by the motors is irrelevant as far as the heat generated in the regulator goes. It will affect the driver chip of course, but that is a different issue entirely and not to be confused.

 

Adding Shroud to Extended Headers

step05

Why?

Extended headers on Raspberry Pi addon boards are a boon as they allow you to connect additional wires, or even another addon board in some situations. The problem is they tend to be relatively weak and can get bent over easily. Also, it is easy to plug things onto the extension shifted left or right by one or two positions – potentially causing catastrophic failures.

Simon Walters @cymplecy came up with the idea of adding a shroud around the extended header pins. This post shows you how to do it.

 

How?

Step 1

Take a Raspberry Pi. Any Pi

step01

 

Step 2

Plug on an Add-On board with extended headers. Here we are using the popular 4tronix PiDie 🙂

step02

 

Step 3

Take a standard male 26-pin male box header

step03

 

Step 4

Use a small pair of pliers to pull out all the pins. Pull them from the top upwards.

step04

 

Step 5

Push the plastic box header shroud onto the PiDie’s extended header pins. Make sure it is pushed all the way down

step05

 

Step 6

Now you can safely use the extended header pins. Here we plug on a PiGlow from Pimoroni as that uses different GPIO pins (I2C) than the PiDie

step06

 

Caveat: With the box header I used, it is still possible to put the PiGlow in one pin to the left or right. Maybe there are box headers with less space at either side. However, at least it protects the pins and makes it much more obvious that the extra board is connected wrongly.

Getting to Know Your MicRoCon

MicRoCon – Micro Robotics Controller for Raspberry Pi

Microcon3_01a

This is the baby sister to our full-featured PiRoCon controller board. It still features two bi-directional motor controllers, a 5V regulator for the Raspberry Pi as well as general purpose IO connectors, 5V servo outputs and a 4-pin Ultrasonic input.

Motors A & B

  • Motor A: Pins 24, 26 (GPIO: CE0 and CE1)
  • Motor B: Pins 19, 21 (GPIO: MOSI, MISO)
  • Permanently enabled
  • Use either pin for each motor with PWM
  • Remember to invert the PWM duty cycle when reversing
  • Motors are driven via an L293D H-Bridge chip from the input voltage at the 2-pin terminal (not from the regulated 5V supply)

 

 GPIO Connections

  • These are NOT level-shifted and only work with 3.3V devices. Do not connect a 5V input
  • Each GPIO pin has an asdsociated Ground and 3.3V pin so can connect 3-pin sensors directly
  • Pin 7 (GPIO: 04)
  • Pin 11 (GPIO: 17)
  • Pin 12 (GPIO: 18)
  • Pin 13 (GPIO: 27)

 

Servos

  • These 2 sets of 3 pins provide outputs to drive 5V servos
  • The signals are not level-shifted but all servos I have tried work happily with a 3.3V input signal
  • Servo 1: Pin 18 (GPIO 22)
  • Servo 2: Pin 22 (GPIO 25)

 

Ultrasonic Input

  • These four pins allow an HC-SR04 4-pin ultrasonic sensor to be connected directly
  • This uses a resistor network to allow the sensor to use only a single GPIO pin, which is shared between Ping/Trig and Echo
  • Output a pulse using the pin in output mode
  • Then switch to input mode to await the response
  • This is connected to Pin 8 (GPIO: Txd)

 

Regulator

  • This uses an L4040V5 linear low dropout regulator
  • The input voltage can go as low as 6V and the output will remain at 5V
  • The higher the input voltage, the hotter the regulator will get in use
  • The motors do not use the regulated voltage so will have no effect on the temperature of the regulator

 

I2C Female Header

  • Allows easy access to the I2C signals SCL and SDA
  • Also provides 0V, 3.3V and 5V connections
  • Same pinout as used on the PiRoCon expansion header so all expansion boards for the PiRoCon can also be fitted to the MicRoCon – ADC, 16-channel PWM available right now.
  • You can use the 4tronix IP Display dongle directly into this header.

 

Return to MicRoCon Home

Using the PiDie Raspberry Pi Addon Board

Overview

There are 9 LEDs arranged in a 3×3 matrix:

  • 1, 2, 3 down left side (Red, Yellow, Green – ideal for use as traffic lights)
  • 4 in centre (Green)
  • 5, 6, 7 down right side (Yellow, White, Blue)

These 7 LEDs then form the dots on a dice. The matrix is completed with LED8 (Red – top centre) and LED9 (White – bottom centre)

1  8  5
2  4  6
3  9  7

The Buttons are Red (top left), Green (bottom left), Yellow (top right), Blue (bottom right) and the colours match the colours of the LEDs in the same corners. Ideal for use in the Simon game,

 

Pin Connections

These refer to the physical pin numbers on the GPIO header. If using gpio module in python, then set the mode to “board”.

LEDs:

  • Led1: 7
  • Led2: 11
  • Led3: 12
  • Led4: 13
  • Led5: 15
  • Led6: 16
  • Led7: 18
  • Led8: 22
  • Led9: 8

Buttons:

  • Red: 21
  • Green: 19
  • Yellow: 24
  • Blue: 26

 

Use in ScratchGPIO

Download the excellent ScratchGPIO by Simon Walters from here.

  • Create a variable called “AddOn”. In the green flag black, set the variable to “PiDie”
  • The LEDs are named Led1 to Led9
  • To switch a LED on or off, you can send a broadcast message, or use variables.
  • Using broadcasts. Create a new message specifying what you want to happen. The syntax is “Led1On” or “Led1Off”. Change the number to select a different LED:
  • Using variables. You should create variables called Led1 to Led9. You can use the variable setting blocks to switch them on or off:
  • You can also set them all on or all off with a broadcast “AllOff” or “AllOn”

 

Use in Python

  • Import the GPIO library: import RPi.GPIO as GPIO
  • Set the GPIO mode to board: GPIO.setmode(GPIO.BOARD)
  • Set the LED pins as outputs: GPIO.setup(7, GPIO.OUT) // 7 is the for LED1. You need to do this for each LED, or use lists, etc
  • Set the Button pins as inputs: GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP) // 21 is the for the Red button. You need to do this for each button, or use lists, etc
  • Note that in the line above we are using the internal pullup resistors. This is mandatory for the buttons to work.
  • You can then set an LED On or Off by setting the output to 0 (ON) or 1 (OFF): GPIO.output(7, 0)
  • You can check if a button is pressed with an IF statement: if GPIO.input(21):

Soldering the 4tronix PiDie Kit

Click on any image to enlarge it

Check you have all the parts

pd00

  • Printed circuit board (PCB)
  • 1 x Diode (not shown above)
  • 4 x switches
  • 2 x resistor networks
  • 4 x capacitors 100nF
  • 12 x LEDs (2 x red, 2 x yellow, 2 x green, 2 x white, 1 x blue)
  • 1 x GPIO 26-waye female header
  • Mounting assembly (10mm hex spacer, 2 x M3 screws, 1mm washer)

Starting Soldering

If you haven’t soldered before, you might want to check out this instructable. I find that the following order of soldering works best, starting with the lowest profile components and moving to the highest. This allows me to place the components through the holes in the PCB, then turn the PCB over onto the desk surface and gravity will hold the components in place. You can also use Blutack to hold the components in place while you solder

 

1. Add the diode

The black diode has a white/grey stripe on one end. this MUST match the marking on the PCB as shown in the photo below in the position D1

pd01

 

2. Add the 100nF Capacitors C1, C2, C3, C4

These are small, yellow and marked 104. It doesn’t matter which way round they are put in, but it is neatest if they point the same way. They fit into positions marked C1, C2, C3 and C4

pd02

 

3. Add in the resistor networks RN1, RN2

These must be soldered in the correct way round. Double check before soldering. The writing needs to be closest to the GPIO header location, with the black dot (for pin 1) next to the end marked on the PCB with a small ‘1’

pd04 pd03

 

4. Solder the switches

These may already be clipped into position when you receive the kit, because that protects them during shipping. However, they will not be soldered so you need to do that for them to work. It doesn’t matter which way round they go – they can fit in 2 positions.

pd05

 

5. Add in the LEDs

The LEDs must fit in the correct way round or they will not work. The long legs on each diode must go into the hole next to the + mark on the PCB. All LEDs are oriented the same way – so if you get one right, then all should be right.

Step04 led01 pd06

 

6. Solder the GPIO Header

This must be placed on the opposite side of the board to all other components. It is extremely difficult to remove them if soldered incorrectly, so please double check before soldering

pd07

 

7. Add the Caps for the switches

These can go any way round, Just carefully push on so they click in place

pd08

 

8. Screw on the spacer

Fit an M3 screw through the hole in the board, then add the 1mm washer, then screw on the 10mm hex spacer. You can then push the board onto the Pi and the spacer will keep the board stable when the switches are pressed. You can screw it onto the Pi if you like, or simply let it rest. Please don’t use this spacer if using a Rev A Pi (without the mounting holes) as there are components in that place which can be damaged,