Skip to content

ExoSenseMKR

nemax68 edited this page Jul 18, 2019 · 19 revisions

This library provides simple functions to monitor and control Iono's I/Os.

Import the library in your sketch:

#include <Iono.h>

The library includes the following constants, that corresponds to Iono's pins (inputs/outputs):

DO1     DO2     DO3     DO4     DO5     DO6

DI1     AV1     AI1

DI2     AV2     AI2

DI3     AV3     AI3

DI4     AV4     AI4

DI5     DI6     AO1

On Iono MKR PIN_TXEN is defined as Arduino's pin 4, which is used as TX enable for RS-485 communication.

Following are the available methods:

read

Iono.read(uint8_t pin)

This method returns the value read from the specified pin. If the specified pin is digital (i.e. DO1...DO6, DI1...DI6) the returned value can be HIGH or LOW. If the specified pin is an analog voltage (i.e. AV1...AV4) the returned value is a float ranging from 0.0 to 10.0 (30.0 for Iono MKR). If the specified pin is an analog current (i.e. AI1...AI4) the returned value is a float ranging from 0.0 to 20.0 (25.0 for Iono MKR). If the specified pin is AO1, the returned value is a float ranging from 0.0 to 10.0.

readAnalogAvg

Iono.readAnalogAvg(uint8_t pin, int n)

This method returns the average of n subsequent readings on the specified analog input.

setBYP

setBYP(uint8_t pin, bool value)

This function is only available and needed on Iono MKR, when using DI5 or DI6 as TTL line. Call this function in setup() and set value to true when the input is used as TTL (jumper in BYP position).

write

Iono.write(uint8_t pin, float value)

This method writes the passed value to the specified pin. If the specified pin is a digital output (i.e. DO1...DO6) the accepted values are HIGH or LOW. If the specified pin is AO1 the accepted values ranges from 0.0 to 10.0

flip

Iono.flip(uint8_t pin)

This method switches the state of the specified digital output pin (i.e. DO1...DO6).

subscribeDigital

Iono.subscribeDigital(uint8_t pin, unsigned long stableTime, Callback *callback);

This method can be used to attach a callback method to the change of state of a digital input.

The callback parameter must point to a void function accepting two parameters: a uint8_t and a float; for instance:

void myCallback(uint8_t pin, float value)

This function will be called every time the specified pin changes state and maintains such state at least for a time equal to the stableTime parameter, in milliseconds. The parameters passed to the callback function will correspond to the monitored pin and the value that triggered the call.

subscribeAnalog

Iono.subscribeAnalog(uint8_t pin, unsigned long stableTime, float minVariation, Callback *callback)

This method can be used to attach a callback method to the change of state of an analog input.

The callback parameter must point to a void function accepting two parameters: a uint8_t and a float; for instance:

void myCallback(uint8_t pin, float value)

This function will be called every time the specified pin changes value of an amount equal or bigger than the minVariation parameter and maintains such difference at least for a time equal to the stableTime parameter, in milliseconds. The parameters passed to the callback function will correspond to the monitored pin and the value that triggered the call.

linkDiDo

Iono.linkDiDo(uint8_t dix, uint8_t dox, uint8_t mode, unsigned long stableTime)

This function can be used to link the state of a digital input (DI1...DI6) to a relay output (DO1...DO6).

The mode parameter can be set to:
LINK_FOLLOW: to have the relay closed when the input is high and open when low
LINK_INVERT: to have the relay open when the input is high and closed when low
LINK_FLIP_H: to have the relay flipped at any input transition from low to high
LINK_FLIP_L: to have the relay flipped at any input transition from high to low
LINK_FLIP_T: to have the relay flipped at any input transition (low to high or high to low)

The stableTime parameter specifies the minimum time (in millisecond) the input must maintain its state before the command is performed on the relay (debounce filter).

N.B. This function can be used in combination with subscribeDigital(), but the stableTime parameters must be set to the same value.

process

Iono.process()

This method must be called periodically (inside the loop() function) if subscribeDigital(), subscribeAnalog() or linkDiDo() are used.

This method checks the inputs and calls the callback functions and performs the relay actions if required.

Examples

The library folder includes some examples that can be opened directly from the Arduino IDE menu File > Examples > Iono.

  • Glow shows how to control the analog output, making the LED glow;
  • ShaveAndAHaircut shows how to play some music with Iono's relays;
  • Subscribe shows how to use the subscribe methods to monitor inputs;
  • Link shows how to use the linkDiDo function.

Clone this wiki locally