Raspberry Pi is a $35 palm-sized Linux-ready embedded computer. Attach a keyboard, mouse, load an operating system on an SD card, attach a monitor, and you have a top of the line computer circa 2002. We're interested in Raspberry Pi because:
- It's a computer, so you should be able to hook it up to a Hummingbird or Finch and write code to control them.
- It's a computer, so you can make it wirelessly connect to other computers and the internet.
- It's a computer, and it's small enough to fit on a Finch or under/on top of a Hummingbird.
- It's a computer, and it's $35!
At the moment, you can write code to control the Finch Robot in C, Java, Python, and Snap! (on a host computer).
The Raspberry Pi isn't exactly plug and play; it requires a fair amount of work to setup, and getting it to work with the Finch requires some extra components, in total these will set you back about $100.
Table of Contents
- Powering, Connecting, and Attaching a Raspberry Pi to the Finch
- Installing an Operating System on the Raspberry Pi
- Software for Remotely Connecting to the Raspberry Pi
- Install and Configure Java
- Initial Configuration for Finch
- Compiling and Running Finch Java Programs
- Compiling and Running Finch C Programs
- Compiling and Running Finch Python Programs
- Compiling and Running Finch Snap! Programs
Powering, Connecting, and Attaching a Raspberry Pi to the Finch
Before you start, you'll need the following:
- A Raspberry Pi Model B
- A 4 GB or greater SD card. Some cards may not work, see this page for a selection of tested cards.
- A power source for the Raspberry Pi. We used the Powergen PGMPP8400. It is no longer available but search for a battery with similar characteristics, specifically ensure that your battery has two USB ports and at least one can output 2A.
- A USB wireless adapter. We use the Airlink101 AWL5088.
- A Finch.
- A Powered USB Hub. We use the Plugable 4-Port hub. Depending on your USB Hub, you may need an adapter that adapts a standard male USB connector (connected to the battery) to the DC 5V in for the powered Hub.
- If using our mounting solution, 3D print or buy our Finch/Raspberry Pi mounting plate. The STL file is available for anyone to print.
- If using our mounting solution, a stretchy velcro strap.
- Velcro with sticky backing or double-sided foam tape is recommended.
- A one or three foot USB A to B cable might be easier to use than the Finch's standard 15 foot USB cable.
Connecting the Raspberry Pi to the Finch is not as simple as it may seem. Due to the fact that the Raspberry Pi's USB ports are unable to power the Finch through a power surge (such as those caused by the robot's motors starting), we need to separate power for the Finch from USB communications with the Finch, hence the need for a USB hub. The following tutorial walks you through connecting the robot to the Pi through a powered hub.
Configure the Powergen battery by connecting the 0.6A output to the micro-USB connector (for powering the Raspberry Pi) and the 2A output to the yellow tipped barrel connector (EIAJ-02 standard).
Place the battery in the Finch/Raspberry Pi mounting shell such that the power switch and USB connector are accessible through the large rectangular hole on the right side of the mounting shell. We recommend affixing the battery to the flat underside of the shell with foam tape or sticky-backed velcro.
Thread the mounting strap through the two smaller rectangular slots on either side of the shell, then place the USB Hub on top of the battery, affixing it with tape or velcro. Connect the yellow-tipped barrel connector from the battery to the USB Hub's power input. Connect the Mini-B USB cable that came with the USB Hub to the Mini-B USB port on the Hub. Connect the Finch's USB Cable to one of the four ports on the USB Hub.
At this point, three cables are unconnected:
- The USB B cable goes to the Finch
- The USB A cable goes to one of the Raspberry Pi's two USB ports.
- The USB Micro-B cable go to the power input for the Raspberry Pi.
Connect the USB B cable to the Finch and place the entire mounting shell on the Finch's back. Ensure that the two Raspberry Pi cables are routed through the small rectangular slot in the back of the shell. Use the velcro strap to mount the shell securely to the Finch.
Now place the Raspberry Pi on top and affix it via the mounting holes, tape, or velcro. Connect the remaining two connectors to the Raspberry Pi and you now have a fully functional, Pi-powered robot!
Alternative Mounting Method
There are other ways of mounting all of the hardware to the Finch. The following method uses a bent piece of fence wire (credit: Tom Simpson):
Installing an Operating System on the Raspberry Pi
There are numerous ways to install an operating system on the Raspberry Pi; you can even buy an SD card preloaded with an OS. See this page for an exhaustive listing of guides to install an OS. Our favorite installation method uses the Berryboot installer. To install via Berryboot, follow these steps:
- Before you begin, make sure you have an internet connection that the Raspberry Pi can access (Access to a wireless signal + a USB wireless adapter, or a router and an ethernet cable).
- Connect your SD card to a host computer; you may need a USB SD card reader.
- Download the zip file from the berryboot page, and extract its contents onto your SD card.
- Plug the SD card into your Raspberry Pi, plug in a keyboard, mouse, monitor, USB wireless or ethernet cable (if ethernet is available, it is less likely to cause problems than wireless). Note that you will only need the monitor, keyboard, and mouse for initial setup.
- Power up your Raspberry Pi and watch it boot!
- Select your SD card as the destination drive. Typically it will be the first option and will have a prefix of "mm".
- For Install operating system, choose the Debian Wheezy Raspbian option - the "offical" rPi Raspbian version.
- Twiddle your thumbs for a while as it downloads and installs.
- When it has installed, reboot the Raspberry Pi.
- The first time Raspbian boots, it will allow you to set some configuration options. We leave the defaults alone, but ensure that the ssh server is enabled as we typically run the Raspberry Pi via a remote terminal.
- Login with username "pi" and password "raspberry"
- Upgrade all the packages in the OS by typing "sudo apt-get update" and then "sudo apt-get upgrade". These commands may take 10 minutes to an hour or so to complete, and are optional but recommended (you may also do them at a later time, or try them if things aren't working).
Software for Remotely Connecting to the Raspberry Pi
Most people wish to run Raspberry Pi's through a remote connection, dispensing with the need for a monitor, keyboard, and mouse, and making the Pi much more portable. In order to run the Raspberry Pi remotely, you will want:
- Software to determine the IP address remotely or admin access to a router to view the attached devices list
- An SSH client program so that you can run programs on the Raspberry Pi
- A file copy program so you can get software from the host
- Possibly a remote desktop so that you display and manipulate the Raspberry Pi's desktop without a monitor.
Software to determine IP Address
We have used Advanced IP Scanner on Windows and Angry IP Scanner on Mac and Linux. They work reasonably well, though you may need to work out the IP address from the Mac address of your USB wireless module or from the ethernet port. Note that you may also simply be able to log into your router and view the attached devices list.
Once you know the IP address, you can log into your Raspberry Pi using ssh client software. Our favorite is Putty in Windows; in Mac and Linux you can simply type "ssh username@host" in any terminal window; for example, "ssh email@example.com".
File Copy Software
To install Java or the BirdBrain Technologies software, it is easier to download the software to a host computer and then copy it over to the Raspberry Pi using file copy software. Our favorite is WinSCP in Windows, Cyberduck or Fugu on Mac. On Linux and Mac you can also use "scp username@host" from a terminal.
Remote Desktop Software
If you want to view the Raspberry Pi's desktop from your host computer, you can use TightVNC. To get it, first ssh into your Raspberry Pi and issue the following command to install the program:
"sudo apt-get install tightvncserver"
Then whenever you wish to allow remote desktops, type
The first time you run it, it will request you set up a password and other configuration options. Every time you run it you will see a message like:
Installing and Configuring Java
Newer versions of Raspbian come with Java pre-installed. You can check by typing "java -version", if you get a response showing the Java version installed, you can skip this step.
If you plan to compile and run Java programs or the Snap server, you'll need to install it first. If you're using C or Python you win! Skip directly to initial configuration for Finch (C and Python compilers are installed by default).
Follow these steps to install Java:
- Do a system wide update with sudo apt-get update
- Install Java with sudo apt-get install oracle-java7-jdk
If that doesn't work, try the following instructions:
- Download Oracle's Java JDK 8 for ARM to a host computer
- Using a file copy program, Copy the file over to your Raspberry Pi's default home/pi directory. (click for screenshot).
- Extract the files in the tarball with the following command - you may need to change the jdk name to the version you've downloaded:
- Move the JDK from your home directory to the /opt/ directory and delete the tarball to conserve space:
- Update the Java alternatives configuration:
- Edit the file ~/.bashrc by typing "nano ~./bashrc" and place the following text at the end of the file:
- Type java -version and make sure your output matches the following, if you get an error, restart your Raspberry Pi and try again after restart:
Initial Configuration for Finch
- On your host computer, download and unzip the BirdBrain Technologies Software for the Raspberry Pi.
- Copy the folder BBTechSoftwareForPi to your Raspberry Pi's home directory (see screenshot for detail).
- Using a terminal, change directory to ~/BBTechSoftwareForPi
- Make the Configure script executable and then run it with sudo ("chmod +x Configure" followed by "sudo ./Configure"). You should see the following output:
To compile a Java program for Finch, first navigate to the FinchJava directory, and then type javac -classpath :finch.jar FILEPATH
For example, if you wish to compile FinchOrientations.java, which is located in Code/looping, you would use:
To run a Java program for Finch, type java -classpath finch.jar: FILEPATH
For example, if you wish to run FinchOrientations, you would use:
To compile a C program for Finch:
- Navigate to the FinchC directory
- Compile a program with "gcc -pthread -o programName programName.c Finch.c -lhidapi32"
- Run the program with "./programName"
- The following shows the commands to compile and run the included main.c sample program, and the resulting output:
You can find documentation of the Finch C library's API here.
Compiling and Running Python Programs for Finch
First, navigate to the FinchPython directory.
You can run python programs for the Finch in two ways: You can compile and run a stand-alone python file, or you can run python in interpretative mode.
To run a standalone file, simply type "python nameofstandalonefile.py". The following shows sample output from running testfinchfunctions.py, one of the five included sample programs.
Alternatively, you can run Python in interpretative mode and issue commands to the Finch. To do so, simply type "python", and then in the resulting Python prompt, type "from finch import Finch". Create a Finch object to read sensors and set outputs by typing "finchObjectName = Finch()". See the following output for an example:
A bug exists in a previous Finch Python implementation: If you are using software downloaded before 3/19/2014 and you plug in your Finch after booting up the Raspberry Pi, the first time you attempt to run a Finch Python program it might hang. You can kill the program with CTRL-Z, after which you should be able to run it or any other Finch Python program. So either plug your Finch in before powering up the Raspberry Pi, or run the program twice, killing it with CTRL-Z if it hangs the first time.
If you need to discover the names of functions for getting sensor values or setting outputs, type "help(Finch)". You can also refer to our documentation of the Finch Python library.
Compiling and Running Finch Snap! Programs
We have created a server that allows you to control the Finch with the Snap! programming environment from a remote computer. Snap! is an in-browser visual programming environment based on Scratch.
To use the Finch Server, you must first install Java on your Raspberry Pi.
Unlike our other software distributions, in this case you will be creating programs on a host computer. You will start a server program on the Raspberry Pi that will expose the Finch's outputs and sensors over HTTP. On a computer on the same local network, you can then create programs in Snap! using our specialized blocks library.
We attempted to use Snap! directly on the Raspberry Pi but modern browsers like Chrome are simply too slow for the program to be usable.
Step 1: Start the server on the Raspberry Pi. Navigate to the FinchServer directory in BBTechSoftwareforPi folder and type "java -jar FinchServer.jar. Assuming a Finch is plugged in, you should see the following:
Step 2: Navigate to http://snap.berkeley.edu/snapsource/snap.html on a computer connected to the same local network as the Raspberry Pi.
Step 3: Import the FinchPiSnapBlocks.xml file by dragging it from a file browser onto the Snap! webpage, or by clicking the file icon and selecting Import...
Step 4: Change the IP Address variable to the IP Address of the Raspberry Pi using the provided "set" block:
Note that the when you launched the server in step 1, the server IP address was printed in the terminal.
You are now ready to program the Finch with Snap!. See the following tutorial if you are unfamiliar with Snap!.