Tuesday, December 30, 2014

Arduino USB Control with Firmata

Control RGB LEDs ( Arduino Uno )

Arduino USB Control with Firmata Library

Arduino Firmata Library is source code to communicate or control Arduino Board with other device.

Firmata is already include in your Arduino IDE.

Firmata Test Program
This "firmata_test" program works with boards running StandardFirmata version 2.2 or higher on standard Baud rate 57600.

For Linux (32 bit)

For Linux (64 bit)

For Mac OS-X

For Windows

Source code
http://www.pjrc.com/teensy/firmata_test/firmata_test_OSL.tgz (unicode compatible, by Orion Lawlor)

We Test on Windows ( see VDO above )

First Program Firmata Code to Arduino Board.

Open Arduino IDE ( we use Arduino 1.0.6 )

Goto File > Examples > Firmata > StandardFirmata

Then Upload to your Arduino Board

Open Firmata Test Program ( we test on Windows )

Connect USB to your Arduino Board then Select port.

Ready To Control

Android USB Control with Firmata

Firmata Command


start the library
start the library and override the default baud rate
send the protocol version to the host computer
blink the protocol version on pin 13
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

check to see if there are any incoming messages in the buffer
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.
void callbackFunction(byte pin, int value);
void systemResetCallbackFunction(void);
void stringCallbackFunction(char *myString);
void sysexCallbackFunction(byte pin, byte byteCount, byte *arrayPointer);

Message Types

These are the various message types that you can attach functions to.
the analog value for a single pin
8-bits of digital pin data (one port)
enable/disable the reporting of analog pin
enable/disable the reporting of a digital port
change the pin mode between INPUT/OUTPUT/PWM/etc.
C-style strings, uses stringCallbackFunction for the function type
generic, arbitrary length messages (via MIDI SysEx protocol), uses sysexCallbackFunction for the function type

message to reset firmware to its default state, uses systemResetCallbackFunction for the function type

My Website
email : info@softpowergroup.net   Tel .081-6452400
Google+  https://plus.google.com/+SoftpowergroupNetThailand/