Modulino
Arduino Library for Modulinos
The Modulino library is designed to simplify integration with various Modulino. It supports a variety of modules, such as motion sensors, buttons, buzzers, LED displays, and more, all through an I2C (
Wire
) interface.Hardware Compatibility
The library is compatible with Arduino boards that support I2C (
Wire
) communication.Each Modulino has a fixed I2C address assigned by default. If you wish to change the I2C address, you can refer to the Utilities section.
Main Features
The Modulino library supports the following hardware modules:
- Buttons (
): Read the state of buttons and control the associated LEDs.ModulinoButtons
- Buzzer (
): Activate and deactivate the buzzer and set its frequency.ModulinoBuzzer
- LEDs (
): Control RGB LEDs with customizable display modes.ModulinoPixels
- Knob (
): Read the value of a rotary encoder.ModulinoKnob
- Motion (
): Interface with the LSM6DSOX IMU sensor to get acceleration values.ModulinoMovement
- Temperature & Humidity (
): Get temperature and humidity readings from the HS300x sensor.ModulinoThermo
- Distance (
): Measures distance using a Time-of-Flight (ToF) sensor (VL53L0x).ModulinoDistance
Library Initialization
To initialize the Modulino library, include the header file and call the
begin()
method. This will set up the I2C communication and prepare the library for use with the modules.1#include <Modulino.h>2Modulino.begin(); // Initialize the Modulino library
Supported Modules
You can initialize a Modulino board easily. The basic setup requires just a call to the
begin()
method for each module. For example:1ModulinoType modulino_name;2modulino_name.begin(); // Initialize the ModulinoType module
ModulinoButtons
Manages the state of three buttons and controls their associated LED states. You can read the state of each button and send commands to turn the LEDs on/off.
1ModulinoButtons buttons;2buttons.begin();3buttons.setLeds(true, false, true); // Turn on LED 1 and LED 3
ModulinoBuzzer
Allows you to emit sounds through the buzzer. You can set the frequency and duration of the sound.
1ModulinoBuzzer buzzer;2buzzer.begin();3buzzer.tone(440, 1000); // 440Hz frequency for 1000ms
ModulinoPixels
Controls an array of 8 RGB LEDs, allowing you to set the colors and brightness. You can also clear individual LEDs or the entire array.
1ModulinoPixels leds;2leds.set(0, ModulinoColor(255, 0, 0)); // Set the first LED (Position: 0) to red3leds.show(); // Display the LEDs
ModulinoKnob
Manages a rotary encoder, allowing you to read the potentiometer value and check if the knob is pressed.
1ModulinoKnob knob;2knob.begin();3int16_t value = knob.get(); // Get the value of the encoder
ModulinoMovement
Interfaces with the LSM6DSOX IMU sensor to get acceleration readings.
1ModulinoMovement movement;2movement.begin();3float x = movement.getX();
ModulinoThermo
Reads temperature and humidity data from the HS300x sensor.
1ModulinoThermo thermo;2thermo.begin();3float temperature = thermo.getTemperature();4float humidity = thermo.getHumidity();
ModulinoDistance
Measures distance using a ToF (Time-of-Flight) sensor.
1ModulinoDistance distance;2distance.begin();3float distanceValue = distance.get();
Example Usage
Here’s an example of how to use some Modulino in a program:
1// This sketch demonstrates how to use the Modulino library to control buttons, LEDs, and a buzzer.2// It listens for a button press (Button A), turns on the LED 0, and plays a sound through the buzzer when pressed.3
4#include <Modulino.h>5
6ModulinoButtons buttons; // Declare a Buttons Modulino7ModulinoPixels leds; // Declare a Pixels Modulino8ModulinoBuzzer buzzer; // Declare a Buzzer Modulino9
10int frequency = 440; // Set frequency to 440Hz11int duration = 1000; // Set duration to 1000ms12
13void setup() {14 Serial.begin(9600);15
16 Modulino.begin(); // Initialize the Modulino library17
18 buttons.begin(); // Initialize the Buttons module19 leds.begin(); // Initialize the Pixels module20 buzzer.begin(); // Initialize the Buzzer module21}22
23void loop() {24 if (buttons.update()) { // Update the button states25 if (buttons.isPressed(0)) { // Check if Button A (button 0) is pressed26 Serial.println("Button A pressed!");27 leds.set(0, RED); // Turn on LED 0 to red28 leds.show();29
30 buzzer.tone(frequency, duration); // Play buzzer sound with the specified frequency and duration31 delay(duration);32 } else {33 leds.clear(0); // Turn off LED 034 leds.show();35 }36 }37}
Examples
The examples folder is organized by Modulino type. Each module has its own folder with example sketches that demonstrate both basic and advanced usage (where applicable).
You can explore the examples here.
Utilities
In the Utilities folder, you will find programs designed to help you manage and manipulate the Modulino:
- AddressChanger: This program allows you to change the I2C address of a Modulino module. It’s helpful when you need to reassign addresses to avoid conflicts or organize your I2C network.
API
The API documentation can be found here.
License
This library is released under the MPL-2.0 license.
Members | Descriptions |
---|---|
| The base class for all Modulino components, providing essential functionality and structure for all subsequent Modulino modules. |
| Handles the functionality of Modulino Buttons, enabling detection of presses and handling input events. |
| Handles the functionality of Modulino Buzzer, enabling the sound generation for feedback or alerts. |
| Handles the functionality of Modulino Pixels, managing LEDs strip color, status and brightness. |
| Handles the functionality of Modulino Knob, interfacing with the rotary knob position. |
| Handles the functionality of Modulino Movement,interfacing with the IMU sensor to get acceleration readings. |
| Handles the functionality of Modulino Thermo, managing temperature sensors to provide real-time temperature and humidity readings. |
| Handles the functionality of Modulino Distance, enabling distance measurement using ToF (Time-of-Flight) sensors for precise range detection. |