Hap-Pi and ScratchGPIO5 and the Raspberry Pi camera module
I backed the Hap-Pi robot kit on Kickstarter and my little robot arrived with few instructions. There were very good guides about how to put together the cardboard case and motors, and on how to solder the motor-control add-on board and these are available at the ever-expanding pi-school.com website. After my 8 and 10-year-old daughters had completed the assembly of our Hap-Pi and we had installed our Raspberry Pi on it, complete with rechargeable battery, we needed a way to control it. I had a dig around and discovered that Simon Walters had made his brilliant ScratchGPIO5 add-on for Scratch v1.4 compatible with the Hap-Pi. All that was needed was to make a Scratch sketch to control our little robot. With Wi-Fi and a battery for the motors and the Raspberry Pi itself, we were able to wander around following the Hap-Pi using the laptop like a remote-control unit. Then we wanted to go one better. What if we could put the Raspberry Pi camera module on the front of the Hap-Pi and stream video from it? That way we had a remote-control robot that we could control from the safety of an armchair. So we did, and this is how…
How to install ScratchGPIO5 on your Pi
ScratchGPIO5 is available here:
Do this part with your Raspberry Pi plugged into your monitor and with a keyboard and mouse plugged into its USB ports. We can look at getting remote access from a PC or laptop later. However, you do need to have the Raspberry Pi connected to the Internet.
Double-click “LXTerminal” and then type the following into the window that opens:
Wait for that to finish, it will output some info looking something like this:
The “isgh5.sh saved” bit is the part that tells you it worked ok. Next type:
A lot of information should fly past the screen. Don’t worry about reading it all, but hopefully the last bit should look like this:
Now you are ready to roll. You should have a few new icons on your desktop that look like this:
If not, give your Pi a quick restart (reboot) and when it all comes back, they should be there. You want to run the one called “ScratchGPIO 5plus” by double-clicking on that icon.
Program the arrow keys to run Hap-Pi from ScratchGPIO:
I was going to write a few paragraphs to show how to do this, but Stewart Dunn, the Hap-Pi designer beat me to it and produced a nice easy to understand video on YouTube, just here:
Also, since beginning on this document, pi-school.com has published a guide to using ScratchGPIO with the Hap-Pi: http://www.pi-school.com/index_htm_files/HapPi_Robot%20ScratchGPIO.pdf
Accessing the Raspberry Pi remotely
In order to run the Hap-Pi robot properly you’ll want to do a few things. Firstly you’ll need to use Wi-Fi to connect the Pi to your network and then you’ll want to run the Raspberry Pi from a battery and access it by connecting to the LX Desktop on the Pi by using some remote desktop software on your PC or laptop.
Connecting a Wi-Fi dongle and using that to connect to your Wi-Fi router has been covered a million times on the Internet. Use your favourite search site to find a guide, or try this one:
Now you want to connect to your Pi using a desktop sharing system called VNC. I followed the guide at raspberrypi.org here: http://www.raspberrypi.org/documentation/remote-access/vnc/
Open up “LXTerminal” again and the type:
Then run TightVNC Server to set the password that you’ll need to type in when you want to connect to your Pi from you laptop using a VNC client. This doesn’t have to be the same as the “pi” user’s password, but it’s probably best for your sanity to set it the same. If you haven’t changed your “pi” user password since you created your SD card, then the default password is “raspberry”:
The screenshot below is hopefully clear enough. I type “raspberry” as the password and said no to a view-only password. You now have a desktop available to connect to over the network from your laptop, but you (probably) don’t have any software on your laptop to connect with.
Install VNC viewer on your laptop
I like to use “Ultra VNC viewer” on my laptop, but there are many available, so shop around. UltraVNC for Windows is a free download from here: http://www.uvnc.com/downloads/ultravnc.html
At the time of writing, the latest version was 220.127.116.11. Download the file and you should have a file called something like “UltraVNC_1_2_01_X86_Setup.exe” in the Downloads folder on your PC. Go ahead and run this file and go through the setup but when you get to this screen:
Just choose to install the viewer part of the software by making sure only the “UltraVNC viewer” box is ticked (untick the others). When you’ve finished clicking on the “next” buttons and the “finish” button go ahead and find “UltraVNC Viewer” in your Start menu and run it. You’ll see this:
Type in the IP address or hostname of your Raspberry Pi in the box, followed by “:1” (e.g. 192.168.1.123:1) and click connect. You will then be prompted to enter a password (leave any username box empty). I chose “raspberry” as my password earlier, so that’s what I type. You should hopefully now see the by now familiar Raspberry Pi desktop and you can get on and run Scratch to program and have fun with your Hap-Pi.
To make the VNC desktop run when you switch on your Pi, one of the many ways to do it is to add the following to the “/etc/rc.local” file. The following line needs to go in the file BEFORE the line “exit 0”:
Adding the camera module and streaming a picture from it
Follow the directions from raspberrypi.org on installing the camera module. http://www.raspberrypi.org/help/camera-module-setup/
Getting streaming working is a tricky affair and involves compiling the raspimjpeg (https://github.com/silvanmelchior/RPi_Cam_Web_Interface) software, but if you follow these steps carefully, you should be OK (provided my steps are correct!).
These instructions are based upon the instructions found on the raspberrypi.org message boards here : http://www.raspberrypi.org/forums/viewtopic.php?t=63276
Before you do the next part, be aware that it overwrites the /etc/rc.local file that we just edited. You should take a backup of it first, or redo adding the VNC line (and any of your own changes you have made to it) to /etc/rc.local afterwards.
This installs a tonne of stuff on your Pi, including the Apache web server. Reboot your Pi, then surf to it using your web browser, and you should see a live picture from your Pi camera module. Wave!
Now the way I started using this was I ran the browser and the VNC session together with the VNC session in the foreground so I could control the Hap-Pi movements and had the stream from the camera visible next to it but in the background.
This is fine for fun, but we are now working on a web interface which runs entirely from the Pi, with no need to use Scratch. It uses Python to control the robot. Watch this space for a write-up (when it’s finished!).