Firmata set up tutorial

Firmata is a protocol for communicating with the Arduino from software on a host computer. It has been implemented for Pd, Processing, Openframeworks (C++) and others. You basic only need to upload the firmware (ie a sketch) on the Arduino one time, and then can do all your programming in OF.

For Arduino beginners, here are some recommended references:

Introduction

Getting started

Arduino IDE

Follow the getting started guide to do the basic Arduino set up and testing before we continue our test.

Goal

In this tutorial, we are going to hook up a potentiometer (ie a variable resistor) to the Arduino, and use it to control the window size in Open Frameworks. If you successfully see the size of the pink window change when you turn the potentiometer (video at the bottom), that means that your set up is correct, and we are ready to move on to more complicated exercises.

Install OF with Arduino support

To be able to communicate with Arduino, you are going to need a different version of OF than the one you previously downloaded. Keeping your current version intact, download the following OF release, and unzipit to your machine.

mac users – find that here:
http://www.openframeworks.cc/files/00573-Xcode-Fat-WithPoco_Firmata.zip

pc – one sec…

Hook up the potentiometer

Potentiometer overview

A potentiometer is a variable resistor, there are many types and models, below is the one we use for this test. But for the most part, any potentiometer you have should behave in the same way and have 3 leads.

Potentiometer theory

The two outside leads of the potentiometer act as a fixed resistor. As you turn the knob, a movable third lead called the wiper moves across the resistor, producing a variable resistance between the middle lead and either of the two sides. This results in a variable value that can be read at the middle lead. In this case between 0 and 1024. In the picture below, the knob controls the wiper which is the thick black line turning clockwise and counterclockwise.

Connect the leads

The potentiometer has 3 leads (the 3 small hoops sticking out on top of the pot), that we will be connecting to Power, Signal and Ground lines. The first thing you will need to do is connect the leads. For this you can either solder some wires to the 3 leads, or use alligator clips (in picture below) and attach one side to the pot lead, and another side to the wire.

For soldering tips, you can check out this tutorial

Use colored wires for convention: black for ground, red for power and a third color (here yellow). The red and black wires will be on the leads on the edges, and the yellow one is the center lead. If you are looking straight at the potentiometer, with the knob facing you, and the 3 leads facing the bottom, you want to solder/connect the red wire to the rightmost lead, the yellow to the middle one, and the black to the leftmost one.

Connect the potentiometer to Arduino

Now that you have 3 wires connected to the potentiometer, you can conenct the potentiometer to the Arduino. If you look at the headers (ie the little holes on the edges of the board), you can see the pins are numbered, and sometimes labeled. In the section labeled ‘POWER’, insert the red wire into the pin labeled ‘5v’, and the black one into one of the two pins labeled ‘Gnd. The yellow wire will go into pin 1 in the section labeled ‘ANALOG IN’

Set up the Arduino

The latest arduino release is the 0012, if you havent yet, go to the arduino download page and download the software to your machine (for basic Arduino testing, you can check out the links above)

This version of the Arduino software contains firmata support.

The Arduino Diecimilia can be powered by an external power supply, or through USB. If you want to power it through USB, make sure the jumper (the small black plastic rectangle) that is next to the USB port is placed between the middle pin, and the one labeled ‘USB’. Otherwise, if you are using a wall wart, the jumper should be placed between the middle pin and the one labeled ‘EXT’. Either way, connect the Arduino to the computer using a USB cable.

Now start the Arduino IDE, and open the file ofStandardFirmata that was sent to you in the OF zip (look in the folder “other”).

mac: http://www.openframeworks.cc/files/00573-Xcode-Fat-WithPoco_Firmata.zip
pc : coming…

Under Tools, go to Board, and select the Arduino board you are using (here Diecimilia).

Upload the firmware to Arduino

Click the play button in the Arduino IDE to compile the code, and then click on the arrow pointing to the right (second to last button in the IDE) to send the code to Arduino.

Modify the Arduino Port in OF

Because every time you hoo up the arduino, the port assigned may be different, we need to modify the OF code to use the current port. In Arduino IDE, go to Tools/Serial port and note the serial port that appears in the list, typically it will look something like this: /dev/tty.usbserial-A40014xn (the last letters and numbers might be different).

Now open the testApp.cpp in openframeworks and replace the string in ‘ard.connect’ with the one you just wrote down.

Run the program

Now that the Arduino is set up, the hardware is hooked up and the Openframeworks app knows how to speak to the Arduino, you can compile the OF code and see the magic!

A pink window should appear and by turning the knob on the potentiometer, you should see the size of the window change. You will also see a stream of values being read from the potentiometer between 0 and 1024.

see the goofy video!

mvi_1389

Comments are closed.