reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

ofArduino.h
Go to the documentation of this file.
1/*
2 * Copyright 2007-2008 (c) Erik Sjodin, eriksjodin.net
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use,
8 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following
11 * conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25#pragma once
26
27#include "ofEvents.h"
28#include "ofSerial.h"
29#include "ofConstants.h"
30#include <list>
31#include <map>
32
33 /* Version numbers for the protocol. The protocol is still changing, so these
34 * version numbers are important. This number can be queried so that host
35 * software can test whether it will be compatible with the currently
36 * installed firmware. */
37#define FIRMATA_MAJOR_VERSION 2 // for non-compatible changes
38#define FIRMATA_MINOR_VERSION 5 // for backwards compatible changes
39#define FIRMATA_BUGFIX_VERSION 0 // for bugfix releases
40
41#define FIRMATA_MAX_DATA_BYTES 64 // max number of data bytes in incoming messages
42
43 // message command bytes (128-255/0x80-0xFF)
44#define DIGITAL_MESSAGE 0x90 // send data for a digital port (collection of 8 pins)
45#define ANALOG_MESSAGE 0xE0 // send data for an analog pin (or PWM)
46#define REPORT_ANALOG 0xC0 // enable analog input by pin #
47#define REPORT_DIGITAL 0xD0 // enable digital input by port pair
48 //
49#define SET_PIN_MODE 0xF4 // set a pin to INPUT/OUTPUT/PWM/etc
50#define SET_DIGITAL_PIN_VALUE 0xF5 // set value of an individual digital pin
51 //
52#define REPORT_VERSION 0xF9 // report protocol version
53#define SYSTEM_RESET 0xFF // reset from MIDI
54 //
55#define START_SYSEX 0xF0 // start a MIDI Sysex message
56#define END_SYSEX 0xF7 // end a MIDI Sysex message
57
58 // extended command set using sysex (0-127/0x00-0x7F)
59 /* 0x00-0x0F reserved for user-defined commands */
60#define SERIAL_MESSAGE 0x60 // communicate with serial devices, including other boards
61#define ENCODER_DATA 0x61 // reply with encoders current positions
62#define SERVO_CONFIG 0x70 // set max angle, minPulse, maxPulse, freq
63#define STRING_DATA 0x71 // a string message with 14-bits per char
64#define STEPPER_DATA 0x72 // control a stepper motor
65#define ONEWIRE_DATA 0x73 // send an OneWire read/write/reset/select/skip/search request
66#define SHIFT_DATA 0x75 // a bitstream to/from a shift register
67#define I2C_REQUEST 0x76 // send an I2C read/write request
68#define I2C_REPLY 0x77 // a reply to an I2C read request
69#define I2C_CONFIG 0x78 // config I2C settings such as delay times and power pins
70#define EXTENDED_ANALOG 0x6F // analog write (PWM, Servo, etc) to any pin
71#define PIN_STATE_QUERY 0x6D // ask for a pin's current mode and value
72#define PIN_STATE_RESPONSE 0x6E // reply with pin's current mode and value
73#define CAPABILITY_QUERY 0x6B // ask for supported modes and resolution of all pins
74#define CAPABILITY_RESPONSE 0x6C // reply with supported modes and resolution
75#define ANALOG_MAPPING_QUERY 0x69 // ask for mapping of analog to pin numbers
76#define ANALOG_MAPPING_RESPONSE 0x6A // reply with mapping info
77#define REPORT_FIRMWARE 0x79 // report name and version of the firmware
78#define SAMPLING_INTERVAL 0x7A // set the poll rate of the main loop
79#define SCHEDULER_DATA 0x7B // send a createtask/deletetask/addtotask/schedule/querytasks/querytask request to the scheduler
80#define SYSEX_NON_REALTIME 0x7E // MIDI Reserved for non-realtime messages
81#define SYSEX_REALTIME 0x7F // MIDI Reserved for realtime messages
82
83 // pin modes
84#define ARD_INPUT 0x00 // defined in Arduino.h
85#define ARD_OUTPUT 0x01 // defined in Arduino.h
86#define ARD_ANALOG 0x02 // analog pin in analogInput mode
87#define ARD_PWM 0x03 // digital pin in PWM output mode
88#define ARD_SERVO 0x04 // digital pin in Servo output mode
89#define ARD_SHIFT 0x05 // shiftIn/shiftOut mode
90#define ARD_I2C 0x06 // pin included in I2C setup
91#define ARD_ONEWIRE 0x07 // pin configured for 1-wire
92#define ARD_STEPPER 0x08 // pin configured for stepper motor
93#define ARD_ENCODER 0x09 // pin configured for rotary encoders
94#define ARD_SERIAL 0x0A // pin configured for serial communication
95#define ARD_INPUT_PULLUP 0x0B // enable internal pull-up resistor for pin
96#define ARD_IGNORE 0x7F // pin configured to be ignored by digitalWrite and capabilityResponse
97#define TOTAL_PIN_MODES 13
98
99//Stepper Subcommands
100#define MAX_STEPPERS 6 // arbitrary value... may need to adjust
101#define STEPPER_CONFIG 0
102#define STEPPER_STEP 1
103
104//Onewire Subcommands:
105#define ONEWIRE_SEARCH_REQUEST 0x40
106#define ONEWIRE_CONFIG_REQUEST 0x41
107#define ONEWIRE_SEARCH_REPLY 0x42
108#define ONEWIRE_READ_REPLY 0x43
109#define ONEWIRE_SEARCH_ALARMS_REQUEST 0x44
110#define ONEWIRE_SEARCH_ALARMS_REPLY 0x45
111
112#define ONEWIRE_RESET_REQUEST_BIT 0x01
113#define ONEWIRE_SKIP_REQUEST_BIT 0x02
114#define ONEWIRE_SELECT_REQUEST_BIT 0x04
115#define ONEWIRE_READ_REQUEST_BIT 0x08
116#define ONEWIRE_DELAY_REQUEST_BIT 0x10
117#define ONEWIRE_WRITE_REQUEST_BIT 0x20
118
119#define ONEWIRE_WITHDATA_REQUEST_BITS 0x3C
120
121//default value for power:
122#define ONEWIRE_POWER 1
123
124//I2C Subcommands
125#define I2C_WRITE B00000000
126#define I2C_READ B00001000
127#define I2C_READ_CONTINUOUSLY B00010000
128#define I2C_STOP_READING B00011000
129#define I2C_READ_WRITE_MODE_MASK B00011000
130#define I2C_10BIT_ADDRESS_MODE_MASK B00100000
131#define I2C_END_TX_MASK B01000000
132#define I2C_STOP_TX 1
133#define I2C_RESTART_TX 0
134#define I2C_MAX_QUERIES 8
135#define I2C_REGISTER_NOT_SPECIFIED -1
136
137//Encoder Subcommands
138#define MAX_ENCODERS 5 // arbitrary value, may need to adjust
139#define ENCODER_ATTACH 0x00
140#define ENCODER_REPORT_POSITION 0x01
141#define ENCODER_REPORT_POSITIONS 0x02
142#define ENCODER_RESET_POSITION 0x03
143#define ENCODER_REPORT_AUTO 0x04
144#define ENCODER_DETACH 0x05
145#define ENCODER_DIRECTION_MASK 0x40 // B01000000
146#define ENCODER_CHANNEL_MASK 0x3F // B00111111
147
148//Serial Subcommands
149#define SERIAL_CONFIG 0x10
150#define SERIAL_WRITE 0x20
151#define SERIAL_READ 0x30
152#define SERIAL_REPLY 0x40
153#define SERIAL_CLOSE 0x50
154#define SERIAL_FLUSH 0x60
155#define SERIAL_LISTEN 0x70
156
157// OF specific settings
158//these are given by the capability query
159//#define ARD_TOTAL_DIGITAL_PINS 70 // total number of pins currently supported
160//#define ARD_TOTAL_ANALOG_PINS 6
161#define ARD_TOTAL_PORTS 15 // total number of ports for the board
162
163#define ARD_HIGH 1
164#define ARD_LOW 0
165#define ARD_ON 1
166#define ARD_OFF 0
167
168#define OF_ARDUINO_DELAY_LENGTH 4.0
169
171 bool inputSupported = false;
172 bool outputSupported = false;
173 bool analogSupported = false;
174 bool pwmSupported = false;
175 bool servoSupported = false;
176 bool i2cSupported = false;
177 bool serialSupported = false;
178 bool onewireSupported = false;
179 bool stepperSupported = false;
180 bool encoderSupported = false;
181};
182
196
202
213
216 int reg;
217 std::string data;
218};
219
225
227 int id;
228 int type;
229 int data;
230};
231
236
248
253
274
275public:
278
279 ofArduino();
280
281 virtual ~ofArduino();
282
286
291 bool connect(const std::string & device, int baud = 57600);
292
295 bool isInitialized() const;
296
297 bool isArduinoReady();
298
301 void disconnect();
302
306
308 void update();
309
313
320 void sendDigitalPinMode(int pin, int mode);
321
322 void sendAnalogPinReporting(int pin, int mode);
323
324 void setUseDelay(bool bDelay);
325
326 void setDigitalHistoryLength(int length);
327 void setAnalogHistoryLength(int length);
328 void setStringHistoryLength(int length);
329 void setSysExHistoryLength(int nSysEx);
330
334
335 void sendDigital(int pin, int value, bool force = false);
336
337 void sendPwm(int pin, int value, bool force = false);
338
339 void sendSysEx(int command, std::vector <unsigned char> data);
340
341 bool isAttached();
342
343
344
347 void sendString(std::string str);
348
350
352
354
356
358
359 void sendPinStateQuery(int pin);
360
362 void sendReset();
363
365 void sendSysExBegin();
366
368 void sendSysExEnd();
369
374 void sendByte(unsigned char byte);
375
383 void sendValueAsTwo7bitBytes(int value);
384
388
395 int getPwm(int pin) const;
396
411 int getDigital(int pin) const;
412
418 int getAnalog(int pin) const;
419
421 std::vector <unsigned char> getSysEx() const;
422
424 std::string getString() const;
425
427 int getMajorFirmwareVersion() const;
428
430 int getMinorFirmwareVersion() const;
431
433 std::string getFirmwareName() const;
434
440 std::list <int> * getDigitalHistory(int pin);
441
444 std::list <int> * getAnalogHistory(int pin);
445
447 std::list <std::vector <unsigned char> > * getSysExHistory();
448
450 std::list <std::string> * getStringHistory();
451
455 int getDigitalPinMode(int pin) const;
456
458 int getAnalogPinReporting(int pin) const;
459
461 int getValueFromTwo7bitBytes(unsigned char lsb, unsigned char msb);
462
463 int getInvertedValueFromTwo7bitBytes(unsigned char lsb, unsigned char msb);
464
468
471 ofEvent <const int> EDigitalPinChanged;
472
475 ofEvent <const int> EAnalogPinChanged;
476
479 ofEvent <const std::vector <unsigned char> > ESysExReceived;
480
483 ofEvent <const int> EFirmwareVersionReceived;
484
488 ofEvent <const int> EInitialized;
489
492 ofEvent <const std::string> EStringReceived;
493
497
500
503
507
509
513
519 void sendServo(int pin, int value, bool force = false);
520
522 void sendServoAttach(int pin, int minPulse = 544, int maxPulse = 2400);
523
526 //void sendServoDetach(int pin);
527
529 int getServo(int pin) const;
530
534
536 void sendStepper2Wire(int dirPin, int stepPin, int stepsPerRev = 200);
538
539 void sendStepper4Wire(int pin1, int pin2, int pin3, int pin4, int stepsPerRev = 200);
541
542 void sendStepperMove(int stepperID, int direction, int steps, int speed = 0, float acceleration = 0, float deceleration = 0);
544
545
549
554 void sendI2CConfig(int delay);
555 bool isI2CConfigured();
556
561 void sendI2CWriteRequest(char slaveAddress, unsigned char * bytes, int numOfBytes, int reg = -1);
562 void sendI2CWriteRequest(char slaveAddress, const char * bytes, int numOfBytes, int reg = -1);
563 void sendI2CWriteRequest(char slaveAddress, char * bytes, int numOfBytes, int reg = -1);
564 void sendI2CWriteRequest(char slaveAddress, std::vector<char> bytes, int reg = -1);
565
571 void sendI2CReadRequest(char address, int numBytes, int reg = -1);
572
578 void sendI2ContinuousReadRequest(char address, int numBytes, int reg = -1);
579
583
590 void sendOneWireConfig(int pin, bool enableParasiticPower);
591
595 void sendOneWireSearch(int pin);
596
600 void sendOneWireAlarmsSearch(int pin);
601 void sendOneWireSearch(char type, int pin);
602
610 void sendOneWireRead(int pin, std::vector<unsigned char> devices, int numBytesToRead);
611
614 void sendOneWireReset(int pin);
615
622 void sendOneWireWrite(int pin, std::vector<unsigned char> devices, std::vector<unsigned char> data);
623
628 void sendOneWireDelay(int pin, unsigned int delay);
629
638 void sendOneWireWriteAndRead(int pin, std::vector<unsigned char> devices, std::vector<unsigned char> data, int numBytesToRead);
639 void sendOneWireRequest(int pin, unsigned char subcommand, std::vector<unsigned char> devices, int numBytesToRead, unsigned char correlationId, unsigned int delay, std::vector<unsigned char> dataToWrite);
640
644
645 void attachEncoder(int pinA, int pinB);
646 void getEncoderPosition(int encoderNum);
648 void resetEncoderPosition(int encoderNum);
651 void detachEncoder(int encoderNum);
652
656
663 void sendSerialConfig(Firmata_Serial_Ports portID, int baud, int rxPin, int txPin);
664
670 void serialWrite(Firmata_Serial_Ports port, unsigned char * bytes, int numOfBytes);
671
678 void serialRead(Firmata_Serial_Ports port, int maxBytesToRead);
679
684 void serialStop(Firmata_Serial_Ports portID);
685
690
696
702
703
704 std::map<int, supportedPinTypes> getPinCapabilities() { return pinCapabilities; }
705
706 int getTotalPins() { return _totalDigitalPins; }
707
708 int getNumAnalogPins() { return _totalAnalogPins; }
709
710private:
711 mutable bool _initialized;
712
713 void initPins();
714 mutable int _totalDigitalPins;
715 mutable int _totalAnalogPins;
716
717 void sendDigitalPinReporting(int pin, int mode);
718
719 void sendDigitalPortReporting(int port, int mode);
720
721 void purge();
722
723 void processData(unsigned char inputData);
724 void processDigitalPort(int port, unsigned char value);
725 virtual void processSysExData(std::vector <unsigned char> data);
726
727 ofSerial _port;
728 int _portStatus;
729
730 // --- history variables
731 int _analogHistoryLength;
732 int _digitalHistoryLength;
733 int _stringHistoryLength;
734 int _sysExHistoryLength;
735
736 // --- data processing variables
737 int _waitForData;
738 int _executeMultiByteCommand;
739 int _multiByteChannel;
740
741 // --- data holders
742 unsigned char _storedInputData[FIRMATA_MAX_DATA_BYTES];
743 std::vector <unsigned char> _sysExData;
744 int _majorFirmwareVersion;
745 int _minorFirmwareVersion;
746 std::string _firmwareName;
747
748 std::list <std::vector <unsigned char> > _sysExHistory;
749 // maintains a history of received sysEx messages (excluding SysEx messages in the extended command set)
750
751 std::list <std::string> _stringHistory;
752 // maintains a history of received strings
753
754 //we dont know the number of pintypes until we do a configuration request so just a placeholder for now
755 mutable std::vector<std::list <int> > _analogHistory;
756 // a history of received data for each analog pin
757
758 mutable std::vector<std::list <int> > _digitalHistory;
759 // a history of received data for each digital pin
760
761 mutable std::vector<int> _digitalPinMode;
762 // the modes for all digital pins
763
764 mutable std::vector<int> _digitalPinValue;
765 // the last set values (DIGITAL/PWM) on all digital pins
766
767 mutable int _digitalPortValue[ARD_TOTAL_PORTS];
768 // the last set values on all ports
769
770 mutable int _digitalPortReporting[ARD_TOTAL_PORTS];
771 // whether pin reporting is enabled / disabled
772
773 mutable std::vector<int> _digitalPinReporting;
774 // whether pin reporting is enabled / disabled
775
776 mutable std::vector<int> _analogPinReporting;
777 // whether pin reporting is enabled / disabled
778
779 bool bUseDelay;
780
781 mutable bool connected;
782
783 float connectTime;
784
785 mutable std::vector<int> _servoValue;
786 // the last set servo values
787
788 bool _i2cConfigured;
789
790 int _numSteppers;
791
792 // int _numEncoders;
793
794 int _encoderID;
795
796 int _firstAnalogPin;
797
798 bool firmataInputSupported,
799 firmataOutputSupported,
800 firmataAnalogSupported,
801 firmataPwmSupported,
802 firmataServoSupported,
803 firmataI2cSupported,
804 firmataOnewireSupported,
805 firmataStepperSupported,
806 firmataEncoderSupported,
807 firmataSerialSupported;
808
809 mutable std::map<int, supportedPinTypes> pinCapabilities;
810 mutable std::map<int, int> analogPinMap;
811
812
813 bool isAnalogPin(int pin) const;
814 bool isPin(int pin) const;
815
816 int convertAnalogPinToDigital(size_t pin) const;
817 int convertDigitalPinToAnalog(size_t pin) const;
818};
819
821
This is a way to control an Arduino that has had the firmata library loaded onto it,...
Definition ofArduino.h:273
int getTotalPins()
Definition ofArduino.h:706
ofArduino()
Definition ofArduino.cpp:62
void sendDigital(int pin, int value, bool force=false)
Definition ofArduino.cpp:287
void setDigitalHistoryLength(int length)
Definition ofArduino.cpp:183
bool isArduinoReady()
Definition ofArduino.cpp:169
void sendI2CWriteRequest(char slaveAddress, std::vector< char > bytes, int reg=-1)
void sendValueAsTwo7bitBytes(int value)
Send value as two 7 bit bytes.
Definition ofArduino.cpp:1058
void sendStepper2Wire(int dirPin, int stepPin, int stepsPerRev=200)
– stepper
Definition ofArduino.cpp:1150
std::vector< unsigned char > getSysEx() const
Definition ofArduino.cpp:272
void setAnalogHistoryLength(int length)
Definition ofArduino.cpp:189
void sendStepper4Wire(int pin1, int pin2, int pin3, int pin4, int stepsPerRev=200)
the pins has to have a stepper attached
Definition ofArduino.cpp:1184
void sendSysExBegin()
Sends the FIRMATA_START_SYSEX command.
Definition ofArduino.cpp:337
ofEvent< const Firmata_Stepper_Data > EStepperDataReceived
triggered when a stepper has finished rotating. Returns which stepper has complted its rotation
Definition ofArduino.h:496
void sendI2ContinuousReadRequest(char address, int numBytes, int reg=-1)
Initialize a continuous I2C read.
Definition ofArduino.cpp:1396
std::string getFirmwareName() const
Definition ofArduino.cpp:547
void sendOneWireDelay(int pin, unsigned int delay)
Tells firmata to not do anything for the passed amount of ms.
Definition ofArduino.cpp:1482
void setStringHistoryLength(int length)
Definition ofArduino.cpp:201
void sendOneWireAlarmsSearch(int pin)
Searches for 1-wire devices on the bus in an alarmed state.
Definition ofArduino.cpp:1447
ofEvent< const int > EInitialized
Triggered when the firmware version is received upon connect, the major firmware version is passed as...
Definition ofArduino.h:488
int getPwm(int pin) const
Returns the last set PWM value (0-255) for the given pin.
Definition ofArduino.cpp:256
void sendOneWireWriteAndRead(int pin, std::vector< unsigned char > devices, std::vector< unsigned char > data, int numBytesToRead)
Sends the passed data to the passed device on the bus, reads the specified number of bytes.
Definition ofArduino.cpp:1487
ofEvent< const int > EFirmwareVersionReceived
Triggered when a firmware version is received, the major version is passed as an argument.
Definition ofArduino.h:483
void serialClose(Firmata_Serial_Ports portID)
Close the specified serial port.
Definition ofArduino.cpp:1724
void sendOneWireSearch(int pin)
Searches for 1-wire devices on the bus.
Definition ofArduino.cpp:1443
void sendReset()
This will cause your Arduino to reset and boot into the program again.
Definition ofArduino.cpp:394
void sendDigitalPinMode(int pin, int mode)
Setting a pins mode to ARD_INPUT turns on reporting for the port the pin is on.
Definition ofArduino.cpp:412
void setUseDelay(bool bDelay)
Definition ofArduino.cpp:179
std::map< int, supportedPinTypes > getPinCapabilities()
Definition ofArduino.h:704
ofEvent< const int > EDigitalPinChanged
Triggered when a digital pin changes value, the pin that changed is passed as an argument.
Definition ofArduino.h:471
void serialListen(Firmata_Serial_Ports portID)
For SoftwareSerial only. Only a single SoftwareSerial instance can read data at a time.
Definition ofArduino.cpp:1738
void setSysExHistoryLength(int nSysEx)
Definition ofArduino.cpp:195
std::string getString() const
Definition ofArduino.cpp:276
void sendOneWireWrite(int pin, std::vector< unsigned char > devices, std::vector< unsigned char > data)
Writes data to the bus to be received by the passed device.
Definition ofArduino.cpp:1478
ofEvent< const Firmata_I2C_Data > EI2CDataRecieved
triggered when the I2C bus returns data after a read request
Definition ofArduino.h:499
void sendAnalogMappingRequest()
Definition ofArduino.cpp:379
void sendSysExEnd()
Sends the FIRMATA_END_SYSEX command.
Definition ofArduino.cpp:341
void sendI2CReadRequest(char address, int numBytes, int reg=-1)
Asks the arduino to request bytes from an I2C device.
Definition ofArduino.cpp:1378
bool connect(const std::string &device, int baud=57600)
Opens a serial port connection to the arduino.
Definition ofArduino.cpp:159
void disconnect()
Closes the serial port connection. Does not turn the Arduino off.
Definition ofArduino.cpp:207
int getAnalogPinReporting(int pin) const
Definition ofArduino.cpp:499
void sendOneWireRequest(int pin, unsigned char subcommand, std::vector< unsigned char > devices, int numBytesToRead, unsigned char correlationId, unsigned int delay, std::vector< unsigned char > dataToWrite)
Definition ofArduino.cpp:1493
void sendProtocolVersionRequest()
Definition ofArduino.cpp:356
void sendI2CConfig(int delay)
Sends a I2C config request.
Definition ofArduino.cpp:1286
void sendPinCapabilityRequest()
Definition ofArduino.cpp:373
void sendFirmwareVersionRequest()
Definition ofArduino.cpp:360
void serialWrite(Firmata_Serial_Ports port, unsigned char *bytes, int numOfBytes)
Write an array of bytes to the specified serial port.
Definition ofArduino.cpp:1693
void detachEncoder(int encoderNum)
Definition ofArduino.cpp:1642
void update()
Polls data from the serial port, this has to be called periodically.
Definition ofArduino.cpp:211
std::list< std::string > * getStringHistory()
Definition ofArduino.cpp:535
void disableEncoderReporting()
Definition ofArduino.cpp:1635
void sendServo(int pin, int value, bool force=false)
Send a value to a servo.
Definition ofArduino.cpp:1097
void sendServoAttach(int pin, int minPulse=544, int maxPulse=2400)
Definition ofArduino.cpp:1080
std::list< int > * getAnalogHistory(int pin)
Returns a pointer to the analog data history list for the given pin.
Definition ofArduino.cpp:512
int getValueFromTwo7bitBytes(unsigned char lsb, unsigned char msb)
Useful for parsing SysEx messages.
Definition ofArduino.cpp:1064
virtual ~ofArduino()
Definition ofArduino.cpp:109
int getMinorFirmwareVersion() const
Definition ofArduino.cpp:543
bool isAttached()
Definition ofArduino.cpp:555
void enableEncoderReporting()
Definition ofArduino.cpp:1628
void sendStepperMove(int stepperID, int direction, int steps, int speed=0, float acceleration=0, float deceleration=0)
the pins has to have a stepper attached
Definition ofArduino.cpp:1238
void resetEncoderPosition(int encoderNum)
Definition ofArduino.cpp:1619
void sendString(std::string str)
Send a string to the Arduino.
Definition ofArduino.cpp:345
void sendSysEx(int command, std::vector< unsigned char > data)
Definition ofArduino.cpp:326
void sendByte(unsigned char byte)
Sends a byte without wrapping it in a firmata message.
Definition ofArduino.cpp:1052
void attachEncoder(int pinA, int pinB)
Definition ofArduino.cpp:1577
void sendOneWireRead(int pin, std::vector< unsigned char > devices, int numBytesToRead)
Reads data from a device on the bus.
Definition ofArduino.cpp:1467
void sendSerialConfig(Firmata_Serial_Ports portID, int baud, int rxPin, int txPin)
Asks the Arduino to configure a hardware or serial port.
Definition ofArduino.cpp:1668
int getServo(int pin) const
Detaches a servo on a pin.
Definition ofArduino.cpp:1126
void serialStop(Firmata_Serial_Ports portID)
Stop continuous reading of the specified serial port.
Definition ofArduino.cpp:1716
void getAllEncoderPositions()
Definition ofArduino.cpp:1613
ofEvent< const std::vector< Firmata_Encoder_Data > > EEncoderDataReceived
triggered when the encoder returns data after a read request
Definition ofArduino.h:502
int getDigitalPinMode(int pin) const
Get the pin mode of the given pin.
Definition ofArduino.cpp:280
void serialFlush(Firmata_Serial_Ports portID)
Flush the specified serial port.
Definition ofArduino.cpp:1731
void sendOneWireConfig(int pin, bool enableParasiticPower)
Configure the passed pin as the controller in a 1-wire bus.
Definition ofArduino.cpp:1427
ofEvent< const std::vector< unsigned char > > ESysExReceived
Triggered when a SysEx message that isn't in the extended command set is received,...
Definition ofArduino.h:479
ofEvent< const Firmata_Serial_Data > ESerialDataReceived
triggered when a Serial message is received. Returns which port and its data
Definition ofArduino.h:506
void sendPinStateQuery(int pin)
Definition ofArduino.cpp:386
void sendAnalogPinReporting(int pin, int mode)
Definition ofArduino.cpp:398
int getNumAnalogPins()
Definition ofArduino.h:708
void serialRead(Firmata_Serial_Ports port, int maxBytesToRead)
Start continuous reading of the specified serial port.
Definition ofArduino.cpp:1703
int getAnalog(int pin) const
Returns the analog in value that the pin is currently reading. because the Arduino has a 10 bit ADC y...
Definition ofArduino.cpp:224
std::list< int > * getDigitalHistory(int pin)
Returns a pointer to the digital data history list for the given pin.
Definition ofArduino.cpp:524
void sendOneWireReset(int pin)
Resets all devices on the bus.
Definition ofArduino.cpp:1473
void sendI2CWriteRequest(char slaveAddress, unsigned char *bytes, int numOfBytes, int reg=-1)
Asks the arduino to send an I2C request to a device.
Definition ofArduino.cpp:1296
void getEncoderPosition(int encoderNum)
Definition ofArduino.cpp:1604
ofEvent< const std::pair< int, Firmata_Pin_Modes > > EPinStateResponseReceived
Definition ofArduino.h:508
bool isI2CConfigured()
Definition ofArduino.cpp:1413
int getInvertedValueFromTwo7bitBytes(unsigned char lsb, unsigned char msb)
Definition ofArduino.cpp:1068
ofEvent< const std::string > EStringReceived
Triggered when a string is received, the string is passed as an argument.
Definition ofArduino.h:492
void sendPwm(int pin, int value, bool force=false)
Definition ofArduino.cpp:311
int getMajorFirmwareVersion() const
Definition ofArduino.cpp:539
bool isInitialized() const
Returns true if a succesfull connection has been established and the Arduino has reported a firmware.
Definition ofArduino.cpp:551
void sendPinCofigurationRequest()
Definition ofArduino.cpp:367
ofEvent< const int > EAnalogPinChanged
Triggered when an analog pin changes value, the pin that changed is passed as an argument.
Definition ofArduino.h:475
std::list< std::vector< unsigned char > > * getSysExHistory()
Definition ofArduino.cpp:531
int getDigital(int pin) const
Returns the last received value (if the pin mode is ARD_INPUT) or the last set value (if the pin mode...
Definition ofArduino.cpp:241
Definition ofEvent.h:444
ofSerial provides a cross platform system for interfacing with the serial port. You can choose the po...
Definition ofSerial.h:113
map< string, int > device
Definition ofAppEGLWindow.cpp:36
#define FIRMATA_MAX_DATA_BYTES
Definition ofArduino.h:41
Firmata_I2C_Modes
Definition ofArduino.h:207
@ FIRMATA_I2C_CONTINUOUS_READ
Definition ofArduino.h:210
@ FIRMATA_I2C_WRITE
Definition ofArduino.h:208
@ FIRMATA_I2C_STOP_READING
Definition ofArduino.h:211
@ FIRMATA_I2C_READ
Definition ofArduino.h:209
Firmata_Stepper_Interface
Definition ofArduino.h:197
@ FIRMATA_STEPPER_TWO_WIRE
Definition ofArduino.h:199
@ FIRMATA_STEPPER_DRIVER
Definition ofArduino.h:198
@ FIRMATA_STEPPER_FOUR_WIRE
Definition ofArduino.h:200
Firmata_Pin_Modes
Definition ofArduino.h:183
@ MODE_OUTPUT
Definition ofArduino.h:185
@ MODE_INPUT
Definition ofArduino.h:184
@ MODE_STEPPER
Definition ofArduino.h:193
@ MODE_SERIAL
Definition ofArduino.h:191
@ MODE_ANALOG
Definition ofArduino.h:187
@ MODE_PWM
Definition ofArduino.h:188
@ MODE_INPUT_PULLUP
Definition ofArduino.h:186
@ MODE_ONEWIRE
Definition ofArduino.h:192
@ MODE_I2C
Definition ofArduino.h:190
@ MODE_ENCODER
Definition ofArduino.h:194
@ MODE_SERVO
Definition ofArduino.h:189
Firmata_Stepper_Direction
Definition ofArduino.h:203
@ FIRMATA_STEPPER_CCW
Definition ofArduino.h:204
@ FIRMATA_STEPPER_CW
Definition ofArduino.h:205
#define ARD_TOTAL_PORTS
Definition ofArduino.h:161
Firmata_Serial_Modes
Definition ofArduino.h:232
@ FIRMATA_SERIAL_READ_CONTINUOUS
Definition ofArduino.h:233
@ FIRMATA_SERIAL_STOP_READING
Definition ofArduino.h:234
ofArduino ofStandardFirmata
Definition ofArduino.h:820
Firmata_Serial_Ports
ids for hardware and software serial ports on the board
Definition ofArduino.h:238
@ SW_SERIAL1
Definition ofArduino.h:244
@ HW_SERIAL3
Definition ofArduino.h:242
@ SW_SERIAL0
Definition ofArduino.h:243
@ HW_SERIAL0
Definition ofArduino.h:239
@ SW_SERIAL3
Definition ofArduino.h:246
@ SW_SERIAL2
Definition ofArduino.h:245
@ HW_SERIAL2
Definition ofArduino.h:241
@ HW_SERIAL1
Definition ofArduino.h:240
Definition ofArduino.h:220
bool direction
Definition ofArduino.h:222
int ID
Definition ofArduino.h:221
int position
Definition ofArduino.h:223
Definition ofArduino.h:214
int reg
Definition ofArduino.h:216
int address
Definition ofArduino.h:215
std::string data
Definition ofArduino.h:217
Definition ofArduino.h:249
Firmata_Serial_Ports portID
Definition ofArduino.h:250
std::string data
Definition ofArduino.h:251
Definition ofArduino.h:226
int data
Definition ofArduino.h:229
int type
Definition ofArduino.h:228
int id
Definition ofArduino.h:227
Definition ofArduino.h:170
bool onewireSupported
Definition ofArduino.h:178
bool stepperSupported
Definition ofArduino.h:179
bool outputSupported
Definition ofArduino.h:172
bool analogSupported
Definition ofArduino.h:173
bool encoderSupported
Definition ofArduino.h:180
bool servoSupported
Definition ofArduino.h:175
bool serialSupported
Definition ofArduino.h:177
bool pwmSupported
Definition ofArduino.h:174
bool inputSupported
Definition ofArduino.h:171
bool i2cSupported
Definition ofArduino.h:176