ofArduino
This is a way to control an Arduino that has had the firmata library loaded onto it, from OF. To load firmata onto your Arduino, run the Arduino IDE, open the Examples
attachEncoder( ... )
void attachEncoder(int pinA, int pinB)} \name Encoder {
connect( ... )
bool connect(const string &device, int baud=57600)Opens a serial port connection to the arduino
Parameters:
device The name of the device. You can get the name from the Arduino IDE
baud The baud rate the connection uses
opens a serial port connection to the arduino
convertAnalogPinToDigital( ... )
int convertAnalogPinToDigital(size_t pin)convertDigitalPinToAnalog( ... )
int convertDigitalPinToAnalog(size_t pin)detachEncoder( ... )
void detachEncoder(int encoderNum)disableEncoderReporting( )
void disableEncoderReporting()disconnect( )
void disconnect()Closes the serial port connection. Does not turn the Arduino off.
closes the serial port connection. Does not turn the Arduino off.
enableEncoderReporting( )
void enableEncoderReporting()getAllEncoderPositions( )
void getAllEncoderPositions()getAnalog( ... )
int getAnalog(int pin)Returns the analog in value that the pin is currently reading. because the Arduino has a 10 bit ADC you get between 0 and 1023 for possible values.
Parameters:
pin The pin number (0-5)
Returns the analog in value that the pin is currently reading. because the Arduino has a 10 bit ADC you get between 0 and 1023 for possible values.
getAnalogHistory( )
int * getAnalogHistory()Returns a pointer to the analog data history list for the given pin.
Parameters:
pin The Arduino Uno pin: 0-5
On the Arduino Uno pin: 0-5 returns a pointer to the analog data history list for the given pin
getAnalogPinReporting( ... )
int getAnalogPinReporting(int pin)Returns: ARD_ON or ARD_OFF
returns ARD_ON, ARD_OFF
getDigital( ... )
int getDigital(int pin)Returns the last received value (if the pin mode is ARD_INPUT) or the last set value (if the pin mode is ARD_OUTPUT) for the given pin
Returns whether the pin is reading high or low, 1 or 0. You can test against this with an if() statement which is handy:
if(arduino.getDigital(pin)){
// do something on high
} else {
// do something on low
}
\note Pin 16-21 can also be used if analog inputs 0-5 are used as digital pins
On the Arduino Uno pin: 2-13 returns the last received value (if the pin mode is ARD_INPUT) or the last set value (if the pin mode is ARD_OUTPUT) for the given pin Note: pin 16-21 can also be used if analog inputs 0-5 are used as digital pins Returns whether the pin is reading high or low, 1 or 0. You can test against this with an if() statement which is handy:
if(arduino.getDigital(pin)){
// do something on high
}else{
// do something on low
}
getDigitalHistory( )
int * getDigitalHistory()Returns a pointer to the digital data history list for the given pin \note Pin 16-21 can also be used if analog inputs 0-5 are used as digital pins
Parameters:
pin The pin number (2-13)
On the Arduino Uno pin: 2-13 returns a pointer to the digital data history list for the given pin Note: pin 16-21 can also be used if analog inputs 0-5 are used as digital pins
getDigitalPinMode( ... )
int getDigitalPinMode(int pin)Get the pin mode of the given pin
Returns: ARD_INPUT, ARD_OUTPUT, ARD_PWM, ARD_SERVO, ARD_ANALOG
returns ARD_INPUT, ARD_OUTPUT, ARD_PWM, ARD_SERVO, ARD_ANALOG
getEncoderPosition( ... )
void getEncoderPosition(int encoderNum)getFirmwareName( )
string getFirmwareName()Returns: the name of the firmware.
returns the name of the firmware
getInvertedValueFromTwo7bitBytes( ... )
int getInvertedValueFromTwo7bitBytes(unsigned char lsb, unsigned char msb)getMajorFirmwareVersion( )
int getMajorFirmwareVersion()Returns: the major firmware version.
returns the major firmware version
getMinorFirmwareVersion( )
int getMinorFirmwareVersion()Returns: the minor firmware version.
returns the minor firmware version
getNumAnalogPins( )
int getNumAnalogPins()getPinCapabilities( )
int getPinCapabilities()getPwm( ... )
int getPwm(int pin)Returns the last set PWM value (0-255) for the given pin
The pins mode has to be ARD_PWM
On the Arduino Uno the following pins are supported: 3, 5, 6, 9, 10 and 11 \note Pin 16-21 can also be used if analog inputs 0-5 are used as digital pins
On the Arduino Uno pin: 3, 5, 6, 9, 10 and 11 returns the last set PWM value (0-255) for the given pin the pins mode has to be ARD_PWM Note: pin 16-21 can also be used if analog inputs 0-5 are used as digital pins
getServo( ... )
int getServo(int pin)Returns: the last set servo value for a pin if the pin has a servo attached.
returns the last set servo value for a pin if the pin has a servo attached
getString( )
string getString()Returns: the last received string.
returns the last received string
getStringHistory( )
int * getStringHistory()Returns: a pointer to the string history.
returns a pointer to the string history
getSysEx( )
int getSysEx()Returns: the last received SysEx message.
returns the last received SysEx message
getSysExHistory( )
int * getSysExHistory()Returns: a pointer to the SysEx history.
returns a pointer to the SysEx history
getTotalPins( )
int getTotalPins()getValueFromTwo7bitBytes( ... )
int getValueFromTwo7bitBytes(unsigned char lsb, unsigned char msb)Useful for parsing SysEx messages
useful for parsing SysEx messages
initPins( )
void initPins()< Indicate that pins are initialized.
isAnalogPin( ... )
bool isAnalogPin(int pin)isArduinoReady( )
bool isArduinoReady()isAttached( )
bool isAttached()isI2CConfigured( )
bool isI2CConfigured()isInitialized( )
bool isInitialized()Returns true if a succesfull connection has been established and the Arduino has reported a firmware
returns true if a succesfull connection has been established and the Arduino has reported a firmware
isPin( ... )
bool isPin(int pin)ofArduino( )
ofArduino()\name Constructor and Destructor {
processData( ... )
void processData(unsigned char inputData)processDigitalPort( ... )
void processDigitalPort(int port, unsigned char value)processSysExData( ... )
void processSysExData(int data)purge( )
void purge()resetEncoderPosition( ... )
void resetEncoderPosition(int encoderNum)sendAnalogMappingRequest( )
void sendAnalogMappingRequest()sendAnalogPinReporting( ... )
void sendAnalogPinReporting(int pin, int mode)sendByte( ... )
void sendByte(unsigned char byte)sends a byte without wrapping it in a firmata message, data has to be in the 0-127 range, values
sendDigital( ... )
void sendDigital(int pin, int value, bool force=false)} \name Senders {
sendDigitalPinMode( ... )
void sendDigitalPinMode(int pin, int mode)Setting a pins mode to ARD_INPUT turns on reporting for the port the pin is on
Parameters:
pin Pin on arduino (2-13)
mode ARD_INPUT, ARD_OUTPUT, ARD_PWM
\note Analog pins 0-5 can be used as digitial pins 16-21 but if the
mode of one of these pins is set to ARD_INPUT then all analog pin
reporting will be turned off
On the Arduino Uno pin: 2-13 mode: ARD_INPUT, ARD_OUTPUT, ARD_PWM setting a pins mode to ARD_INPUT turns on reporting for the port the pin is on Note: analog pins 0-5 can be used as digitial pins 16-21 but if the mode of one of these pins is set to ARD_INPUT then all analog pin reporting will be turned off
sendDigitalPinReporting( ... )
void sendDigitalPinReporting(int pin, int mode)sendDigitalPortReporting( ... )
void sendDigitalPortReporting(int port, int mode)sendFirmwareVersionRequest( )
void sendFirmwareVersionRequest()sendI2CConfig( ... )
void sendI2CConfig(int delay)Sends a I2C config request
Must be called before an I2C Read or Write
Parameters:
{number} delay in microseconds to set for I2C Read
sendI2CReadRequest( ... )
void sendI2CReadRequest(char address, int numBytes, int reg)Asks the arduino to request bytes from an I2C device
Parameters:
{number} slaveAddress The address of the I2C device
{number} numBytes The number of bytes to receive.
{function} callback A function to call when we have received the bytes.
sendI2CWriteRequest( ... )
void sendI2CWriteRequest(char slaveAddress, unsigned char *bytes, int numOfBytes, int reg)Asks the arduino to send an I2C request to a device
Parameters:
{number} slaveAddress The address of the I2C device
{Array} bytes The bytes to send to the device
sendI2CWriteRequest( ... )
void sendI2CWriteRequest(char slaveAddress, const char *bytes, int numOfBytes, int reg)sendI2CWriteRequest( ... )
void sendI2CWriteRequest(char slaveAddress, char *bytes, int numOfBytes, int reg)sendI2CWriteRequest( ... )
void sendI2CWriteRequest(char slaveAddress, int bytes, int reg)sendI2ContinuousReadRequest( ... )
void sendI2ContinuousReadRequest(char address, int numBytes, int reg)Initialize a continuous I2C read.
Parameters:
{number} address The address of the I2C device
{number} register Optionally set the register to read from.
{number} numBytes The number of bytes to receive.
sendOneWireAlarmsSearch( ... )
void sendOneWireAlarmsSearch(int pin)Searches for 1-wire devices on the bus in an alarmed state.
Parameters:
pin
sendOneWireConfig( ... )
void sendOneWireConfig(int pin, bool enableParasiticPower)Configure the passed pin as the controller in a 1-wire bus.
Pass as enableParasiticPower true if you want the data pin to power the bus.
Parameters:
pin
enableParasiticPower
sendOneWireDelay( ... )
void sendOneWireDelay(int pin, unsigned int delay)Tells firmata to not do anything for the passed amount of ms.
For when you need to give a device attached to the bus time to do a calculation.
Parameters:
pin
sendOneWireRead( ... )
void sendOneWireRead(int pin, int devices, int numBytesToRead)Reads data from a device on the bus.
N.b. ConfigurableFirmata will issue the 1-wire select command internally.
Parameters:
pin
device
numBytesToRead
callback
sendOneWireRequest( ... )
void sendOneWireRequest(int pin, unsigned char subcommand, int devices, int numBytesToRead, unsigned char correlationId, unsigned int delay, int dataToWrite)sendOneWireReset( ... )
void sendOneWireReset(int pin)Resets all devices on the bus.
Parameters:
pin
sendOneWireSearch( ... )
void sendOneWireSearch(int pin)Searches for 1-wire devices on the bus.
Parameters:
pin
sendOneWireSearch( ... )
void sendOneWireSearch(char type, int pin)sendOneWireWrite( ... )
void sendOneWireWrite(int pin, int devices, int data)Writes data to the bus to be received by the passed device.
The device should be obtained from a previous call to sendOneWireSearch. ConfigurableFirmata will issue the 1-wire select command internally.
Parameters:
pin
device
data
sendOneWireWriteAndRead( ... )
void sendOneWireWriteAndRead(int pin, int devices, int data, int numBytesToRead)Sends the passed data to the passed device on the bus, reads the specified number of bytes.
ConfigurableFirmata will issue the 1-wire select command internally.
Parameters:
pin
device
data
numBytesToRead
callback
sendPinCapabilityRequest( )
void sendPinCapabilityRequest()sendPinCofigurationRequest( )
void sendPinCofigurationRequest()sendPinStateQuery( ... )
void sendPinStateQuery(int pin)sendProtocolVersionRequest( )
void sendProtocolVersionRequest()sendPwm( ... )
void sendPwm(int pin, int value, bool force=false)On the Uno this will work on pins: 3, 5, 6, 9, 10 and 11 value: 0 (always off) to 255 (always on). the pins mode has to be set to ARD_PWM TODO check if the PWM bug still is there causing frequent digital port reporting...
sendReset( )
void sendReset()This will cause your Arduino to reset and boot into the program again.
This will cause your Arduino to reset and boot into the program again.
sendSerialConfig( ... )
void sendSerialConfig(Firmata_Serial_Ports portID, int baud, int rxPin, int txPin)Asks the Arduino to configure a hardware or serial port.
Parameters:
portID The serial port to use (HW_SERIAL1, HW_SERIAL2, HW_SERIAL3, SW_SERIAL0, SW_SERIAL1, SW_SERIAL2, SW_SERIAL3)
baud The baud rate of the serial port
rxPin [SW Serial only] The RX pin of the SoftwareSerial instance
txPin [SW Serial only] The TX pin of the SoftwareSerial instance
sendServo( ... )
void sendServo(int pin, int value, bool force=false)Send a value to a servo.
A servo has to be atached to the pin prior
Parameters:
pin 9 or 10
value The value to send
On the Arduino Uno pin: 9, 10 the pin has to have a servo attached for this to work.
sendServoAttach( ... )
void sendServoAttach(int pin, int minPulse=544, int maxPulse=2400)Parameters:
angle parameter DEPRECATED as of Firmata 2.2
On the Arduino Uno pin: 9, 10 attaches a servo to a pin angle parameter DEPRECATED as of Firmata 2.2
sendStepper2Wire( ... )
void sendStepper2Wire(int dirPin, int stepPin, int stepsPerRev=200)-- stepper
sendStepper4Wire( ... )
void sendStepper4Wire(int pin1, int pin2, int pin3, int pin4, int stepsPerRev=200)the pins has to have a stepper attached
sendStepperMove( ... )
void sendStepperMove(int stepperID, int direction, int steps, int speed=0, float acceleration, float deceleration)the pins has to have a stepper attached
sendString( ... )
void sendString(string str)Send a string to the Arduino \note Firmata can not handle strings longer than 12 characters.
firmata can not handle strings longer than 12 characters.
sendSysEx( ... )
void sendSysEx(int command, int data)sendSysExBegin( )
void sendSysExBegin()Sends the FIRMATA_START_SYSEX command
sendSysExEnd( )
void sendSysExEnd()Sends the FIRMATA_END_SYSEX command
sendValueAsTwo7bitBytes( ... )
void sendValueAsTwo7bitBytes(int value)Send value as two 7 bit bytes.
Sends a value as two 7-bit bytes without wrapping it in a firmata message. Values in the range 0 - 16384 will be sent as two bytes within the 0-127 data range.
Parameters:
value The value to send.
serialClose( ... )
void serialClose(Firmata_Serial_Ports portID)Close the specified serial port.
Parameters:
portId The serial port to close.
serialFlush( ... )
void serialFlush(Firmata_Serial_Ports portID)Flush the specified serial port.
For hardware serial, this waits for the transmission of outgoing serial data to complete.For software serial, this removed any buffered incoming serial data.
Parameters:
portId The serial port to listen on.
serialListen( ... )
void serialListen(Firmata_Serial_Ports portID)For SoftwareSerial only. Only a single SoftwareSerial instance can read data at a time.
Call this method to set this port to be the reading port in the case there are multiple SoftwareSerial instances.
Parameters:
portId The serial port to flush.
serialRead( ... )
void serialRead(Firmata_Serial_Ports port, int maxBytesToRead)Start continuous reading of the specified serial port.
The port is checked for data each iteration of the main Arduino loop.
Parameters:
portId The serial port to start reading continuously.
maxBytesToRead [Optional] The maximum number of bytes to read per iteration. \note If there are less bytes in the buffer, the lesser number of bytes will be returned. A value of 0 indicates that all available bytes in the buffer should be read.
serialStop( ... )
void serialStop(Firmata_Serial_Ports portID)Stop continuous reading of the specified serial port.
This does not close the port, it stops reading it but keeps the port open.
Parameters:
portId The serial port to stop reading.
serialWrite( ... )
void serialWrite(Firmata_Serial_Ports port, unsigned char *bytes, int numOfBytes)Write an array of bytes to the specified serial port.
Parameters:
portId The serial port to write to.
bytes An array of bytes to write to the serial port.
numOfBytes length of the array of bytes.
setAnalogHistoryLength( ... )
void setAnalogHistoryLength(int length)setDigitalHistoryLength( ... )
void setDigitalHistoryLength(int length)setStringHistoryLength( ... )
void setStringHistoryLength(int length)setSysExHistoryLength( ... )
void setSysExHistoryLength(int nSysEx)setUseDelay( ... )
void setUseDelay(bool bDelay)update( )
void update()Polls data from the serial port, this has to be called periodically
polls data from the serial port, this has to be called periodically
~ofArduino( )
~ofArduino()