arduio component
The arduio component remotely controls an Arduino™ board that runs the arduio software. It interacts with the board through its serial port, either via USB or directly via the TX/RX pins.
Each of the analog pins (labeled A#
on the hardware) can be read and the digital pins (labeled D#
) can be individually configured as a regular GPIO, or to output a PWM signal at different frequencies, or to control RGB LEDs using the WS28XX chip family.
Ports
ios (out)
Data structure
|
Digital and analog pin states.
This port is updated by the comm task and reflects the current pin states. It is not updated until a successful call to the service connect (activity) is done. Updates also stop after a disconnect (activity).
The diodir
is the currently configured digital I/O directions (see set_dir (activity)) for each digital pin (up to 16, depending on the hardware). The digital
array is the state of each digital pin. Values should be interpreted according to the description of the service out1 (function). Finally, analog
is the current state of all the analog pins. Values are in the range [0.0 - 1.0]
, where 1.0
means +Vcc
(either 3.3V or 5V).
Services
connect (activity)
Inputs
|
Throws
|
Context
|
Connect to the hardware.
This service must be called before any other useful action can be done. Before calling it, the Arduino™ should be connected. The serial
parameter should be either the pathname of the serial device, for instance /dev/ttyUSB0
, or the serial number of the serial device, for instance something like AL02YSSF
(this number is usually visible in the dmesg
of your system).
disconnect (activity)
Throws
|
Context
|
Disconnect from the hardware.
This is the opposite of connect
. After calling it, no operation on the device can be done anymore.
set_dir (activity)
Inputs
|
Throws
|
Set digital I/O pin direction.
This service configures the direction and operation mode of a GPIO pin. n
is the digital pin number and dir
is the operation mode, selected among those 4 main modes:
- Input (
IO_IN
andIO_IN_PU
) -
The GPIO is configured as input. Pullups can be activated by choosing
IO_IN_PU
, otherwise the pin is floating. The pin level can be read in the port ios (out). - Output (
IO_OUT
) -
The GPIO is configured as output. Its state is either on or off and is controlled by the services out1 (function) and out (function).
- PWM output (
IO_PWM_*
) -
The GPIO outputs a PWM signal at the correspoding frequency (e.g.
31kHz
forIO_PWM_31kHZ
). The services out1 (function) and out (function) control the duty cycle of the PWM. Not all pins can do pwm: the following table summarizes the capabilities.Pin # Frequencies Duty cycle resolution (bits) 3, 5, 6, 11
31kHz, 122Hz, 31Hz
8
9, 10
31kHz
8
122Hz
16
31Hz
15
- Digital RGB (
IO_WS28XX
) -
The GPIO controls a digital RGB LED compatible with the WS28XX chip family. Up to 16 such LEDs can be chained on each pin.
out1 (function)
Inputs
|
Throws
|
Set digital I/O pin state.
This controls the state of a GPIO previously configured with set_dir (activity). Depending on the pin mode, the value
has a different meaning:
- Input (
IO_IN
andIO_IN_PU
) -
No effect.
- Output (
IO_OUT
) -
The pin is set low with a
value
of0
. Any other value sets it high. - PWM output (
IO_PWM_*
) -
The PWM duty cycle is controlled from
0%
to100%
by passing a value between0.0
and1.0
. The value is internally converted to a 16bits integer number between0
and65535
and the actual duty cycle resolution depends on the pin number and mode. See set_dir (activity) for details. - Digital RGB (
IO_WS28XX
) -
An integer value between
0
and65535
(16 bits) should be given. Each bit is interpreted according to the following table:15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 Led #
Green
Red
Blue
For instance,
0xfff
sets LED #0 to pure white,0x1800
sets LED #1to green at 50% instensity, etc.
out (function)
Inputs
|
Throws
|
Set all digital I/O pin state
This service is a convenience service for setting all digital pins at once. An array of up to 53 values can be given, corresponding to the desired state of each pins. Values are interpreted as in the service out1 (function).