Reference.Firmata History

Hide minor edits - Show changes to output

June 01, 2015, at 09:06 AM by Arturo -
Changed lines 5-7 from:
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.

to:
The '''Firmata''' library implements the [[https://github.com/firmata/protocol | 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.

Added line 14:
begin(Stream &s); // start the library using a [Stream](http://www.arduino.cc/en/Reference/Stream) other than Serial (eg Serial1 or EthernetClient)
Changed line 16 from:
blinkVersion(): //blink the protocol version on pin 13
to:
blinkVersion(): //blink the protocol version on the build in LED (typically pin 13)
Changed lines 18-19 from:
setFirmwareVersion(byte major, byte minor); //set the firmware name and version, using the sketch's filename, minus the ''.pde''
to:
setFirmwareVersion(byte major, byte minor); //set the firmware name and version, using the sketch's filename, minus the '.ino'
setFirmwareNameAndVersion(const char *name, byte major, byte minor); //set both the name and version of the firmware
Changed lines 25-27 from:
sendDigitalPorts(byte pin, byte firstPort, byte secondPort); //send digital ports as individual bytes
sendDigitalPortPair(byte pin, int value); //send digital ports as one int
sendSysex(byte command, byte bytec, byte* bytev); //send a command with an arbitrary array of bytes
to:
sendDigitalPort(byte portNumber, int portData); //send an 8-bit port in a single digital message
Changed lines 27-29 from:
sendString(byte command, const char* string); //send a string to the host computer using a custom command type
to:
sendString(byte command, byte bytec, byte *bytev); //send a string to the host computer using a custom command type
sendSysex(byte command, byte bytec, byte* bytev); //send a command with an arbitrary array of bytes
write(byte c); //write a byte to the Stream
Changed lines 40-44 from:
!! Callback Functions

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''.

:generic:
to:
!! Utility methods
Changed lines 42-44 from:
void callbackFunction(byte pin, int value);
to:
sendValueAsTwo7bitBytes(int value); //writes value as 2 bytes
startSysex(void); //starts a sysex message
endSysex(void); //ends a sysex message
Changed lines 46-52 from:
:system_reset:
to:

!! Callback Functions
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.

:generic:
Changed line 54 from:
void systemResetCallbackFunction(void);
to:
void callbackFunction(byte pin, int value);
Changed line 56 from:
:string:
to:
:system_reset:
Changed line 58 from:
void stringCallbackFunction(char *myString);
to:
void systemResetCallbackFunction(void);
Changed line 60 from:
:sysex:
to:
:string:
Changed line 62 from:
void sysexCallbackFunction(byte pin, byte byteCount, byte *arrayPointer);
to:
void stringCallbackFunction(char *myString);
Changed lines 64-68 from:
to:
:sysex:
(:source lang=arduino tabwidth=4:)
void sysexCallbackFunction(byte command, byte byteCount, byte *arrayPointer);
(:sourceend:)
Changed lines 71-72 from:
These are the various message types that you can attach functions to.
to:
There are various message types that you can attach callback functions to.
Changed line 76 from:
REPORT_ANALOG //enable/disable the reporting of analog pin
to:
REPORT_ANALOG //enable/disable the reporting of an analog pin
Changed line 79 from:
FIRMATA_STRING //C-style strings, uses stringCallbackFunction for the function type
to:
STRING_DATA //C-style strings, uses stringCallbackFunction for the function type
Changed lines 95-96 from:
pinMode(pin,OUTPUT);
analogWrite(pin, value);
to:
pinMode(pin, OUTPUT);
analogWrite(pin, value);
Changed lines 101-103 from:
Firmata.setFirmwareVersion(0, 1);
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
Firmata.begin();
to:
Firmata.setFirmwareVersion(FIRMATA_MAJOR_VERSION, FIRMATA_MINOR_VERSION);
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
Firmata.begin();
Changed lines 108-113 from:
while(Firmata.available()) {
Firmata.processInput();
}
for(analogPin = 0; analogPin < TOTAL_ANALOG_PINS; analogPin++) {
Firmata.sendAnalog(analogPin, analogRead(analogPin));
}
to:
while (Firmata.available()) {
Firmata.processInput();
}
for (analogPin = 0; analogPin < TOTAL_ANALOG_PINS; analogPin++) {
Firmata.sendAnalog(analogPin, analogRead(analogPin));
}
April 17, 2015, at 10:54 AM by Arturo -
Changed line 76 from:
(: source lang=arduino tabwidth=4:)
to:
(:source lang=arduino tabwidth=4:)
April 17, 2015, at 10:53 AM by Arturo -
Changed line 61 from:
(: source lang=arduino tabwidth=4:)
to:
(:source lang=arduino tabwidth=4:)
Changed lines 103-104 from:
(:sourceend)
to:
(:sourceend:)
April 17, 2015, at 10:52 AM by Arturo -
Changed line 61 from:
(: source lang = arduino tabwidth = 4:)
to:
(: source lang=arduino tabwidth=4:)
Changed line 76 from:
(: source lang = arduino tabwidth = 4:)
to:
(: source lang=arduino tabwidth=4:)
April 17, 2015, at 10:29 AM by Arturo -
Changed line 29 from:
(: source lang = arduino tabwidth = 4:)
to:
(:source lang=arduino tabwidth=4:)
Changed lines 40-57 from:
:generic:(: source lang = arduino tabwidth = 4:)void callbackFunction(byte pin, int value);(:sourceend:)
:system_reset:(: source lang = arduino tabwidth = 4:)void systemResetCallbackFunction(void);(:sourceend:)
:string:(: source lang = arduino tabwidth = 4:)void stringCallbackFunction(char *myString);(:sourceend:)
:sysex:(: source lang = arduino tabwidth = 4:)void sysexCallbackFunction(byte pin, byte byteCount, byte *arrayPointer);(:sourceend:)

!!!!Message Types

These are the various message types that you can attach functions to.

(: source lang = arduino tabwidth = 4:)
ANALOG_MESSAGE //the analog value for a single pin
DIGITAL_MESSAGE //8-bits of digital pin data (one port)
REPORT_ANALOG //enable/disable the reporting of analog pin
REPORT_DIGITAL //enable/disable the reporting of a digital port
SET_PIN_MODE //change the pin mode between INPUT/OUTPUT/PWM/etc.
FIRMATA_STRING //C-style strings, uses stringCallbackFunction for the function type
SYSEX_START //generic, arbitrary length messages (via MIDI SysEx protocol), uses sysexCallbackFunction for the function type
SYSTEM_RESET //message to reset firmware to its default state, uses systemResetCallbackFunction for the function type
to:
:generic:
(:source lang=arduino tabwidth=4:)
void callbackFunction(byte pin, int value);
Changed lines 44-48 from:

!! Example

This example shows how to send and receive analog messages using Firmata.
to:
:system_reset:
(:source lang=arduino tabwidth=4:)
void systemResetCallbackFunction(void);
(:sourceend:)
:string:
(:source lang=arduino tabwidth=4:)
void stringCallbackFunction(char *myString);
(:sourceend:)
:sysex:
(:source lang=arduino tabwidth=4:)
void sysexCallbackFunction(byte pin, byte byteCount, byte *arrayPointer);
(:sourceend:)

!!!!Message Types

These are the various message types that you can attach functions to.
Added lines 62-76:
ANALOG_MESSAGE //the analog value for a single pin
DIGITAL_MESSAGE //8-bits of digital pin data (one port)
REPORT_ANALOG //enable/disable the reporting of analog pin
REPORT_DIGITAL //enable/disable the reporting of a digital port
SET_PIN_MODE //change the pin mode between INPUT/OUTPUT/PWM/etc.
FIRMATA_STRING //C-style strings, uses stringCallbackFunction for the function type
SYSEX_START //generic, arbitrary length messages (via MIDI SysEx protocol), uses sysexCallbackFunction for the function type
SYSTEM_RESET //message to reset firmware to its default state, uses systemResetCallbackFunction for the function type
(:sourceend:)

!! Example

This example shows how to send and receive analog messages using Firmata.

(: source lang = arduino tabwidth = 4:)
April 17, 2015, at 10:27 AM by Arturo -
Changed lines 19-25 from:
(: source lang = arduino tabwidth = 4:)sendAnalog(byte pin, int value)(:sourceend):send an analog message
(: source lang = arduino tabwidth = 4:)sendDigitalPorts(byte pin, byte firstPort, byte secondPort)(:sourceend):send digital ports as individual bytes
(: source lang = arduino tabwidth = 4:)sendDigitalPortPair(byte pin, int value)@@:send digital ports as one int
(: source lang = arduino tabwidth = 4:)sendSysex(byte command, byte bytec, byte* bytev)(:sourceend):send a command with an arbitrary array of bytes
(: source lang = arduino tabwidth = 4:)sendString(const char* string)@@:send a string to the host computer
(: source lang = arduino tabwidth = 4:)sendString(byte command, const char* string)(:sourceend):send a string to the host computer using a custom command type
to:
(:source lang=arduino tabwidth=4:)
sendAnalog(byte pin, int value); //send an analog message
sendDigitalPorts(byte pin, byte firstPort, byte secondPort); //send digital ports as individual bytes
sendDigitalPortPair(byte pin, int value); //send digital ports as one int
sendSysex(byte command, byte bytec, byte* bytev); //send a command with an arbitrary array of bytes
sendString(const char* string); //send a string to the host computer
sendString(byte command, const char* string); //send a string to the host computer using a custom command type
(:sourceend:)
Changed lines 29-33 from:
(: source lang = arduino tabwidth = 4:)available()(:sourceend):check to see if there are any incoming messages in the buffer
(: source lang = arduino tabwidth = 4:)processInput()(:sourceend):process incoming messages from the buffer, sending the data to any registered callback functions
(: source lang = arduino tabwidth = 4:)attach(byte command, callbackFunction myFunction)@@:attach a function to an incoming message type
(: source lang = arduino tabwidth = 4:)detach(byte command)(:sourceend):detach a function from an incoming message type
to:
(: source lang = arduino tabwidth = 4:)
available(); //check to see if there are any incoming messages in the buffer
processInput(); //process incoming messages from the buffer, sending the data to any registered callback functions
attach(byte command, callbackFunction myFunction); //attach a function to an incoming message type
detach(byte command); //detach a function from an incoming message type
(:sourceend:)
Changed lines 40-44 from:
:generic:(: source lang = arduino tabwidth = 4:)void callbackFunction(byte pin, int value);(:sourceend)
:system_reset:(: source lang = arduino tabwidth = 4:)void systemResetCallbackFunction(void);(:sourceend)
:string:(: source lang = arduino tabwidth = 4:)void stringCallbackFunction(char *myString);(:sourceend)
:sysex:(: source lang = arduino tabwidth = 4:)void sysexCallbackFunction(byte pin, byte byteCount, byte *arrayPointer);(:sourceend)
to:
:generic:(: source lang = arduino tabwidth = 4:)void callbackFunction(byte pin, int value);(:sourceend:)
:system_reset:(: source lang = arduino tabwidth = 4:)void systemResetCallbackFunction(void);(:sourceend:)
:string:(: source lang = arduino tabwidth = 4:)void stringCallbackFunction(char *myString);(:sourceend:)
:sysex:(: source lang = arduino tabwidth = 4:)void sysexCallbackFunction(byte pin, byte byteCount, byte *arrayPointer);(:sourceend:)
Deleted lines 48-60:
(: source lang = arduino tabwidth = 4:)ANALOG_MESSAGE(:sourceend):the analog value for a single pin
(: source lang = arduino tabwidth = 4:)DIGITAL_MESSAGE(:sourceend):8-bits of digital pin data (one port)
(: source lang = arduino tabwidth = 4:)REPORT_ANALOG(:sourceend):enable/disable the reporting of analog pin
(: source lang = arduino tabwidth = 4:)REPORT_DIGITAL(:sourceend):enable/disable the reporting of a digital port
(: source lang = arduino tabwidth = 4:)SET_PIN_MODE(:sourceend):change the pin mode between (: source lang = arduino tabwidth = 4:)INPUT@@/@@OUTPUT@@/@@PWM@@/etc.
(: source lang = arduino tabwidth = 4:)FIRMATA_STRING(:sourceend):C-style strings, uses @@stringCallbackFunction@@ for the function type
(: source lang = arduino tabwidth = 4:)SYSEX_START(:sourceend):generic, arbitrary length messages (via MIDI SysEx protocol), uses @@sysexCallbackFunction(:sourceend) for the function type
(: source lang = arduino tabwidth = 4:)SYSTEM_RESET(:sourceend):message to reset firmware to its default state, uses (: source lang = arduino tabwidth = 4:)systemResetCallbackFunction@@ for the function type

!! Example

This example shows how to send and receive analog messages using Firmata.
Added lines 50-64:
ANALOG_MESSAGE //the analog value for a single pin
DIGITAL_MESSAGE //8-bits of digital pin data (one port)
REPORT_ANALOG //enable/disable the reporting of analog pin
REPORT_DIGITAL //enable/disable the reporting of a digital port
SET_PIN_MODE //change the pin mode between INPUT/OUTPUT/PWM/etc.
FIRMATA_STRING //C-style strings, uses stringCallbackFunction for the function type
SYSEX_START //generic, arbitrary length messages (via MIDI SysEx protocol), uses sysexCallbackFunction for the function type
SYSTEM_RESET //message to reset firmware to its default state, uses systemResetCallbackFunction for the function type
(:sourceend:)

!! Example

This example shows how to send and receive analog messages using Firmata.

(: source lang = arduino tabwidth = 4:)
April 17, 2015, at 09:53 AM by Arturo -
Changed lines 16-17 from:
(:sourceend)
to:
(:sourceend:)
April 17, 2015, at 09:52 AM by Arturo -
Changed line 9 from:
(: source lang=arduino tabwidth=4:)
to:
(:source lang=arduino tabwidth=4:)
April 17, 2015, at 09:51 AM by Arturo -
Changed line 9 from:
(: source lang = arduino tabwidth = 4:)
to:
(: source lang=arduino tabwidth=4:)
April 17, 2015, at 09:51 AM by Arturo -
Changed lines 9-16 from:
(: source lang = arduino tabwidth = 4:) begin() (:sourceend):start the library
(: source lang = arduino tabwidth = 4:)begin(long)(:sourceend):start the library and override the default baud rate
(: source lang = arduino tabwidth = 4:)printVersion()(:sourceend):send the protocol version to the host computer
(: source lang = arduino tabwidth = 4:)blinkVersion()(:sourceend):blink the protocol version on pin 13
(: source lang = arduino tabwidth = 4:)printFirmwareVersion()(:sourceend):send the firmware name and version to the host computer
(: source lang = arduino tabwidth = 4:)setFirmwareVersion(byte major, byte minor)@@:set the firmware name and version, using the sketch's filename, minus the ''.pde''

to:
(: source lang = arduino tabwidth = 4:)
begin(); //start the library
begin(long); //start the library and override the default baud rate
printVersion(); //send the protocol version to the host computer
blinkVersion(): //blink the protocol version on pin 13
printFirmwareVersion(); //send the firmware name and version to the host computer
setFirmwareVersion(byte major, byte minor); //set the firmware name and version, using the sketch's filename, minus the ''.pde''
(:sourceend)
April 17, 2015, at 09:48 AM by Arturo -
Changed lines 9-16 from:
(:source lang = arduino tabwidth = 4:) begin() (:sourceend):start the library
(:source lang = arduino tabwidth = 4:)begin(long)(:sourceend):start the library and override the default baud rate
(:source lang = arduino tabwidth = 4:)printVersion()(:sourceend):send the protocol version to the host computer
(:source lang = arduino tabwidth = 4:)blinkVersion()(:sourceend):blink the protocol version on pin 13
(:source lang = arduino tabwidth = 4:)printFirmwareVersion()(:sourceend):send the firmware name and version to the host computer
(:source lang = arduino tabwidth = 4:)setFirmwareVersion(byte major, byte minor)@@:set the firmware name and version, using the sketch's filename, minus the ''.pde''

to:
(: source lang = arduino tabwidth = 4:) begin() (:sourceend):start the library
(: source lang = arduino tabwidth = 4:)begin(long)(:sourceend):start the library and override the default baud rate
(: source lang = arduino tabwidth = 4:)printVersion()(:sourceend):send the protocol version to the host computer
(: source lang = arduino tabwidth = 4:)blinkVersion()(:sourceend):blink the protocol version on pin 13
(: source lang = arduino tabwidth = 4:)printFirmwareVersion()(:sourceend):send the firmware name and version to the host computer
(: source lang = arduino tabwidth = 4:)setFirmwareVersion(byte major, byte minor)@@:set the firmware name and version, using the sketch's filename, minus the ''.pde''

Changed lines 18-24 from:
(:source lang = arduino tabwidth = 4:)sendAnalog(byte pin, int value)(:sourceend):send an analog message
(:source lang = arduino tabwidth = 4:)sendDigitalPorts(byte pin, byte firstPort, byte secondPort)(:sourceend):send digital ports as individual bytes
(:source lang = arduino tabwidth = 4:)sendDigitalPortPair(byte pin, int value)@@:send digital ports as one int
(:source lang = arduino tabwidth = 4:)sendSysex(byte command, byte bytec, byte* bytev)(:sourceend):send a command with an arbitrary array of bytes
(:source lang = arduino tabwidth = 4:)sendString(const char* string)@@:send a string to the host computer
(:source lang = arduino tabwidth = 4:)sendString(byte command, const char* string)(:sourceend):send a string to the host computer using a custom command type
to:
(: source lang = arduino tabwidth = 4:)sendAnalog(byte pin, int value)(:sourceend):send an analog message
(: source lang = arduino tabwidth = 4:)sendDigitalPorts(byte pin, byte firstPort, byte secondPort)(:sourceend):send digital ports as individual bytes
(: source lang = arduino tabwidth = 4:)sendDigitalPortPair(byte pin, int value)@@:send digital ports as one int
(: source lang = arduino tabwidth = 4:)sendSysex(byte command, byte bytec, byte* bytev)(:sourceend):send a command with an arbitrary array of bytes
(: source lang = arduino tabwidth = 4:)sendString(const char* string)@@:send a string to the host computer
(: source lang = arduino tabwidth = 4:)sendString(byte command, const char* string)(:sourceend):send a string to the host computer using a custom command type
Changed lines 26-30 from:
(:source lang = arduino tabwidth = 4:)available()(:sourceend):check to see if there are any incoming messages in the buffer
(:source lang = arduino tabwidth = 4:)processInput()(:sourceend):process incoming messages from the buffer, sending the data to any registered callback functions
(:source lang = arduino tabwidth = 4:)attach(byte command, callbackFunction myFunction)@@:attach a function to an incoming message type
(:source lang = arduino tabwidth = 4:)detach(byte command)(:sourceend):detach a function from an incoming message type
to:
(: source lang = arduino tabwidth = 4:)available()(:sourceend):check to see if there are any incoming messages in the buffer
(: source lang = arduino tabwidth = 4:)processInput()(:sourceend):process incoming messages from the buffer, sending the data to any registered callback functions
(: source lang = arduino tabwidth = 4:)attach(byte command, callbackFunction myFunction)@@:attach a function to an incoming message type
(: source lang = arduino tabwidth = 4:)detach(byte command)(:sourceend):detach a function from an incoming message type
Changed lines 35-39 from:
:generic:(:source lang = arduino tabwidth = 4:)void callbackFunction(byte pin, int value);(:sourceend)
:system_reset:(:source lang = arduino tabwidth = 4:)void systemResetCallbackFunction(void);(:sourceend)
:string:(:source lang = arduino tabwidth = 4:)void stringCallbackFunction(char *myString);(:sourceend)
:sysex:(:source lang = arduino tabwidth = 4:)void sysexCallbackFunction(byte pin, byte byteCount, byte *arrayPointer);(:sourceend)
to:
:generic:(: source lang = arduino tabwidth = 4:)void callbackFunction(byte pin, int value);(:sourceend)
:system_reset:(: source lang = arduino tabwidth = 4:)void systemResetCallbackFunction(void);(:sourceend)
:string:(: source lang = arduino tabwidth = 4:)void stringCallbackFunction(char *myString);(:sourceend)
:sysex:(: source lang = arduino tabwidth = 4:)void sysexCallbackFunction(byte pin, byte byteCount, byte *arrayPointer);(:sourceend)
Changed lines 44-52 from:
(:source lang = arduino tabwidth = 4:)ANALOG_MESSAGE(:sourceend):the analog value for a single pin
(:source lang = arduino tabwidth = 4:)DIGITAL_MESSAGE(:sourceend):8-bits of digital pin data (one port)
(:source lang = arduino tabwidth = 4:)REPORT_ANALOG(:sourceend):enable/disable the reporting of analog pin
(:source lang = arduino tabwidth = 4:)REPORT_DIGITAL(:sourceend):enable/disable the reporting of a digital port
(:source lang = arduino tabwidth = 4:)SET_PIN_MODE(:sourceend):change the pin mode between (:source lang = arduino tabwidth = 4:)INPUT@@/@@OUTPUT@@/@@PWM@@/etc.
(:source lang = arduino tabwidth = 4:)FIRMATA_STRING(:sourceend):C-style strings, uses @@stringCallbackFunction@@ for the function type
(:source lang = arduino tabwidth = 4:)SYSEX_START(:sourceend):generic, arbitrary length messages (via MIDI SysEx protocol), uses @@sysexCallbackFunction(:sourceend) for the function type
(:source lang = arduino tabwidth = 4:)SYSTEM_RESET(:sourceend):message to reset firmware to its default state, uses (:source lang = arduino tabwidth = 4:)systemResetCallbackFunction@@ for the function type
to:
(: source lang = arduino tabwidth = 4:)ANALOG_MESSAGE(:sourceend):the analog value for a single pin
(: source lang = arduino tabwidth = 4:)DIGITAL_MESSAGE(:sourceend):8-bits of digital pin data (one port)
(: source lang = arduino tabwidth = 4:)REPORT_ANALOG(:sourceend):enable/disable the reporting of analog pin
(: source lang = arduino tabwidth = 4:)REPORT_DIGITAL(:sourceend):enable/disable the reporting of a digital port
(: source lang = arduino tabwidth = 4:)SET_PIN_MODE(:sourceend):change the pin mode between (: source lang = arduino tabwidth = 4:)INPUT@@/@@OUTPUT@@/@@PWM@@/etc.
(: source lang = arduino tabwidth = 4:)FIRMATA_STRING(:sourceend):C-style strings, uses @@stringCallbackFunction@@ for the function type
(: source lang = arduino tabwidth = 4:)SYSEX_START(:sourceend):generic, arbitrary length messages (via MIDI SysEx protocol), uses @@sysexCallbackFunction(:sourceend) for the function type
(: source lang = arduino tabwidth = 4:)SYSTEM_RESET(:sourceend):message to reset firmware to its default state, uses (: source lang = arduino tabwidth = 4:)systemResetCallbackFunction@@ for the function type
Changed line 57 from:
(:source lang = arduino tabwidth = 4:)
to:
(: source lang = arduino tabwidth = 4:)
April 17, 2015, at 09:47 AM by Arturo -
Changed lines 9-16 from:
:@@begin()@@:start the library
:@@begin(long)@@:start the library and override the default baud rate
:@@printVersion()@@:send the protocol version to the host computer
:@@blinkVersion()@@:blink the protocol version on pin 13
:@@printFirmwareVersion()@@:send the firmware name and version to the host computer
:@@setFirmwareVersion(byte major, byte minor)@@:set the firmware name and version, using the sketch's filename, minus the ''.pde''

to:
(:source lang = arduino tabwidth = 4:) begin() (:sourceend):start the library
(:source lang = arduino tabwidth = 4:)begin(long)(:sourceend):start the library and override the default baud rate
(:source lang = arduino tabwidth = 4:)printVersion()(:sourceend):send the protocol version to the host computer
(:source lang = arduino tabwidth = 4:)blinkVersion()(:sourceend):blink the protocol version on pin 13
(:source lang = arduino tabwidth = 4:)printFirmwareVersion()(:sourceend):send the firmware name and version to the host computer
(:source lang = arduino tabwidth = 4:)setFirmwareVersion(byte major, byte minor)@@:set the firmware name and version, using the sketch's filename, minus the ''.pde''

Changed lines 18-24 from:
:@@sendAnalog(byte pin, int value)@@:send an analog message
:@@sendDigitalPorts(byte pin, byte firstPort, byte secondPort)@@:send digital ports as individual bytes
:@@sendDigitalPortPair(byte pin, int value)@@:send digital ports as one int
:@@sendSysex(byte command, byte bytec, byte* bytev)@@:send a command with an arbitrary array of bytes
:@@sendString(const char* string)@@:send a string to the host computer
:@@sendString(byte command, const char* string)@@:send a string to the host computer using a custom command type
to:
(:source lang = arduino tabwidth = 4:)sendAnalog(byte pin, int value)(:sourceend):send an analog message
(:source lang = arduino tabwidth = 4:)sendDigitalPorts(byte pin, byte firstPort, byte secondPort)(:sourceend):send digital ports as individual bytes
(:source lang = arduino tabwidth = 4:)sendDigitalPortPair(byte pin, int value)@@:send digital ports as one int
(:source lang = arduino tabwidth = 4:)sendSysex(byte command, byte bytec, byte* bytev)(:sourceend):send a command with an arbitrary array of bytes
(:source lang = arduino tabwidth = 4:)sendString(const char* string)@@:send a string to the host computer
(:source lang = arduino tabwidth = 4:)sendString(byte command, const char* string)(:sourceend):send a string to the host computer using a custom command type
Changed lines 26-30 from:
:@@available()@@:check to see if there are any incoming messages in the buffer
:@@processInput()@@:process incoming messages from the buffer, sending the data to any registered callback functions
:@@attach(byte command, callbackFunction myFunction)@@:attach a function to an incoming message type
:@@detach(byte command)@@:detach a function from an incoming message type
to:
(:source lang = arduino tabwidth = 4:)available()(:sourceend):check to see if there are any incoming messages in the buffer
(:source lang = arduino tabwidth = 4:)processInput()(:sourceend):process incoming messages from the buffer, sending the data to any registered callback functions
(:source lang = arduino tabwidth = 4:)attach(byte command, callbackFunction myFunction)@@:attach a function to an incoming message type
(:source lang = arduino tabwidth = 4:)detach(byte command)(:sourceend):detach a function from an incoming message type
Changed lines 35-39 from:
:generic:@@void callbackFunction(byte pin, int value);@@
:system_reset:@@void systemResetCallbackFunction(void);@@
:string:@@void stringCallbackFunction(char *myString);@@
:sysex:@@void sysexCallbackFunction(byte pin, byte byteCount, byte *arrayPointer);@@
to:
:generic:(:source lang = arduino tabwidth = 4:)void callbackFunction(byte pin, int value);(:sourceend)
:system_reset:(:source lang = arduino tabwidth = 4:)void systemResetCallbackFunction(void);(:sourceend)
:string:(:source lang = arduino tabwidth = 4:)void stringCallbackFunction(char *myString);(:sourceend)
:sysex:(:source lang = arduino tabwidth = 4:)void sysexCallbackFunction(byte pin, byte byteCount, byte *arrayPointer);(:sourceend)
Changed lines 44-52 from:
:@@ANALOG_MESSAGE@@:the analog value for a single pin
:@@DIGITAL_MESSAGE@@:8-bits of digital pin data (one port)
:@@REPORT_ANALOG@@:enable/disable the reporting of analog pin
:@@REPORT_DIGITAL@@:enable/disable the reporting of a digital port
:@@SET_PIN_MODE@@:change the pin mode between @@INPUT@@/@@OUTPUT@@/@@PWM@@/etc.
:@@FIRMATA_STRING@@:C-style strings, uses @@stringCallbackFunction@@ for the function type
:@@SYSEX_START@@:generic, arbitrary length messages (via MIDI SysEx protocol), uses @@sysexCallbackFunction@@ for the function type
:@@SYSTEM_RESET@@:message to reset firmware to its default state, uses @@systemResetCallbackFunction@@ for the function type
to:
(:source lang = arduino tabwidth = 4:)ANALOG_MESSAGE(:sourceend):the analog value for a single pin
(:source lang = arduino tabwidth = 4:)DIGITAL_MESSAGE(:sourceend):8-bits of digital pin data (one port)
(:source lang = arduino tabwidth = 4:)REPORT_ANALOG(:sourceend):enable/disable the reporting of analog pin
(:source lang = arduino tabwidth = 4:)REPORT_DIGITAL(:sourceend):enable/disable the reporting of a digital port
(:source lang = arduino tabwidth = 4:)SET_PIN_MODE(:sourceend):change the pin mode between (:source lang = arduino tabwidth = 4:)INPUT@@/@@OUTPUT@@/@@PWM@@/etc.
(:source lang = arduino tabwidth = 4:)FIRMATA_STRING(:sourceend):C-style strings, uses @@stringCallbackFunction@@ for the function type
(:source lang = arduino tabwidth = 4:)SYSEX_START(:sourceend):generic, arbitrary length messages (via MIDI SysEx protocol), uses @@sysexCallbackFunction(:sourceend) for the function type
(:source lang = arduino tabwidth = 4:)SYSTEM_RESET(:sourceend):message to reset firmware to its default state, uses (:source lang = arduino tabwidth = 4:)systemResetCallbackFunction@@ for the function type
Changed line 57 from:
[@
to:
(:source lang = arduino tabwidth = 4:)
Changed lines 84-85 from:
@]
to:
(:sourceend)
November 25, 2008, at 08:28 PM by Hans Steiner -
Deleted line 0:
[[Interfacing.Firmata|Firmata]] - Library - [[Interfacing.FirmataBaudRateDetails|Baud Rate Details]] - [[Interfacing.FirmataProtocolDetails|Protocol Details]] - [[Interfacing.FirmataProtocolProposals | Protocol Proposals]]
Added lines 2-3:
[[http://www.arduino.cc/playground/Interfacing/Firmata|Firmata]] - Library - [[http://www.arduino.cc/playground/Interfacing/FirmataBaudRateDetails|Baud Rate Details]] - [[http://www.arduino.cc/playground/Interfacing/FirmataProtocolDetails|Protocol Details]] - [[http://www.arduino.cc/playground/Interfacing/FirmataProtocolProposals | Protocol Proposals]]
----
November 25, 2008, at 08:24 PM by Hans Steiner -
Added lines 1-84:
[[Interfacing.Firmata|Firmata]] - Library - [[Interfacing.FirmataBaudRateDetails|Baud Rate Details]] - [[Interfacing.FirmataProtocolDetails|Protocol Details]] - [[Interfacing.FirmataProtocolProposals | Protocol Proposals]]
----
!Firmata Library
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.


!! Methods
:@@begin()@@:start the library
:@@begin(long)@@:start the library and override the default baud rate
:@@printVersion()@@:send the protocol version to the host computer
:@@blinkVersion()@@:blink the protocol version on pin 13
:@@printFirmwareVersion()@@:send the firmware name and version to the host computer
:@@setFirmwareVersion(byte major, byte minor)@@:set the firmware name and version, using the sketch's filename, minus the ''.pde''


!!!!Sending Messages
:@@sendAnalog(byte pin, int value)@@:send an analog message
:@@sendDigitalPorts(byte pin, byte firstPort, byte secondPort)@@:send digital ports as individual bytes
:@@sendDigitalPortPair(byte pin, int value)@@:send digital ports as one int
:@@sendSysex(byte command, byte bytec, byte* bytev)@@:send a command with an arbitrary array of bytes
:@@sendString(const char* string)@@:send a string to the host computer
:@@sendString(byte command, const char* string)@@:send a string to the host computer using a custom command type

!!!!Receiving Messages
:@@available()@@:check to see if there are any incoming messages in the buffer
:@@processInput()@@:process incoming messages from the buffer, sending the data to any registered callback functions
:@@attach(byte command, callbackFunction myFunction)@@:attach a function to an incoming message type
:@@detach(byte command)@@:detach a function from an incoming message type

!! Callback Functions

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''.

:generic:@@void callbackFunction(byte pin, int value);@@
:system_reset:@@void systemResetCallbackFunction(void);@@
:string:@@void stringCallbackFunction(char *myString);@@
:sysex:@@void sysexCallbackFunction(byte pin, byte byteCount, byte *arrayPointer);@@

!!!!Message Types

These are the various message types that you can attach functions to.

:@@ANALOG_MESSAGE@@:the analog value for a single pin
:@@DIGITAL_MESSAGE@@:8-bits of digital pin data (one port)
:@@REPORT_ANALOG@@:enable/disable the reporting of analog pin
:@@REPORT_DIGITAL@@:enable/disable the reporting of a digital port
:@@SET_PIN_MODE@@:change the pin mode between @@INPUT@@/@@OUTPUT@@/@@PWM@@/etc.
:@@FIRMATA_STRING@@:C-style strings, uses @@stringCallbackFunction@@ for the function type
:@@SYSEX_START@@:generic, arbitrary length messages (via MIDI SysEx protocol), uses @@sysexCallbackFunction@@ for the function type
:@@SYSTEM_RESET@@:message to reset firmware to its default state, uses @@systemResetCallbackFunction@@ for the function type

!! Example

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));
}
}
@]

Share