Hardware Reference
In-Depth Information
Introducing Firmata
Arduinos are used in a wide variety of projects, from the most simple to some
extremely complex devices. In most cases, their exact use is known; you know
beforehand that digital pin 3 will be used to light an LED, and that analog input 4
will read the value of a light sensor. For some projects, you may not know what
is connected, but you will still need to set pins as input or output, depending
on the situation. Imagine a laboratory setup, one where you can study how new
components work before deciding to use them in your projects. You could write
a quick sketch each time to see how a component works, but this isn't always
the best solution and certainly not the easiest. One way to easily set up your
laboratory is to use Firmata.
Firmata is a protocol that communicates between computers and microcon-
trollers to easily access the Arduino hardware from software on a host machine.
It uses standard serial commands and as such can be used on several different
Arduino models. Messages are sent serially to and from the host computer,
indicating pin status or requesting a pin to change state.
Firmata Library
To use the Firmata library, you must i rst import it. You can import the Firmata
library from the Arduino IDE automatically, by going to the Sketch
Import
Library
Firmata menu entry. Alternatively, you can write the lines manually:
#include <Firmata.h>
#include <Boards.h>
The Firmata protocol has several revisions, and if two devices use different
revisions, that can lead to errors. To prevent this, you can specify which protocol
revision to use with setFirmwareVersion() :
setFirmwareVersion(major, minor);
The major and minor parameters are byte s, which specify the revision to use.
For most Arduino applications, this is set to major version 0 and minor version 1.
To begin using the Firmata library, you must i rst call begin() :
Firmata.begin();
Firmata.begin(speed);
This function opens a serial connection. By default, the speed is set to 57600
baud, but this can be changed by the optional speed parameter.
 
Search WWH ::




Custom Search