Learning to code is one of the best things about owning a Raspberry Pi for a lot of people. Python and C are easy enough to start with on the Pi and you can get great results in a short time. When it comes to physical computing and making, though, not much beats using the Arduino IDE to control the open source controllers, servos and sensors associated with the system. Once set up, we can also use the Pi to program the Makeblock robot we reviewed in issue 142 of Linux User & Developer, using either the built-in commands or your own code.
01 Update your Pi
Always make sure your Raspberry Pi is up to date. This tutorial is based around Raspbian so set up an SD card if you don’t have one, and then do an update with sudo apt-get update && sudo apt-get upgrade. Make sure the firmware is up to date as well with a sudo rpi-update.
02 Install Arduino IDE
Next you’ll need to install Arduino to the Raspberry Pi – luckily it’s in the repos for Raspbian so all you’ll need to is open a terminal and type:
$ sudo apt-get install arduino
03 Install Arduino libraries
To get everything working on your Pi you’ll also need to get the relevant libraries as well. These will allow you to connect to various Arduino boards, especially the Makeblock kit. Do this with:
$ sudo apt-get install avr-libc libftdi1 avrdude openjdk-6-jre librxtx-java
04 Using Arduino
Now everything is ready you can open up the Ardunio IDE. It can be found in the new Electronics section of the programs menu. It will create a new sketchbook folder in the home menu where all your projects will live.
05 Makeblock starter kit libraries
To program the Makeblock, it’s best to grab the example code so you can get an idea of how it works. The zip for these can be downloaded from https://github.com/Makeblock-official/Makeblock-Library/archive/master.zip. Unzip it to a separate folder before continuing.
06 Install Makeblock examples
Turn off the Arduino IDE, if you haven’t already, and find the ‘sketchbook’ folder in the home directory. Create a new folder inside called libraries and copy and paste the ‘makeblock’ folder from the unzipped files into this new directory to effectively install it to Arduino.
07 Prepare your robot
Once you’ve built your Makeblock robot, unplug the battery and plug the control board into the Raspberry Pi via a micro USB cable. Restart the Arduino IDE and go to Tools, Board and select Arduino Leonardo. Also check to make sure the right Serial Port is selected.
08 Program your robot
Now you can load an example code to make sure everything is working. Click on File, Examples and find the ‘makeblock’ menu. Go to the Starter Kit option and select IR Control example. Upload it to the Makeblock, unplug it from the Pi and give it a go with the remote control.
09 More programming
Now you can modify the example codes to change the functionality of the Makeblock. This will allow you to understand how the robot, and other Ardunio devices, are programmed so that you can start writing your own custom code for it.