These instructions try to assume very little. Hopefully, if you can boot a Raspberry Pi and have an internet connection you should be able to complete this great little project.
Basically, this is a project which will result in some specific areas which can be used in other projects.
The main outcomes will be:
Using a PS3 controller
Controlling DC motors
But along the way, youāll get a chance to look at some code and perform some often used linux commands in the terminal
Step 1: What you need
Itās a bit of a list ā but nothing is terribly expensive. Iāve also tried to keep the list to commonly used components that will be useful on any related project.
For example, this project could be adapted to control a garage door or to trigger some other project by incorporating a motion detector and/or camera.
So hereās the list:
- Raspberry Pi & SD Card with Raspbian installed
- DC Motors (pictured are 2 different types ā one set is geared)
- L293D motor driver pcb (ChrisMason has described how to breadboard this chip if you donāt want to buy the pcb)
- Powered USB hub
- 9V battery & holder
- 5V power source
- PS3 Controller
- All the necessary cables/power supplies for the above
- Youāll also need to download the *.sh files (attached) to your /home/pi directory.
Step 2: Wiring the motors
When I began doing bits and pieces with Arduino and Raspberry Pi, I didnāt get why motors couldnāt be connected directly to them. Hereās the quick explanationā¦..
If you look at the specifications of a motor youāll get information about itās RPM, ampage, ratio etc. Also included will be a voltage span within which it can operate. For the majority of motors used by hobbyists and makers, this voltage span is likely to be 6V or greater.
For the motors Iām using in this project, Iāll be using a 9V battery. Now, a 9V battery is too much to run the Raspberry Pi from. Also, hooking up the motors directly to the RPi means that the greedy little things will try to draw more current than the RPi (or indeed an Arduino) can provide.
This can result in damaging your hardware.
You can wire the motors, battery holder and wires to the L293D pcb as shown. The 9V battery will independently power the motors. The motors themselves are attached to terminals marked āMAā and āMBā on the board I have.
The other 3 pins (per side) are inputs 1 & 2 and an enabling terminal also. The enabling terminal could be regarded as a kind of handbrake, you have to enable the motor on the channel in order to drive it. The other 2 pins are switch controls which determine the direction the motor will spin.
Step 3: Connecting the motor driver pcb to the RPi
Apparently you shouldnāt connect anything to the GPIO pins while the RPi is running so itās worth making sure to heed this advice or it could be expensive.
You can connect the wiring to the RPi as shown in the image.
Donāt put the 9V battery in just yet. Iāve found that if the battery is left in, it will slowly drain. Given that setting up the RPi for this could take some time, weāll just leave it out until weāre ready for testing.
Another solution to this is that you can add a simple switch to the battery holder.
Step 4: Getting the PS3 controller running on the Raspberry Pi
We now have the connections all made and so can move on to setting up the PS3 controller.
There are a good few tutorials on how to do this. The one I initially used is available here:
https://github.com/petrockblog/RetroPie-Setup/wikiā¦
For anyone who is a beginner at using the command line in linux going through all the commands and encountering some problems can be really frustrating. To help with that, Iāve started off with a completely clean install of Raspbian so that I can hopefully identify every issue you might encounter.
The first thing you need to do is install some background programs and libraries. These are known as ādependenciesā.
For more detail:Ā Remote Raspberry Pi Robot (PS3 Controller) ā Fablab NerveCentre