class methods
- attachEncoder()
- connect()
- detachEncoder()
- disableEncoderReporting()
- disconnect()
- enableEncoderReporting()
- getAllEncoderPositions()
- getAnalog()
- getAnalogPinReporting()
- getDigital()
- getDigitalPinMode()
- getEncoderPosition()
- getInvertedValueFromTwo7bitBytes()
- getNumAnalogPins()
- getPinCapabilities()
- getPwm()
- getString()
- getTotalPins()
- isArduinoReady()
- isAttached()
- isI2CConfigured()
- isInitialized()
- resetEncoderPosition()
- sendAnalogMappingRequest()
- sendAnalogPinReporting()
- sendByte()
- sendDigital()
- sendDigitalPinMode()
- sendI2CConfig()
- sendI2CReadRequest()
- sendI2CWriteRequest()
- sendI2ContinuousReadRequest()
- sendOneWireAlarmsSearch()
- sendOneWireConfig()
- sendOneWireDelay()
- sendOneWireRead()
- sendOneWireRequest()
- sendOneWireReset()
- sendOneWireSearch()
- sendOneWireWrite()
- sendOneWireWriteAndRead()
- sendPinCapabilityRequest()
- sendPinCofigurationRequest()
- sendPinStateQuery()
- sendPwm()
- sendReset()
- sendSerialConfig()
- sendStepper2Wire()
- sendStepper4Wire()
- sendStepperMove()
- sendString()
- serialClose()
- serialFlush()
- serialListen()
- serialRead()
- serialStop()
- serialWrite()
- setUseDelay()
- update()
variables
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 > Firmata > StandardFirmata sketch, and upload it to the Arduino board. Once the ofArduino instance returns true from isArduinoReady() you can set the mode of the different digital pins using sendDigitalPinMode()
sendDigitalPinMode(9, ARD_INPUT)
This sets pin 9 to input so that it can read a button press, while:
sendDigitalPinMode(9, ARD_PWM)
sets pin 9 to be a PWM out pin. Note that this only works on pins that are PWM enabled.
attachEncoder(...)
void ofArduino::attachEncoder(int pinA, int pinB)
Documentation from code comments
} \name Encoder {
connect(...)
bool ofArduino::connect(const string &device, int baud=57600)
opens a serial port connection to the arduino
Documentation from code comments
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
disconnect()
void ofArduino::disconnect()
closes the serial port connection. Does not turn the Arduino off.
getAnalog(...)
int ofArduino::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.
getAnalogPinReporting(...)
int ofArduino::getAnalogPinReporting(int pin)
returns ARD_ON, ARD_OFF
Documentation from code comments
Returns: ARD_ON
or ARD_OFF
getDigital(...)
int ofArduino::getDigital(int pin)
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
}
Documentation from code comments
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
getDigitalPinMode(...)
int ofArduino::getDigitalPinMode(int pin)
returns ARD_INPUT, ARD_OUTPUT, ARD_PWM, ARD_SERVO, ARD_ANALOG
Documentation from code comments
Get the pin mode of the given pin
Returns: ARD_INPUT
, ARD_OUTPUT
, ARD_PWM
, ARD_SERVO
, ARD_ANALOG
getInvertedValueFromTwo7bitBytes(...)
int ofArduino::getInvertedValueFromTwo7bitBytes(unsigned char lsb, unsigned char msb)
getPwm(...)
int ofArduino::getPwm(int pin)
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
Documentation from code comments
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
isInitialized()
bool ofArduino::isInitialized()
returns true if a succesfull connection has been established and the Arduino has reported a firmware
sendByte(...)
void ofArduino::sendByte(unsigned char byte)
sends a byte without wrapping it in a firmata message, data has to be in the 0-127 range, values > 127 will be interpreted as commands.
sendDigital(...)
void ofArduino::sendDigital(int pin, int value, bool force=false)
Documentation from code comments
} \name Senders {
sendDigitalPinMode(...)
void ofArduino::sendDigitalPinMode(int pin, int mode)
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
Documentation from code comments
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
sendI2CConfig(...)
void ofArduino::sendI2CConfig(int delay)
Documentation from code comments
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 ofArduino::sendI2CReadRequest(char address, int numBytes, int reg)
Documentation from code comments
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 ofArduino::sendI2CWriteRequest(char slaveAddress, char *bytes, int numOfBytes, int reg)
sendI2CWriteRequest(...)
void ofArduino::sendI2CWriteRequest(char slaveAddress, const char *bytes, int numOfBytes, int reg)
sendI2CWriteRequest(...)
void ofArduino::sendI2CWriteRequest(char slaveAddress, unsigned char *bytes, int numOfBytes, int reg)
Documentation from code comments
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
sendI2ContinuousReadRequest(...)
void ofArduino::sendI2ContinuousReadRequest(char address, int numBytes, int reg)
Documentation from code comments
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 ofArduino::sendOneWireAlarmsSearch(int pin)
Documentation from code comments
Searches for 1-wire devices on the bus in an alarmed state.
Parameters:
pin
sendOneWireConfig(...)
void ofArduino::sendOneWireConfig(int pin, bool enableParasiticPower)
Documentation from code comments
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 ofArduino::sendOneWireDelay(int pin, unsigned int delay)
Documentation from code comments
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 ofArduino::sendOneWireRead(int pin, int devices, int numBytesToRead)
Documentation from code comments
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 ofArduino::sendOneWireRequest(int pin, unsigned char subcommand, int devices, int numBytesToRead, unsigned char correlationId, unsigned int delay, int dataToWrite)
sendOneWireReset(...)
void ofArduino::sendOneWireReset(int pin)
Documentation from code comments
Resets all devices on the bus.
Parameters:
pin
sendOneWireSearch(...)
void ofArduino::sendOneWireSearch(int pin)
Documentation from code comments
Searches for 1-wire devices on the bus.
Parameters:
pin
sendOneWireWrite(...)
void ofArduino::sendOneWireWrite(int pin, int devices, int data)
Documentation from code comments
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 ofArduino::sendOneWireWriteAndRead(int pin, int devices, int data, int numBytesToRead)
Documentation from code comments
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
sendPwm(...)
void ofArduino::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 ofArduino::sendReset()
This will cause your Arduino to reset and boot into the program again.
sendSerialConfig(...)
void ofArduino::sendSerialConfig(Firmata_Serial_Ports portID, int baud, int rxPin, int txPin)
Documentation from code comments
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
sendStepper2Wire(...)
void ofArduino::sendStepper2Wire(int dirPin, int stepPin, int stepsPerRev=200)
Documentation from code comments
-- stepper
sendStepper4Wire(...)
void ofArduino::sendStepper4Wire(int pin1, int pin2, int pin3, int pin4, int stepsPerRev=200)
Documentation from code comments
the pins has to have a stepper attached
sendStepperMove(...)
void ofArduino::sendStepperMove(int stepperID, int direction, int steps, int speed=0, float acceleration, float deceleration)
Documentation from code comments
the pins has to have a stepper attached
sendString(...)
void ofArduino::sendString(string str)
firmata can not handle strings longer than 12 characters.
Documentation from code comments
Send a string to the Arduino \note Firmata can not handle strings longer than 12 characters.
serialClose(...)
void ofArduino::serialClose(Firmata_Serial_Ports portID)
Documentation from code comments
Close the specified serial port.
Parameters:
portId The serial port to close.
serialFlush(...)
void ofArduino::serialFlush(Firmata_Serial_Ports portID)
Documentation from code comments
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 ofArduino::serialListen(Firmata_Serial_Ports portID)
Documentation from code comments
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 ofArduino::serialRead(Firmata_Serial_Ports port, int maxBytesToRead)
Documentation from code comments
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 ofArduino::serialStop(Firmata_Serial_Ports portID)
Documentation from code comments
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 ofArduino::serialWrite(Firmata_Serial_Ports port, unsigned char *bytes, int numOfBytes)
Documentation from code comments
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.
update()
void ofArduino::update()
polls data from the serial port, this has to be called periodically
Last updated Tuesday, 19 November 2024 17:24:44 UTC - 2537ee49f6d46d5fe98e408849448314fd1f180e
If you have any doubt about the usage of this module you can ask in the forum.
If you want to contribute better documentation or start documenting this section you can do so here
If you find anything wrong with this docs you can report any error by opening an issue