Arduino IDE libraries and examples for Iono RP D16 - the multi-purpose digital I/O module with a Raspberry Pi RP2040 (Pico) computing core.
Install the Arduino IDE version 1.8.13 or newer
Install the Raspberry Pi RP2040 Arduino core available here: https://github.com/earlephilhower/arduino-pico
- Download this repo
- Open the Arduino IDE
- Go to the menu Sketch > Include Library > Add .ZIP Library...
- Select the downloaded zip file
After installation you will see the example sketches under the menu File > Examples > Iono RP D16.
Go to the menu Tools > Board > Raspberry Pi RP2040 Boards and select "Generic RP2040" (end of the list).
You will see additional menu entries under the Tools menu, set:
- Flash size to 16MB (with or without FS);
- Boot Stage 2 to "W25Q128JV QSPI /4";
- leave the other entries unchanged.
The first time you upload a sketch:
- Remove power to Iono RP D16 (disconnect main power supply and USB)
- Hold the BOOTSEL button down
- Connect the USB cable to Iono RP D16
- Release the BOOTSEL button
Select "UF2 Board" as upload Port then hit the Arduino IDE's upload button, the sketch will be transferred and start to run.
After the first upload, the board will appear under the standard Serial ports list and will automatically reset and switch to bootloader mode when hitting the IDE's upload button as with any other Arduino boards.
For a quick start and ready-to-use applications, check out the examples.
Following some more details:
You can include the library in your sketch with:
#include <IonoD16.h>
It exports a Iono
object which has the methods described below.
It defines the constants D1
... D16
and DT1
... DT4
, corresponding to Iono RP D16's I/Os, to be used as the pin
parameter of the Iono
object methods.
A reference to the serial port connected to the RS-485 interface is available as IONO_RS485
.
Usage example:
IONO_RS485.begin(19200, SERIAL_8N1);
The TX-enable pin should be controlled when sending or receiving data on the RS-485 interface, use the rs485TxEn() method.
Call this function in your setup()
, before using any other functionality of the library. It initializes the used pins and peripherals.
true
upon success.
Useful for synchronization between the two cores.
whether or not the setup()
method has been executed.
void setup() {
Iono.setup();
// ...
}
void setup1() {
// wait for setup() to complete on the other core
while (!Iono.ready()) ;
// ...
}
Call this function periodically, with a maximum interval of 20ms. It performs the reading of the input/output peripherals' state, moreover it checks for fault conditions, enables safety routines and updates the outputs' watchdog. It is recommended to reserve one core of the RP2040 for calling this function, while performing your custom logic on the other core.
void loop1() {
Iono.process();
delay(10);
}
void loop() {
// read/write Iono's I/O and perform your other tasks
}
Initializes a pin as input or output. To be called before any other operation on the same pin.
pin
: D1
... D16
, DT1
... DT4
mode
:
INPUT
: use pin as inputOUTPUT_HS
: use pin as high-side output (only forD1
...D16
)OUTPUT_PP
: use pin as push-pull output (only forD1
...D16
)OUTPUT
: use pin as output (only forDT1
...DT4
)
wbol
: enable (true
) or disable (false
) wire-break (for inputs) or open-load (for high-side outputs) detection (only for D1
... D16
)
true
upon success.
Joins two high-side outputs to be used as a single output. Outputs can be joined in specific pairs: D1
-D2
, D3
-D4
, ..., D15
-D16
.
When a pair is joined, the other pair of the same group of four is also joined, e.g. joining D3
-D4
results in D1
-D2
being joined too if used as outputs.
Therefore, joining a pair requires the pins of the other pair of the same group of four to be initialized as OUTPUT_HS
or INPUT
. In the latter case the two pins can be used as independent inputs.
pin
: one pin of the pair: D1
... D16
join
: true
to join, false
to un-join
true
upon success.
Returns the state of a pin.
For D1
... D16
pins the returned value corresponds to the reading performed during the latest process()
call.
For DT1
... DT4
pins the returned value corresponds to the instant reading of the corresponding GPIO.
pin
: D1
... D16
, DT1
... DT4
HIGH
, LOW
, or -1
upon error.
Sets the value of an output pin.
pin
: D1
... D16
, DT1
... DT4
val
: HIGH
or LOW
true
upon success.
Flips the value of an output pin.
pin
: D1
... D16
, DT1
... DT4
true
upon success.
Returns the wire-break fault state of an input pin with wire-break detection enabled.
The fault state is updated on each process()
call and set HIGH
when detected. It is cleared (set LOW
) only after calling this method.
pin
: D1
... D16
HIGH
if wire-break detected, LOW
if wire-break not detected, or -1
upon error.
Returns the open-load fault state of an input pin with open-load detection enabled.
The fault state is updated on each process()
call and set HIGH
when detected. It is cleared (set LOW
) only after calling this method.
pin
: D1
... D16
HIGH
if open-load detected, LOW
if open-load not detected, or -1
upon error.
Returns the over-voltage fault state of a pin.
The fault state is updated on each process()
call and set HIGH
when detected. It is cleared (set LOW
) only after calling this method.
pin
: D1
... D16
HIGH
if over-voltage detected, LOW
if over-voltage not detected, or -1
upon error.
Returns whether or not an output pin is temporarily locked due to an over-voltage condition.
The output cannot be set when locked.
The fault state is updated on each process()
call and set HIGH
when detected. It is cleared (set LOW
) only after calling this method.
pin
: D1
... D16
HIGH
if locked, LOW
if not locked, or -1
upon error.
Returns the thermal shutdown fault state of a pin.
The fault state is updated on each process()
call and set HIGH
when detected. It is cleared (set LOW
) only after calling this method.
pin
: D1
... D16
HIGH
if thermal shutdown active, LOW
if thermal shutdown not active, or -1
upon error.
Returns whether or not an output pin is temporarily locked due to a thermal shutdown condition.
The output cannot be set when locked.
The fault state is updated on each process()
call and set HIGH
when detected. It is cleared (set LOW
) only after calling this method.
pin
: D1
... D16
HIGH
if locked, LOW
if not locked, or -1
upon error.
Returns whether or not the temperature alarm 1 threshold has been exceeded on the input peripheral the pin belongs to.
The state is updated on each process()
call and set HIGH
when detected. It is cleared (set LOW
) only after calling this method.
pin
: D1
... D16
HIGH
if threshold exceeded, LOW
if threshold not exceeded, or -1
upon error.
Returns whether or not the temperature alarm 2 threshold has been exceeded on the input peripheral the pin belongs to.
The state is updated on each process()
call and set HIGH
when detected. It is cleared (set LOW
) only after calling this method.
pin
: D1
... D16
HIGH
if threshold exceeded, LOW
if threshold not exceeded, or -1
upon error.
Set a callback function to be called upon input state change with a debounce filter.
The callback function is called within process()
execution, it is therefore recommended to execute only quick operations.
pin
: D1
... D16
, DT1
... DT4
debounceMs
: debounce time in milliseconds
cb
: callback function
Links the state of two pins. when the inPin
pin changes state (with the specified debounce filter), the outPin
output is set according to the specified mode.
pin
: D1
... D16
mode
:
LINK_FOLLOW
:outPin
is set to the same state ofinPin
LINK_INVERT
:outPin
is set to the opposite state ofinPin
LINK_FLIP_H
:outPin
is flipped upon each low-to-high transition ofinPin
LINK_FLIP_L
:outPin
is flipped upon each high-to-low transition ofinPin
LINK_FLIP_T
:outPin
is flipped upon each state transition ofinPin
debounceMs
: debounce time in milliseconds
Sets the blue 'ON' LED state.
on
: true
LED on, false
LED off
Sets a soft-PWM on a push-pull output.
The maximum frequency is determined by the frequency of process()
calls.
pin
: D1
... D16
freqHz
: frequency in Hz
dutyU16
: duty cycle as a ratio dutyU16 / 65535
true
upon success.
Controls the TX-enable line of the RS-485 interface.
Call Iono.serialTxEn(true)
before writing to the IONO_RS485 serial. When incoming data is expected, call Iono.serialTxEn(false)
before. Good practice is to call Iono.serialTxEn(false)
as soon as data has been written and flushed to the serial port.
enabled
: true
to enable the TX-enable line, false
to disable it
Iono.rs485TxEn(true);
IONO_RS485.write(data);
IONO_RS485.write(more_data);
IONO_RS485.flush();
Iono.rs485TxEn(false);
IONO_RS485.readBytes(buffer, length);