Robots > PiBot
Click on the links below to jump to the various sections of this design….
- Brief & Inspiration
- Time & Money
- Set up the Pi
- Flashing LEDs
- Flashing LEDs from a web page
- It Speaks!
- LCD Screen and Buttons
- Further Reading
Robots… I love Robots!
I’ve been looking at various robots for years and now happen to have a spare Pi lying around. I want to spend as little as possible which is handy as I already have a Pi and a wireless dongle. This should cover me for the brain of the robot and I can publish a webpage to a webserver running on the Pi which allows me control over the GPIO pins (General Purpose Input Output).
I am going to document the working code as and when I get some! If you see a “Code So Far…” link then click to expand this and see working version of the code so far, you may want to ignore this and figure it out for yourself! If you do use my code please check it first, I do not guarantee that it will not break your Pi, sleep with your wife, burn your house down or anything else!
Brief & Inspiration
After doing some research I’ve found a pile of useful websites… I’ll try and link to each tutorial as I go so you can see my research!
Money is going to be out on this project as I already had a Raspberry Pi B and power supply (~£35) and a WiFi adaptor (~£8) left over from a previous project.So if you are staarting from scratch, research prices for those on top!
Time & Money
|Time to Design||100 hrs||5 hrs|
|Time to Build
(Including sourcing/scrounging materials!)
|100 hrs||4 hrs|
|Cost to Build||£100||£0|
I’ve been following various tutorials and installing various things! So far I have Raspian on an SD card, I’ve enabled and tested VNC and SSH and installed a wireless card.
Next steps will be to install Apache and confirm I have a webpage being served up from the Pi, then check I can use in the GPIO for input output.
Install Apache / PHP
At this point you should now have only one cable connected to your Pi (5v Power) and you should be able to browse to your Pi’s IP address and see the default Apache webpage.
Get an LED to blink… now there are lots of tutorials on this but the following ones I found well done and without someone insanely annoying doing the video!
[Edit: for future reference I linked the GPIOs out through the various LEDs and then back to Ground…. I’ve taken it apart once and had to look it up again.]
The ModMyPi series of videos: https://www.youtube.com/watch?v=OR5h0UnMcUE
The AdaFruit tutorials, although I couldn’t find a basic ‘Flash an LED’ tutorial they are worth going through: https://learn.adafruit.com/category/learn-raspberry-pi
This is a nice one as well: http://roverpi.blogspot.co.uk/2013/06/getting-leds-to-light-up-with-raspberry.html
Here’s my three LED code I ended up creating and how to run it…
You should now be able to connect wirelessly to your Pi by VNC and/or SSH and run your LED script to flash some LEDs. The next challenge is to get a button on a webpage to run that script!
Flashing LEDs from a webpage[Edit: for future reference its on port 8000!!]
This is my first attempt for the web page… but I’ve done websites for a while so this was fairly straight forward for me. I’ll get some downloads sorted so you can download my version of the code…
As an aside this is fairly helpful…
Make a shortcut to my windows share from my pi
Code So Far... (Click for disclaimer and link!)
The next plan is to make it speak, as this is free pretty much! At this point the robot isn’t moving so I could just plug the 3.5mm jack output of the pi into a spare input on the stereo.
I followed the steps in this tutorial…
…and basically didn’t bother with a button! First thing is to check you can play an MP3 by running a python script and then run the same code from a button press on the WebIOPI page we created earlier. I’ll post code examples later 🙂
Yes! My Robot is going to have the voice of Ash from Army of Darkness!
Some of the audio samples are a bit raw but you can clean them up and sort out the levels using Audacity – http://web.audacityteam.org/
Code So Far... (Click for disclaimer and link!)
A note on terminal controls
I realised that I write a lot of code by through an SSH putty Connection and that I have been teaching myself terminal commands but not shared them or written them down… so here are the basics. I’m used to a Windows environment and there is a fair amount of crossover…
CD – change directory!
To change the current working directory from ~/pi/ to ~/pi/pythoncode would be “
To change the current working directory from ~/pi/pythoncode to ~/pi/ would be “
CD ..“, two dots is essentially “up one level”
MKDIR – Make Directory
To make a directory called “bingo” in the current working directory you would type “
CP – Copy
To copy a folder contents to another folder, ~/pi/script-live to ~/pi/script6-audio, I would type “
CP ~/pi/script-live ~/pi/script6-audio -r“, you need the -r to make it recursive copy otherwise it would only copy files that you specify and not folders!
The reason that I work like this is that I can type and view code on my laptop rather than through a VNC connection to my Pi and I can still copy and paste into Putty. Prior to each major code change I take a copy of the working directory and save it a level higher with an appropriate name!
Basically my folder stucture is like this
Any files in the Project-Live folder are the ones referenced by WebIOPI and are the “live” scripts.
This way if I make a major stuff up I can just copy the contents of the highest numbered project folder over the contents of the Project-Live folder and I am working again (basic versioning)!
Backing up the scripts
Browse to the folder containing all of the project folders, right-click on the folders and select Open in Terminal.
sudo cp * /mnt/PiData -r
…PiData is the name of my SMB share from my Windows server (it could be a desktop or laptop though) that I have mapped following one of the links earlier. Be careful this will copy the contents of your current working folder to a mounted folder called PiData! The “-r” switch makes it including sub-folders and contents.
I need to reread all of my motors links!
…but the first step is using the servos that I have!
Hmmm struggling to get that working so I’m going to follow a tutorial first to check everything works.
OK, so also struggling to install WiringPi! This is what I get:
$ sudo apt-get install wiringpi
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package wiringpi is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'wiringpi' has no installation candidate
OK… so update things first!
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
That kind-of worked and I now have a servo motor that randomly twitches!
I wanted to add an LCD screen so I can get some feedback from the robot without having to add a screen, keyboard and mouse.
I actually got a knock-off one from AliExpress but this is basically it. My plan is to have the screen display the IP address in case I can’t get to it! This actually comes with a lot more than I though so maybe I can change the background colour to indicate a status (Green = good, red = fubar…).
Mine came ready assembled which is good as I suck at soldering…. so straight onto the coding:
Trying to stick true to my doing it on the cheap idea I have ripped apart a CD drive and a couple of printers to scavenge a variety of Motors, Switches, Cogs, Springs, Belts and Cables!
So far I’ve connected everything up, now for the code and batteries.
The idea is to eventually have it tracked! I could custom make a chassis and tracks but they’ve dropped in price and it looks like I can get a cheap one about the right size for ~£15.