ExoSenseMKR - nemax68/test GitHub Wiki

This library provides simple functions to monitor and control Exo Sense MKR's I/Os, internal resources and environment data sensors.

Import the library in your sketch:

#include <ExoSenseMKR.h>

The library includes the following constants, that corresponds to Exo Sense MKR's pins (inputs/outputs) and internal resources:

DI1     DI2     external digital inputs

OC1             external open collector output

BUZZER          internal buzzer  

SOUND           internal sound level meter

Following are the available methods:

begin

ExoSenseMKR.begin(void)

This method must be called inside the setup() function, it initialize the wire interface and the internal class:

bme : ExoBme680.

read

ExoSenseMKR.read(uint8_t pin)

This method returns the value read from the specified pin (DI1 or DI2).

write

ExoSenseMKR.write(uint8_t pin, uint8_t value)

This method writes the passed value to the specified pin (OC1) or resource(BUZZER).

buzzer

ExoSenseMKR.buzzer(uint8_t value)

This method enable/disable directly the internal buzzer (value=0 --> buzzer silent, value=1 --> buzzer sound).

sound

ExoSenseMKR.sound(void)

This method return the sound level meter (12 bit 0-4095 value).

soundAvg

ExoSenseMKR.soundAvg(int n)

This method return the n samples average sound level meter (12 bit 0-4095 value).

subscribeDigital

ExoSenseMKR.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 int; for instance:

void myCallback(uint8_t pin, int 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.

subscribeSound

ExoSenseMKR.subscribeSound(uint8_t pin, unsigned long stableTime, int minVariation, Callback *callback)

This method can be used to attach a callback method to the change of state of sound level meter.

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

void myCallback(uint8_t pin, int value)

This function will be called every time the sound level 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 2nd parameter passed to the callback function will correspond to the value that triggered the call, the 1st parameter is fixed (SOUND input pin).

subscribeMeasure

ExoSenseMKR.subscribeMeasure(unsigned long time, enum measure_type type, uint8_t device, CallbackMs *callback)

This method can be used to attach a callback method to a device measure.

The callback parameter must point to a void function:

void myCallback(void)

based on measure_type value:

MEASURE_SINGLE

This function will be called only one time, and parameter time is the time to wait for measure (in millisec)

MEASURE_CONTINUE

This function will be called continuosly with time period equal to the parameter time

The parameter device (BME680 or OPT3001) target the sensor.

linkDiDo

ExoSenseMKR.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 or DI2) to a output (OC1 or BUZZER).

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.

flip

ExoSenseMKR.flip(uint8_t pin)

This method switches the state of the specified digital output pin (i.e. OC1 or BUZZER).

process

ExoSenseMKR.process()

This method must be called periodically (inside the loop() function) if subscribeDigital(), subscribeSound(), subscribeMeasure() 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 > ExoSenseMKR.

  • Port shows how to control the digital port with subscribeDigital and linkDiDo methods;
  • link shows how to use the linkDiDo method;
  • Sound shows how to use the sound, soundAvg and subscribeSound function.
  • Poll shows how to get BMP680 value with the callback method