Reference Language | Libraries | Comparison | Changes
Firmata - Library - Baud Rate Details - Protocol Details - Protocol Proposals
The Firmata library implements the Firmata protocol for communicating with software on the host computer. This allows you to write custom firmware without having to create your own protocol and objects for the programming environment that you are using.
begin()begin(long)printVersion()blinkVersion()printFirmwareVersion()setFirmwareVersion(byte major, byte minor)sendAnalog(byte pin, int value)sendDigitalPorts(byte pin, byte firstPort, byte secondPort)sendDigitalPortPair(byte pin, int value)sendSysex(byte command, byte bytec, byte* bytev)sendString(const char* string)sendString(byte command, const char* string)available()processInput()attach(byte command, callbackFunction myFunction)detach(byte command)In order to attach your function to a message type, your function must match the standard callback function. There are currently three types of callback functions in Firmata: generic, string, and sysex.
void callbackFunction(byte pin, int value);
void systemResetCallbackFunction(void);
void stringCallbackFunction(char *myString);
void sysexCallbackFunction(byte pin, byte byteCount, byte *arrayPointer);
These are the various message types that you can attach functions to.
ANALOG_MESSAGEDIGITAL_MESSAGEREPORT_ANALOGREPORT_DIGITALSET_PIN_MODEINPUT/OUTPUT/PWM/etc.
FIRMATA_STRINGstringCallbackFunction for the function type
SYSEX_STARTsysexCallbackFunction for the function type
SYSTEM_RESETsystemResetCallbackFunction for the function type
This example shows how to send and receive analog messages using Firmata.
#include <Firmata.h>
byte analogPin;
void analogWriteCallback(byte pin, int value)
{
pinMode(pin,OUTPUT);
analogWrite(pin, value);
}
void setup()
{
Firmata.setFirmwareVersion(0, 1);
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
Firmata.begin();
}
void loop()
{
while(Firmata.available()) {
Firmata.processInput();
}
for(analogPin = 0; analogPin < TOTAL_ANALOG_PINS; analogPin++) {
Firmata.sendAnalog(analogPin, analogRead(analogPin));
}
}
Corrections, suggestions, and new documentation should be posted to the Forum.
The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.