Notice: Undefined index: order_next_posts in /nas/content/live/gadgetmag/wp-content/plugins/smart-scroll-posts/smart-scroll-posts.php on line 194

Notice: Undefined index: post_link_target in /nas/content/live/gadgetmag/wp-content/plugins/smart-scroll-posts/smart-scroll-posts.php on line 195

Notice: Undefined index: posts_featured_size in /nas/content/live/gadgetmag/wp-content/plugins/smart-scroll-posts/smart-scroll-posts.php on line 196

Program Arduino on your Raspberry Pi

You can interface a Raspberry Pi with Arduino components – now learn how to program them from the Pi and control robots like the Makeblock

Program Arduino on your Raspberry Pi

Program Arduino on your Raspberry Pi

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.

Step 1

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

Step 2

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.

Step 4

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 Unzip it to a separate folder before continuing.

Step 5

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.

Step 6

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.

Step 7

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.