Hardware Reference
In-Depth Information
Example Program
The beauty of Firmata is that it can adapt to so many situations. It is, of course,
up to you to choose which pins will be used. If you want to expose only some
pins, for example, to allow Firmata to control them, you can choose to enable
just those relevant to your project. The sketch might receive Firmata instructions
to update pins, but ultimately it is up to you, the developer, to decide if you
should allow these instructions on all pins. Maybe you do not want a Firmata
program to be able to modify certain pins. If a pressure sensor is connected to
two pins, you do not want Firmata to change the pins to output and potentially
damage the component.
The Arduino IDE has an excellent sketch that lets you begin working with
Firmata: the StandardFirmata program. To access this program, go to Files
Examples
StandardFirmata, and upload the sketch to your board.
However, uploading the sketch to your Arduino is only one-half the project;
you also need a Firmata program on your computer. Several programs exist,
and one is available on the Firmata website at http://www.firmata.org/wiki/
Main_Page#Firmata_Test_Program .
Download the version for your system (Windows, Mac OS, and Linux binaries
are available), and run the program. You need to know which serial port your
Arduino is connected to. After this is done, you are presented with the Firmata
screen, where the status of every pin is presented. This works by sending data
to the Arduino as quickly as possible; the faster the data transfer, the more
responsive the output will be. The Arduino also sends data to the computer,
using a clever sampling rate technique, which is described next.
Using this system, you can instruct your Arduino to perform advanced features
such as turning LEDs on and off without the need to write a sketch or reading
input lines without knowing in advance what will be connected (if anything).
However, this has its limitations. As explained previously, if you require a device
to be present on specii c pins, you might want to edit the Standard Firmata
sketch to not poll or update those pins. It is up to you, the programmer, to know
which pins you want to expose and to create or modify a sketch to make sure
that only the pins that are usable can be accessed by Firmata.
The Standard Firmata sketch is complicated and is one of the larger sketches
that you will see on an Arduino, but it is well structured and can be used as the
basis for your own sketches. By looking at setup() , you can see this:
Firmata
Firmata.setFirmwareVersion(FIRMATA_MAJOR_VERSION,
FIRMATA_MINOR_VERSION);
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback);
Firmata.attach(REPORT_ANALOG, reportAnalogCallback);
Firmata.attach(REPORT_DIGITAL, reportDigitalCallback);
 
Search WWH ::




Custom Search