Programming

Programming

This guide will demonstrate:

Before starting, make sure that your Raspberry Pi is configured and you have gone through the Getting Started Guide.

Program the Arduberry using Arduino IDE

To program the Arduberry using the Arduino IDE, do the following:

Step1: Open the Arduino IDE

arduino

 Step 2: Open the Example Arduino Sketch

Open an example or an Arduino sketch that you want to upload.

blink

 Step 3: Set the Programmer

Make sure that the programmer is set to Raspberry Pi GPIO and the board is set as Arduino Uno.

prog

board

Step 4: Upload

Click Upload. If Upload does not work use Upload using Programmer (Ctrl+Shift+U) to upload the sketch to the Arduberry

upload

Access the Serial Port using minicom

The default Serial port monitor that is installed with the configuration script is minicom. To use minicom follow the steps:

Step 1: (Default config)

Minicom is configured to a default baud rate of 9600.  To open minicom at 9600 baud, enter the following in terminal:

sudo minicom -b 9600 -D /dev/ttyAMA0

 

Starting Minicom with 9600 Baud

Arduberry and Raspberry Pi minicom at 9600
 

 Step 2: (Other baud rates)

If you want to use minicom in any other baud rate than 9600, open minicom in terminal with the following command:

sudo minicom -s

minicom_setup

Select the “Serial Port Setup“:

minicom_serial_setup

Press “A” to change the device to “ttyAMA0“, “E” to change the baud rate, “F” and “G” to change the flow control. Press Enter to go back to the main menu.

minicom_serial_setup 2

Select Exit to start minicom in the new configuration.

minicom_exit

Minicom running at 115200 baud

minicom_open

Access the Serial data from Python

To access the Serial data coming from Arduberry in Python, install pyserial.  Note: if you used our setup script to get started here, you have already installed pyserial.

sudo pip install pyserial

pyserial

Write a small program in python to access the Serial data

import serial
ser = serial.Serial('/dev/ttyAMA0', 115200)
while True:
         print ser.readline()

Save it and run it.

python serial

Adding a New Arduino Library

Download the new library in Raspberry Pi using the Netsurf browser.

Save the library to /usr/share/arduino/libraries/

lib_dwld

Open /usr/share/arduino/libraries/ in the File Manager.

Extract the library in the same directory.

extract

Now the new library can be used in the Arduino IDE

lib_imported

Have a question?  Post it on the forums!