11Arduino Octave
22==============
33A class to control an Arduino board using the Firmata protocol.
4- I kept most functions identical to Matlab's version for compatibility.
54
6- The StandardFirmata.ino firmware needs to be loaded to your development board.
7- Serial communication is the only form possible right now.
5+ Note that any time a pin is specified, it must be of the form 'D#' or
6+ 'A#'. For example, to use digital pin 11 you must type 'D11'.
7+
8+ The standard Firmata functionality must be uploaded to use this.
9+ If you're unsure what needs to be there, just upload StandardFirmata
10+ for serial and StandardFirmataWifi (with wifi credential set) for TCP/IP.
811
912To install, download the latest release from the release page.
10- Start Octave, and move to the folder it the file is saved in.
11- Type ` pkg install arduino.tar.gz `
13+ Start Octave, and move to the folder the file is saved in.
14+ Type ` pkg install arduino.tar.gz ` into Octave's command window.
1215It requires instrument-control package to run from Forge.
13- To install that, type ` pkg install -forge instrument-control `
16+ To install that, type ` pkg install -forge instrument-control ` .
1417
15- Additional features will be added later.
16- version 1.0.0
18+ version 1.1.0
19+ To do: add I2C interface
1720
1821Table of Contents
1922=================
2023* [ Initialization] ( #initialization )
21- * [ arduino] ( #arduinoport-board-voltage " arduino(Port, Board, Voltage) " )
24+ * [ arduino] ( #arduino )
2225* [ General Commands] ( #general-commands )
23- * [ configurePin] ( #configurepinobj-pin-mode " configurePin(obj, pin, mode) ")
24- * [ readDigitalPin] ( #readdigitalpinobj-pin " readDigitalPin(obj, pin) ")
25- * [ writeDigitalPin] ( #writedigitalpinobj-pin-val " writeDigitalPin(obj, pin, val) ")
26- * [ readVoltage] ( #readvoltageobj-pin " readVoltage(obj, pin) ")
26+ * [ configurePin] ( #configurepinard-pin-mode )
27+ * [ readDigitalPin] ( #readdigitalpinard-pin )
28+ * [ writeDigitalPin] ( #writedigitalpinard-pin-val )
29+ * [ readVoltage] ( #readvoltageard-pin )
30+ * [ writePWMDutyCycle] ( #writepwmdutycycleard-pin-duty )
31+ * [ writePWMVoltage] ( #writepwmvoltageard-pin-volt )
32+ * [ Version History] ( #version-history )
2733
2834Initialization
2935==============
3036
31- arduino(Port, Board, Voltage )
37+ arduino()
3238-----------------------------
33- Starts the class. All parameters are optional, the serial port should be automatically found
34- (only tested on Linux). Board is to keep compatibility with Matlab and to help determine the
35- maximum voltage. Voltage is a way to manually set the maximum voltage (5V on Uno, 3.3 on ESP32, etc).
36- Note that Voltage is not compatible with Matlab.
39+ or:
40+ #### arduino(port)
41+ #### arduino('',board)
42+ #### arduino(port,board)
43+ #### arduino(ip_address)
44+ #### arduino(ip_address,board)
45+ #### arduino(ip_address,board,tcpipport)
46+ #### arduino(ip_address,'',tcpipport)
47+
48+ Open connection with a microcontroller using the Firmata protocol over serial or TCP/IP (internet).
49+
50+ ` port ` - the serial port, string.
51+ ` board ` - the name of the microcontroller, string.
52+ ` ip_address ` - the ip address, string.
53+ ` tcpipport ` - the tcp/ip port, int.
3754
38- Returns the arduino object (used for every other function).
55+ If ` port ` is left out or an empty string, this will attempt to use the first available serial port.
56+ If ` board ` is left out or an empty string, this will try to guess the board using the pins.
57+ If the mapping doesn't match any known board, it will default to 'Generic 5V'.
58+ If ` tcpipport ` is left out, it will default to the Firmata default of 3030.
3959
40- If this is run without a parenthese (;) at the end, it will display the
41- serial port, board name (defaults to 'Uno'), all available digital and analog pins,
42- and the max voltage value being used with voltage functions.
60+ Note that the Firmata protocol does not specify the maximum voltage that boards read.
61+ If the correct voltage is not found automatically, use 'Generic 5V', 'Generic 3.3V', or 'Generic 1.8V' for ` board ` .
62+
63+ Known ` board ` names: 'Uno', 'Nano', 'Teensy 2.0', 'Teensy 2.0 3.3V', 'MKR1000', 'ESP8266',
64+ 'Generic 5V', 'Generic 3.3V', 'Generic 1.8V'. If an unknown board is specified,
65+ the voltage will default to 5V.
66+
67+ Returns the Arduino object.
4368
4469General Commands
4570================
4671
47- configurePin(obj , pin, mode)
72+ configurePin(ard , pin, mode)
4873----------------------------
49- If the ` mode ` is specified, this will set the desired pin to that mode. If not, it simply
50- returns the mode already on the pin.
74+ If the ` mode ` is specified, this will set the desired ` pin ` to that mode. If not, it simply
75+ returns the mode already on the pin. Note that this does not check that the
76+ pin is compatible with that mode.
5177
5278| ` Mode ` |
5379| ------------------|
@@ -63,29 +89,72 @@ returns the mode already on the pin.
6389| 'Encoder' |
6490| 'Unset' |
6591
66- readDigitalPin(obj , pin)
92+ readDigitalPin(ard , pin)
6793------------------------
68- Reads the value of a digital pin. This can also be used on analog pins.
94+ Reads the value of a digital ` pin ` . This can also be used on analog pins.
6995It will automatically set the pin mode if it is not 'DigitalInput' or 'Pullup'.
7096
71- Returns ` [val,err] ` where val is 1 or 0, err is 1 if an error occured during the process.
72- Note that err is not compatible with Matlab.
97+ Returns 1 if high, 0 if low.
7398
74- writeDigitalPin(obj , pin, val)
99+ writeDigitalPin(ard , pin, val)
75100------------------------------
76101Writes a value to a pin. This can also be used on analog pins.
77102It will automatically set the pin mode if it is not 'DigitalOutput'.
78103
79-
80- readVoltage(obj, pin)
104+ readVoltage(ard, pin)
81105---------------------
82- Reads the voltage on an analog pin. It will automatically
106+ Reads the voltage on an analog ` pin ` . It will automatically
83107set the pin mode if it is not 'AnalogInput'.
84108
85- The output value will be scaled from 0-1023 to 0-5V. Note that this is an
86- approximation, and the actual maximum voltage will not be 5V without a good
87- power supply.
109+ The output value will be scaled from 0-1023 to the estimated maximum voltage.
110+ The estimated max voltage is found at the start, see [ above] ( #arduino ) .
111+
112+ Returns the approximate voltage.
113+
114+ writePWMDutyCycle(ard, pin, duty)
115+ ---------------------------------
116+ Sets a PWM duty cycle for the desired ` pin ` . Note that this does not
117+ check if the pin is PWM compatible. If the pin's mode is not 'PWM', it will
118+ change it to that.
119+
120+ ` duty ` is a value between 0 and 1. For example, 0.25 turns on the pin for
121+ 25% of the time.
122+
123+ writePWMVoltage(ard, pin, volt)
124+ -------------------------------
125+ Sets a ` pin ` PWM duty cycle relative to the maximum voltage of the board. For example,
126+ if the board has a 5V max, setting ` volt ` to 5 will set the duty cycle to max.
127+
128+ Trying to use a duty cycle higher than the board voltage will output the max duty.
129+
130+ Version History
131+ ===============
132+
133+ Version 1.1.0
134+ -------------
135+ Tested on Octave 4.0.3, Linux kernel 3.18, Firmata 2.5.7.
136+
137+ Added TCP/IP interface, tested with Espressif ESP8266 and Arduino MKR1000.
138+
139+ Added 'help' features (try typing ` help arduino ` ) for every available function.
140+
141+ Can now print information about the class object, such as the available pins,
142+ reference voltage, and the name of the sketch running on the board.
143+
144+ Every function is now compatible with Matlab (sorry if this breaks anything).
145+
146+ New functions:
147+ writePWMDutyCycle, writePWMVoltage
148+
149+ Version 1.0.0
150+ -------------
151+ Tested on Octave 4.0.2, Linux kernel 3.18, Firmata 2.5.1.
152+
153+ First version. Tested with Arduino Uno, Arduino Nano, Teensy 2.0.
154+
155+ Added serial interface. Will scan for first open port if not specified.
156+
157+ Some optional parameters differ from Matlab's.
88158
89- Returns ` [volt,value,err] ` where volt is the approximate voltage, value is the
90- raw value (0-1023), and err is 1 if an error occured during the process.
91- Note that only volt is compatible with Matlab.
159+ New functions:
160+ arduino, configurePin, readDigitalPin, writeDigitalPin, readVoltage
0 commit comments