Project

General

Profile

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
  • struct ::arduio::state_s ios

    • sequence< enum ::arduio::dir_s, 64 > diodir ∈ { IO_IN, IO_IN_PU, IO_OUT, IO_PWM_31kHz, IO_PWM_122Hz, IO_PWM_31Hz, IO_WS28XX }

    • sequence< float, 64 > digital

    • sequence< float, 16 > analog

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
  • string<64> serial (default "/dev/ttyUSB0") Serial device path or serial number

Throws
  • exception ::arduio::e_sys

    • short code

    • string<128> what

  • exception ::arduio::e_baddev

    • string<256> dev

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
  • exception ::arduio::e_sys

    • short code

    • string<128> what

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
  • octet n Digital I/O pin number

  • enum ::arduio::dir_s dir (default "::arduio::IO_IN") Operation mode ∈ { IO_IN, IO_IN_PU, IO_OUT, IO_PWM_31kHz, IO_PWM_122Hz, IO_PWM_31Hz, IO_WS28XX }

Throws
  • exception ::arduio::e_sys

    • short code

    • string<128> what

  • exception ::arduio::e_baddev

    • string<256> dev

  • exception ::arduio::e_baddir

Context

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 and IO_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 for IO_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
  • octet n Digital I/O pin

  • float value State

Throws
  • exception ::arduio::e_sys

    • short code

    • string<128> what

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 and IO_IN_PU)

No effect.

Output (IO_OUT)

The pin is set low with a value of 0. Any other value sets it high.

PWM output (IO_PWM_*)

The PWM duty cycle is controlled from 0% to 100% by passing a value between 0.0 and 1.0. The value is internally converted to a 16bits integer number between 0 and 65535 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 and 65535 (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
  • sequence< float, 53 > values State

Throws
  • exception ::arduio::e_sys

    • short code

    • string<128> what

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).


Tasks

comm

Context
Throws
  • exception ::arduio::e_sys

    • short code

    • string<128> what

This task asynchronously receives all the messages sent by the hardware. It updates the ios (out) port according to the information received.


main

Context
  • Frequency 200.0 Hz

This task handles the execution of all activities and periodically asks to the hardware to report the current pin states.