- Raspberry Pi 3
- Motor controller board
- 2 × 12V DC motors
- 2 × wheels
- 1 × AA battery holder (for 4 AA batteries)
- 4 × AA batteries
- Ball caster
- Wire or jumper leads
- A USB Battery pack
- Screw driver
- Soldering iron and solder
- Wire strippers
- Small cardboard or plastic box and glue/tape
- VL53L0X time-of-flight range finder or ultrasonic distance sensor
- 2 × line following sensors
- 18650 battery, battery clip, USB charge/discharge board (or USB power bank)
Set up the trash-box. Mark the holes for tires.
Connecting the Rasp with batteri and tire.
Connecting the board to your Raspberry Pi
The board used in this project needs to be wired to the Raspberry Pi. Other boards may connect differently, and some boards can simply be placed onto the Raspberry Pi GPIO pins as a HAT. Make sure you look at the documentation for your board to see whether this is the case.
On the board used here there are pins labeled In1, In2, In3, and In4, as well as two GND pins. Which GPIO pins on your Pi that you use is up to you; in this project, GPIO 7, 8, 9, and 10 have been used.
|GPIO pin||connects to||board pin|
Rasp PI 2 B+ – GPIO schema
Simple python script:
from gpiozero import Robot
robby = Robot(left = (7, 8), right = (9, 10))
Save your file and call it robby.py or similar. You can then run it by pressing F5 on your keyboard.
Now switch over to the shell and type the following to observe which way the motors turn.
If the right motor spins, you’re good; if not you’ll need to swap them round by swapping the pin numbers in your original script:
robby = Robot(left = (9, 10), right = (7, 8))
Next check your motors are both turning the right direction:
robby = Robot(left = (9, 10), right = (8, 7))
Now we’re ready to put the bot together – there’s many ways to construct a chassis, from 3D printing to laser cutting, but first it’s best to use a cardboard box to get the hang of the layout. Experts recommend a chocolate box because the card is nice and rigid, but the choices are endless!
The chassis needs to contain the Raspberry Pi, motor controller and batteries, and needs to allow a pair of wheels to be mounted. Cardboard also allows you to experiment with fitting sensors later on, such as a couple of line sensors, and an ultrasonic distance sensor or a lidar sensor.
You’ll essentially end up with a motor on each side at one end of the box, attached to an external wheel, and the ball caster at the front. Locate your USB power bank in the box, along with the Pi, controller board and motor battery pack.
You should now be able to boot your Pi (from the USB pack) and begin to program it.
There are five basic commands to move your robot, that can be combined to make it move in different ways:
For example, here’s a simple script to make it go in a square shape (although you may need to tweak the sleep functions to get the motions correct).
from gpiozero import Robot
robot = Robot(left = (7, 8), right = (9, 10))
Thanks to the Raspberry Pi foundation for the official Robot buggy project.