Arduino package: Difference between revisions
No edit summary |
|||
(5 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
The {{Forge|arduino}} package is part of the [[Octave Forge]] project and provides an Octave look-alike implementation of the Arduino extension for Matlab. | The {{Forge|arduino}} package is part of the [[Octave Forge]] project and provides an Octave look-alike implementation of the Arduino extension for Matlab. | ||
The package currently supports the following boards: | |||
* uno | |||
* nano | |||
* promini | |||
* promicro | |||
* mega2560 | |||
* leonardo | |||
* micro | |||
* lilypad | |||
* uno wifi rev2 | |||
* sparkfunsamd21 | |||
* nano every | |||
= Installation = | = Installation = | ||
Line 10: | Line 24: | ||
== octave installation == | == octave installation == | ||
From octave | From octave command line: | ||
>> pkg install -forge arduino | >> pkg install -forge arduino | ||
Line 24: | Line 38: | ||
In order to use the arduino hardware with the toolkit, it must be programmed with special firmware. | In order to use the arduino hardware with the toolkit, it must be programmed with special firmware. | ||
From octave | From octave command line: | ||
>> arduinosetup | >> arduinosetup | ||
Line 40: | Line 54: | ||
>> arduinosetup('arduinobinary', '/path_to_the_installed_arduino/arduino') | >> arduinosetup('arduinobinary', '/path_to_the_installed_arduino/arduino') | ||
More specifically on MacOS: | |||
>> arduinosetup('arduinobinary', '/Applications/Arduino.app/Contents/MacOS/Arduino') | |||
== Connecting to an Arduino == | == Connecting to an Arduino == | ||
Line 87: | Line 105: | ||
The full code, with the LED controlled in a loop ti turn it on/off each second is in the following example: | The full code, with the LED controlled in a loop ti turn it on/off each second is in the following example: | ||
ar = arduino; | |||
led_pin = "d13"; | led_pin = "d13"; | ||
while true | while true | ||
Line 95: | Line 113: | ||
pause (0.5) | pause (0.5) | ||
endwhile | endwhile | ||
= Documentation = | = Documentation = |
Latest revision as of 20:37, 1 July 2022
The arduino package is part of the Octave Forge project and provides an Octave look-alike implementation of the Arduino extension for Matlab.
The package currently supports the following boards:
- uno
- nano
- promini
- promicro
- mega2560
- leonardo
- micro
- lilypad
- uno wifi rev2
- sparkfunsamd21
- nano every
Installation[edit]
package requirements[edit]
This package requires Octave 4.0 or later.
It needs the Arduino IDE to be installed and functioning on the computer in order to program Arduino boards, however does not need it to control boards that have already been programmed.
The Arduino package also requires the instrument-control package to be installed.
octave installation[edit]
From octave command line:
>> pkg install -forge arduino
Using it[edit]
Load it before any usage:
>> pkg load arduino
Arduino board hardware setup[edit]
In order to use the arduino hardware with the toolkit, it must be programmed with special firmware.
From octave command line:
>> arduinosetup
A temporary Arduino project will be created, with the Arduino toolkit files copied to it and the Arduino IDE will open.
Set the board type and port correctly for the connected Arduino and press the upload button on the IDE.
The sources will be compiled and then uploaded to the connected arduino board.
After successful upload the Arduino IDE should be closed.
NOTE: on some versions of Ubuntu, the default installed Arduino IDE / java interface is broken so that the IDE will not detect the serial port and allow the board to be programmed. The solution is installed the Arduino ide as a flatpack, or manually. The Arduino binary must be added to the path in order to be found by arduinosetup. Alternatively, the full path/binary for the ide can be specified to arduinosetup.
>> arduinosetup('arduinobinary', '/path_to_the_installed_arduino/arduino')
More specifically on MacOS:
>> arduinosetup('arduinobinary', '/Applications/Arduino.app/Contents/MacOS/Arduino')
Connecting to an Arduino[edit]
Assuming a single arduino device is connected to the computer, creating an arduino object with no arguments will find the connected arduino and connect to it:
>> a = arduino;
Where multiple arduinos may be connected to the computer, a specific board can be connected by specifying the name of the port it is connected to:
>> ar = arduino("/dev/ttyACM0")
To list the ports of all programmed available arduinos, the scanForArduinos function can be used:
>> scanForArduinos
This will list information on each detected (programmed with firmware) Arduino board found.
Simple example[edit]
The following example shows very basic control of the Arduino package to blink the inbuilt LED.
1. load the Arduino package (if not already done)
>> pkg load arduino
2. create an arduino object
>> a = arduino;
3. what pin is the inbuild LED on? On Uno boards, D13.
>> led_pin = "d13";
4. turn LED off.
>> writeDigitalPin (a, led_pin, 0);
5. turn LED on.
>> writeDigitalPin (a, led_pin, 1);
The full code, with the LED controlled in a loop ti turn it on/off each second is in the following example:
ar = arduino; led_pin = "d13"; while true writeDigitalPin (ar, led_pin, 0); pause (0.5) writeDigitalPin (ar, led_pin, 1); pause (0.5) endwhile
Documentation[edit]
Documentation and reference for the Arduino package is available as:
- The Online manual