Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: arduino-libraries/Modulino
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.4.0
Choose a base ref
...
head repository: arduino-libraries/Modulino
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Loading
Showing with 944 additions and 207 deletions.
  1. +1 −0 .github/workflows/compile-examples.yml
  2. +13 −0 README.md
  3. +186 −0 docs/api.md
  4. BIN docs/images/modulino-buttons.jpeg
  5. BIN docs/images/modulino-buzzer.jpg
  6. BIN docs/images/modulino-distance.jpg
  7. BIN docs/images/modulino-knob.jpg
  8. BIN docs/images/modulino-movement.jpg
  9. BIN docs/images/modulino-pixels.jpg
  10. BIN docs/images/modulino-thermo.jpg
  11. +181 −0 docs/readme.md
  12. +0 −28 examples/Modulino_Buttons/Basic/Basic.ino
  13. +8 −1 examples/Modulino_Buttons/Button2Integration/Button2Integration.ino
  14. +46 −0 examples/Modulino_Buttons/Buttons_Basic/Buttons_Basic.ino
  15. +0 −20 examples/Modulino_Buzzer/Basic/Basic.ino
  16. +33 −0 examples/Modulino_Buzzer/Buzzer_Basic/Buzzer_Basic.ino
  17. +15 −2 examples/Modulino_Buzzer/Simple_melody/Simple_melody.ino
  18. +32 −0 examples/Modulino_Buzzer/Theremin/Theremin.ino
  19. +0 −17 examples/Modulino_Distance/Basic/Basic.ino
  20. +30 −0 examples/Modulino_Distance/Distance_Basic/Distance_Basic.ino
  21. +0 −22 examples/Modulino_Knob/Basic/Basic.ino
  22. +0 −30 examples/Modulino_Knob/EncoderSetter/EncoderSetter.ino
  23. +50 −0 examples/Modulino_Knob/Encoder_Setter/Encoder_Setter.ino
  24. +35 −0 examples/Modulino_Knob/Knob_Basic/Knob_Basic.ino
  25. +0 −29 examples/Modulino_Movement/Basic/Basic.ino
  26. +58 −0 examples/Modulino_Movement/Movement_Basic/Movement_Basic.ino
  27. +0 −18 examples/Modulino_Pixels/Basic/Basic.ino
  28. +32 −0 examples/Modulino_Pixels/Pixels_Basic/Pixels_Basic.ino
  29. +16 −2 examples/Modulino_Pixels/Simple_Animation/Simple_Animation.ino
  30. +13 −0 ...trix/TemperatureHumidityMatrix.ino → Temperature_Humidity_Matrix/Temperature_Humidity_Matrix.ino}
  31. +13 −2 examples/Modulino_Thermo/{Basic/Basic.ino → Thermo_Basic/Thermo_Basic.ino}
  32. +8 −0 examples/Utilities/AddressChanger/AddressChanger.ino
  33. +15 −0 examples/Utilities/FirmwareUpdater/FirmwareUpdater.ino
  34. +21 −4 examples/Utilities/Modulino_PlugNPlay/Modulino_PlugNPlay.ino
  35. +3 −3 library.properties
  36. +17 −2 src/Modulino.cpp
  37. +118 −27 src/Modulino.h
1 change: 1 addition & 0 deletions .github/workflows/compile-examples.yml
Original file line number Diff line number Diff line change
@@ -47,6 +47,7 @@ jobs:
- source-path: ./
# Install library dependencies.
- name: STM32duino VL53L4CD
- name: STM32duino VL53L4ED
- name: Arduino_LSM6DSOX
- name: Arduino_LPS22HB
- name: Arduino_HS300x
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 🧩 Arduino Modulino® Library

The Arduino Modulino® Library simplifies the integration and management of Modulino® modules on Arduino boards.

A Modulino® is a compact, modular electronic device that connects easily to Arduino via the Qwiic connector and communicates using the I2C (`Wire`) protocol. These modules include sensors, actuators, and more.

📖 For more information about this library please read the documentation [here](./docs/).

## Hardware Compatibility
This library is compatible with all Arduino boards that feature an I2C interface (`Wire`).

## Support and Contributions
If you find this library helpful, consider supporting us through [donations](https://www.arduino.cc/en/donate/), [sponsorship](https://github.com/sponsors/arduino) or check out our [store](https://store.arduino.cc/).
186 changes: 186 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
# Arduino Modulino Library API

## Summary

Members | Descriptions
--------------------------------------------|------------------------------------------
| `class` [`ModulinoClass`](#modulinoclass) | The base class for all Modulino components, providing essential functionality and structure for all subsequent Modulino modules. |
| `class` [`ModulinoButtons`](#modulinobuttons) | Handles the functionality of Modulino Buttons, enabling detection of presses and handling input events. |
| `class` [`ModulinoBuzzer`](#modulinobuttons) |Handles the functionality of Modulino Buzzer, enabling the sound generation for feedback or alerts. |
| `class` [`ModulinoPixels`](#modulinopixels) | Handles the functionality of Modulino Pixels, managing LEDs strip color, status and brightness. |
| `class` [`ModulinoKnob`](#modulinoknob) | Handles the functionality of Modulino Knob, interfacing with the rotary knob position. |
| `class` [`ModulinoMovement`](#modulinomovement) | Handles the functionality of Modulino Movement,interfacing with the IMU sensor to get acceleration readings. |
| `class` [`ModulinoThermo`](#modulinothermo) | Handles the functionality of Modulino Thermo, managing temperature sensors to provide real-time temperature and humidity readings. |
| `class` [`ModulinoDistance`](#modulinodistance) | Handles the functionality of Modulino Distance, enabling distance measurement using ToF (Time-of-Flight) sensors for precise range detection. |

### ModulinoClass

The `ModulinoClass` is the main class that handles the initialization of the I2C communication bus.

#### Methods

- **`void begin(HardwareI2C& wire = Wire)`**
Initializes the I2C communication. The default I2C bus is `Wire`, but you can specify another one (e.g., `Wire1`).

---

### ModulinoButtons

Represents a Modulino Buttons module.

#### Methods

- **`PinStatus isPressed(int index)`**
Returns the press status (HIGH/LOW) of the button at the specified index (_0-A, 1-B, 2-C_).

- **`bool update()`**
Updates the button status. Returns `true` if the status has changed, `false` otherwise.

- **`void setLeds(bool a, bool b, bool c)`**
Sets the LED states. Each argument corresponds to one LED's state (on/off).

---

### ModulinoBuzzer

Represents a Modulino Buzzer module.

#### Methods

- **`void tone(size_t freq, size_t len_ms)`**
Plays a tone at the specified frequency (`freq`) and duration (`len_ms`).

- **`void noTone()`**
Stops any tone currently playing.

---

### ModulinoPixels

Represents a Modulino Pixels module.

#### Methods

- **`void set(int idx, ModulinoColor rgb, uint8_t brightness = 25)`**
Sets the color of the LED at the specified index.

- **`void set(int idx, uint8_t r, uint8_t g, uint8_t b, uint8_t brightness = 5)`**
Sets the color of the LED at the specified index using RGB values.

- **`void clear(int idx)`**
Clears the LED at the specified index (turns it off).

- **`void clear()`**
Clears all LEDs (turns them all off).

- **`void show()`**
Updates the LEDs to display the current color data.

---

### ModulinoKnob

Represents a Modulino Knob module.

#### Methods

- **`int16_t get()`**
Gets the current value of the knob.

- **`bool isPressed()`**
Returns `true` if the button on the knob is pressed, `false` otherwise.

- **`void set(int16_t value)`**
Sets the knob value.

---

### ModulinoMovement

Represents a Modulino Movement module.

#### Methods

- **`int update()`**
Updates the sensor data and reads the acceleration values.

- **`int available()`**
Returns `true` if acceleration data is available.

- **`float getX()`**
Returns the X-axis acceleration.

- **`float getY()`**
Returns the Y-axis acceleration.

- **`float getZ()`**
Returns the Z-axis acceleration.

- **`float getRoll()`**
Returns the angular velocity around X-axis.

- **`float getPitch()`**
Returns the angular velocity around Y-axis.

- **`float getYaw()`**
Returns the angular velocity around Z-axis.

---

### ModulinoThermo

Represents a Modulino Thermo module.

#### Methods

- **`float getHumidity()`**
Returns the humidity reading.

- **`float getTemperature()`**
Returns the temperature reading.

---

### ModulinoDistance

Represents a Modulino Distance module.

#### Methods

- **`available()`**
Checks if new distance data is available from the sensor. If data is ready, it reads the data and updates the distance value.
`true` if distance data is available, `false` if distance data is not available.

- **`float get()`**
Returns the distance measured by the sensor in millimeters.
The measured distance in millimeters if available, `NAN` if the distance reading is invalid.

## Constants

- **`ModulinoColor RED`**
Represents the color red for Modulino Pixels modules.

- **`ModulinoColor BLUE`**
Represents the color blue for Modulino Pixels modules.

- **`ModulinoColor GREEN`**
Represents the color green for Modulino Pixels modules.

- **`ModulinoColor VIOLET`**
Represents the color violet for Modulino Pixels modules.

- **`ModulinoColor WHITE`**
Represents the color white for Modulino Pixels modules.

### ModulinoColor

Represents a color for Modulino Pixels modules.

#### Constructor

- **`ModulinoColor(uint8_t r, uint8_t g, uint8_t b)`**
Creates a color with the specified red (`r`), green (`g`), and blue (`b`) components.

## License

This library is released under the [MPL-2.0 license](../LICENSE).
Binary file added docs/images/modulino-buttons.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/modulino-buzzer.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/modulino-distance.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/modulino-knob.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/modulino-movement.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/modulino-pixels.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/modulino-thermo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
181 changes: 181 additions & 0 deletions docs/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
# Arduino Modulino® Library

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](#utilities) section.

## Main Features

The **Modulino** library supports the following hardware modules:

- **Buttons (`ModulinoButtons`)**: Read the state of buttons and control the associated LEDs.
- **Buzzer (`ModulinoBuzzer`)**: Activate and deactivate the buzzer and set its frequency.
- **LEDs (`ModulinoPixels`)**: Control RGB LEDs with customizable display modes.
- **Knob (`ModulinoKnob`)**: Read the value of a rotary encoder.
- **Motion (`ModulinoMovement`)**: Interface with the LSM6DSOX IMU sensor to get acceleration values.
- **Temperature & Humidity (`ModulinoThermo`)**: Get temperature and humidity readings from the HS300x sensor.
- **Distance (`ModulinoDistance`)**: Measures distance using a Time-of-Flight (ToF) sensor (VL53L0x).

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

```cpp
#include <Modulino.h>
Modulino.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:

```cpp
ModulinoType modulino_name;
modulino_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.

![Modulino Buttons](./images/modulino-buttons.jpeg)

```cpp
ModulinoButtons buttons;
buttons.begin();
buttons.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.

![Modulino Buzzer](./images/modulino-buzzer.jpg)

```cpp
ModulinoBuzzer buzzer;
buzzer.begin();
buzzer.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.

![Modulino Pixels](./images/modulino-pixels.jpg)

```cpp
ModulinoPixels leds;
leds.set(0, ModulinoColor(255, 0, 0)); // Set the first LED (Position: 0) to red
leds.show(); // Display the LEDs
```

### ModulinoKnob
Manages a rotary encoder, allowing you to read the potentiometer value and check if the knob is pressed.

![Modulino Knob](./images/modulino-knob.jpg)

```cpp
ModulinoKnob knob;
knob.begin();
int16_t value = knob.get(); // Get the value of the encoder
```

### ModulinoMovement
Interfaces with the LSM6DSOX IMU sensor to get acceleration readings.

![Modulino Movement](./images/modulino-movement.jpg)

```cpp
ModulinoMovement movement;
movement.begin();
float x = movement.getX();
```

### ModulinoThermo
Reads temperature and humidity data from the HS300x sensor.

![Modulino Thermo](./images/modulino-thermo.jpg)

```cpp
ModulinoThermo thermo;
thermo.begin();
float temperature = thermo.getTemperature();
float humidity = thermo.getHumidity();
```

### ModulinoDistance
Measures distance using a ToF (Time-of-Flight) sensor.

![Modulino Distance](./images/modulino-distance.jpg)

```cpp
ModulinoDistance distance;
distance.begin();
float distanceValue = distance.get();
```

## Example Usage

Here’s an example of how to use some Modulino in a program:

```cpp
// This sketch demonstrates how to use the Modulino library to control buttons, LEDs, and a buzzer.
// It listens for a button press (Button A), turns on the LED 0, and plays a sound through the buzzer when pressed.

#include <Modulino.h>

ModulinoButtons buttons; // Declare a Buttons Modulino
ModulinoPixels leds; // Declare a Pixels Modulino
ModulinoBuzzer buzzer; // Declare a Buzzer Modulino

int frequency = 440; // Set frequency to 440Hz
int duration = 1000; // Set duration to 1000ms

void setup() {
Serial.begin(9600);

Modulino.begin(); // Initialize the Modulino library

buttons.begin(); // Initialize the Buttons module
leds.begin(); // Initialize the Pixels module
buzzer.begin(); // Initialize the Buzzer module
}

void loop() {
if (buttons.update()) { // Update the button states
if (buttons.isPressed(0)) { // Check if Button A (button 0) is pressed
Serial.println("Button A pressed!");
leds.set(0, RED); // Turn on LED 0 to red
leds.show();

buzzer.tone(frequency, duration); // Play buzzer sound with the specified frequency and duration
delay(duration);
} else {
leds.clear(0); // Turn off LED 0
leds.show();
}
}
}
```

## 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](../examples).

### Utilities

In the [Utilities](../examples/Utilities) folder, you will find programs designed to help you manage and manipulate the Modulino:

- [AddressChanger](../examples/Utilities/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](./api.md).

## License

This library is released under the [MPL-2.0 license](../LICENSE).
Loading