Outdated. Check out updated version revision 0.2! http://pi.gbaman.info/?p=97
I would like to start off by saying, I didn’t come up with all this myself, I have followed a few guides over the internet to make this and added a bit of my own stuff to it. The guide I used the most was
You will need
- A Raspberry Pi + SD card
- A Motor controller
- A Wifi dongle
- A battery for the Pi
- A 9v battery
- 2 motors
- Female to female jumper cables
- Male to male jumper cables
- Android phone – rooted
- Mobile tablet/Laptop for viewing video feed
- Mifi portable wifi transmitter
First you will need some sort of base robot to be building this all on, I will only cover the electronics and the software, not how to build your robot.
So here’s my base robot
It looks a little ugly, but was built to a deadline so I don’t really mind, it works.
So after you have got everything on shopping list, its time to start building!
My lego robot base is built from an old lego RCX box set so I decided to try and use some of the old 9v lego motors.
These motors required gearing to provide enough torque to move the robot forward so if using these motors, keep that in mind. I did come across another problem with these motors, they don’t easily connect to normal wires…
So I cut one of their cables and soldered it to 2 jumper cables and bam!
So now we have our motors, we need to hook our motor controller up to the raspberry pi. For this, I recommend you check out the diagram from Paul Geek Dads blog as it is the one I used.
This is Paul Geek Dads blog’s work, all rights to it belong to him
For my setup I found that a 9v battery would run out very quickly so I got x2 triple AA battery holders to produce that required 9v
So now we have our Raspberry Pi hooked up to our motor controller and our motor controller powered by a 9v battery or some AAs.
Check out the below pictures for pictures on where everything goes
Now time for the software behind it all. I am using Rasbian. At the time of writing, 2012-12-16-wheezy-raspbian. Rasbian comes with WiringPi which is needed for our scripts, if you don’t have it, try sudo apt-get wiringpi
For this section, that is all you need (for attaching a webcam, you will need a little more software but we will get onto that later)
Hook your pi up to a screen and with your wifi dongle plugged in, type startx and open the wifi config on the desktop. Connect to your home wifi. Now that this is done, it should automatically connect to the wifi even without a screen plugged in (seeing as the PiBot does not have a screen….Yet).
The Raspberry Pi
Next, on a windows computer, grab putty
Or if on Mac OS or Linux, open terminal and type
ssh pi@IP address
E.g. ssh email@example.com
Now we are connected, you will need to grab this python script and upload it onto the pi
Use sudo apt-get git
and git clone git://github.com/gbaman/Lego-PiBot.git
To grab the script for the pi. Now you have the scripts, it’s time to move on to the phone.
You will need a rooted android phone which can run sl4a http://code.google.com/p/android-scripting/
To grab it just scan the qr codes on the pages below.
This great piece of software allows you to install interpreters on your android rooted device (e.g. python interpreter).
Next find a way to get the script onto your phone (different for all phones).
Now you need to set the IP address of your Pi in the scripts. In the android script it is on line 12, UDP_IP =
And on the Pi script it is on line 25, UDP_IP =
Now all you have to do is tap the script and click the command-line button and run the Pi script (sudo python pi_script.py) to run it and move your phone around and your robot should move!
Live video! (Optional)
Wouldn’t it be even cooler if you could see what your robot sees as you drive it around? We you can!
I recommend following this guide below, it is very good and explains exactly how to do it.
After following the guide, open up the web page on a smartphone, maybe a tablet or a laptop etc and you can now watch your robot take over the world!
If it does not work there is a few things that could have gone wrong.
First test if your Pi is able to turn control the motors. Inside the Pi folder that you grabbed off github, there is a testing_motor1.py and testing_motor2.py. Try running these and see if the motors come on. If not, check the light is on on the motor controller, if not, check back to the pictures for wiring or maybe your board is broken?
If those scripts work then your phone isn’t able to talk to the Pi… Make sure the IP address is right (use ifconfig on the pi) and maybe try rebooting your Pi and phone just in case.
If it still isn’t working, leave a comment below and I may be able to help out.
Any question? Leave them below and I will try to answer them the best I can.