Skip to content

Commit a02e107

Browse files
Merge pull request #25 from leonardocavagnis/doc-readme-api
Adding Documentation
2 parents d5de8d9 + abfb363 commit a02e107

File tree

27 files changed

+495
-5
lines changed

27 files changed

+495
-5
lines changed

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# 🧩 Arduino Modulino® Library
2+
3+
The Arduino Modulino® Library simplifies the integration and management of Modulino® modules on Arduino boards.
4+
5+
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.
6+
7+
📖 For more information about this library please read the documentation [here](./docs/).
8+
9+
## Hardware Compatibility
10+
This library is compatible with all Arduino boards that feature an I2C interface (`Wire`).
11+
12+
## Support and Contributions
13+
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/).

docs/api.md

+177
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
# Arduino Modulino Library API
2+
3+
## Summary
4+
5+
Members | Descriptions
6+
--------------------------------------------|------------------------------------------
7+
| `class` [`ModulinoClass`](#modulinoclass) | The base class for all Modulino components, providing essential functionality and structure for all subsequent Modulino modules. |
8+
| `class` [`ModulinoButtons`](#modulinobuttons) | Handles the functionality of Modulino Buttons, enabling detection of presses and handling input events. |
9+
| `class` [`ModulinoBuzzer`](#modulinobuttons) |Handles the functionality of Modulino Buzzer, enabling the sound generation for feedback or alerts. |
10+
| `class` [`ModulinoPixels`](#modulinopixels) | Handles the functionality of Modulino Pixels, managing LEDs strip color, status and brightness. |
11+
| `class` [`ModulinoKnob`](#modulinoknob) | Handles the functionality of Modulino Knob, interfacing with the rotary knob position. |
12+
| `class` [`ModulinoMovement`](#modulinomovement) | Handles the functionality of Modulino Movement,interfacing with the IMU sensor to get acceleration readings. |
13+
| `class` [`ModulinoThermo`](#modulinothermo) | Handles the functionality of Modulino Thermo, managing temperature sensors to provide real-time temperature and humidity readings. |
14+
| `class` [`ModulinoDistance`](#modulinodistance) | Handles the functionality of Modulino Distance, enabling distance measurement using ToF (Time-of-Flight) sensors for precise range detection. |
15+
16+
### ModulinoClass
17+
18+
The `ModulinoClass` is the main class that handles the initialization of the I2C communication bus.
19+
20+
#### Methods
21+
22+
- **`void begin(HardwareI2C& wire = Wire)`**
23+
Initializes the I2C communication. The default I2C bus is `Wire`, but you can specify another one (e.g., `Wire1`).
24+
25+
---
26+
27+
### ModulinoButtons
28+
29+
Represents a Modulino Buttons module.
30+
31+
#### Methods
32+
33+
- **`PinStatus isPressed(int index)`**
34+
Returns the press status (HIGH/LOW) of the button at the specified index (_0-A, 1-B, 2-C_).
35+
36+
- **`bool update()`**
37+
Updates the button status. Returns `true` if the status has changed, `false` otherwise.
38+
39+
- **`void setLeds(bool a, bool b, bool c)`**
40+
Sets the LED states. Each argument corresponds to one LED's state (on/off).
41+
42+
---
43+
44+
### ModulinoBuzzer
45+
46+
Represents a Modulino Buzzer module.
47+
48+
#### Methods
49+
50+
- **`void tone(size_t freq, size_t len_ms)`**
51+
Plays a tone at the specified frequency (`freq`) and duration (`len_ms`).
52+
53+
- **`void noTone()`**
54+
Stops any tone currently playing.
55+
56+
---
57+
58+
### ModulinoPixels
59+
60+
Represents a Modulino Pixels module.
61+
62+
#### Methods
63+
64+
- **`void set(int idx, ModulinoColor rgb, uint8_t brightness = 25)`**
65+
Sets the color of the LED at the specified index.
66+
67+
- **`void set(int idx, uint8_t r, uint8_t g, uint8_t b, uint8_t brightness = 5)`**
68+
Sets the color of the LED at the specified index using RGB values.
69+
70+
- **`void clear(int idx)`**
71+
Clears the LED at the specified index (turns it off).
72+
73+
- **`void clear()`**
74+
Clears all LEDs (turns them all off).
75+
76+
- **`void show()`**
77+
Updates the LEDs to display the current color data.
78+
79+
---
80+
81+
### ModulinoKnob
82+
83+
Represents a Modulino Knob module.
84+
85+
#### Methods
86+
87+
- **`int16_t get()`**
88+
Gets the current value of the knob.
89+
90+
- **`bool isPressed()`**
91+
Returns `true` if the button on the knob is pressed, `false` otherwise.
92+
93+
- **`void set(int16_t value)`**
94+
Sets the knob value.
95+
96+
---
97+
98+
### ModulinoMovement
99+
100+
Represents a Modulino Movement module.
101+
102+
#### Methods
103+
104+
- **`int update()`**
105+
Updates the sensor data and reads the acceleration values.
106+
107+
- **`int available()`**
108+
Returns `true` if acceleration data is available.
109+
110+
- **`float getX()`**
111+
Returns the X-axis acceleration.
112+
113+
- **`float getY()`**
114+
Returns the Y-axis acceleration.
115+
116+
- **`float getZ()`**
117+
Returns the Z-axis acceleration.
118+
119+
---
120+
121+
### ModulinoThermo
122+
123+
Represents a Modulino Thermo module.
124+
125+
#### Methods
126+
127+
- **`float getHumidity()`**
128+
Returns the humidity reading.
129+
130+
- **`float getTemperature()`**
131+
Returns the temperature reading.
132+
133+
---
134+
135+
### ModulinoDistance
136+
137+
Represents a Modulino Distance module.
138+
139+
#### Methods
140+
141+
- **`available()`**
142+
Checks if new distance data is available from the sensor. If data is ready, it reads the data and updates the distance value.
143+
`true` if distance data is available, `false` if distance data is not available.
144+
145+
- **`float get()`**
146+
Returns the distance measured by the sensor in millimeters.
147+
The measured distance in millimeters if available, `NAN` if the distance reading is invalid.
148+
149+
## Constants
150+
151+
- **`ModulinoColor RED`**
152+
Represents the color red for Modulino Pixels modules.
153+
154+
- **`ModulinoColor BLUE`**
155+
Represents the color blue for Modulino Pixels modules.
156+
157+
- **`ModulinoColor GREEN`**
158+
Represents the color green for Modulino Pixels modules.
159+
160+
- **`ModulinoColor VIOLET`**
161+
Represents the color violet for Modulino Pixels modules.
162+
163+
- **`ModulinoColor WHITE`**
164+
Represents the color white for Modulino Pixels modules.
165+
166+
### ModulinoColor
167+
168+
Represents a color for Modulino Pixels modules.
169+
170+
#### Constructor
171+
172+
- **`ModulinoColor(uint8_t r, uint8_t g, uint8_t b)`**
173+
Creates a color with the specified red (`r`), green (`g`), and blue (`b`) components.
174+
175+
## License
176+
177+
This library is released under the [MPL-2.0 license](../LICENSE).

docs/images/modulino-buttons.jpeg

183 KB
Loading

docs/images/modulino-buzzer.jpg

168 KB
Loading

docs/images/modulino-distance.jpg

137 KB
Loading

docs/images/modulino-knob.jpg

156 KB
Loading

docs/images/modulino-movement.jpg

158 KB
Loading

docs/images/modulino-pixels.jpg

175 KB
Loading

docs/images/modulino-thermo.jpg

144 KB
Loading

docs/readme.md

+181
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# Arduino Modulino® Library
2+
3+
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.
4+
5+
## Hardware Compatibility
6+
7+
The library is compatible with Arduino boards that support I2C (`Wire`) communication.
8+
9+
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.
10+
11+
## Main Features
12+
13+
The **Modulino** library supports the following hardware modules:
14+
15+
- **Buttons (`ModulinoButtons`)**: Read the state of buttons and control the associated LEDs.
16+
- **Buzzer (`ModulinoBuzzer`)**: Activate and deactivate the buzzer and set its frequency.
17+
- **LEDs (`ModulinoPixels`)**: Control RGB LEDs with customizable display modes.
18+
- **Knob (`ModulinoKnob`)**: Read the value of a rotary encoder.
19+
- **Motion (`ModulinoMovement`)**: Interface with the LSM6DSOX IMU sensor to get acceleration values.
20+
- **Temperature & Humidity (`ModulinoThermo`)**: Get temperature and humidity readings from the HS300x sensor.
21+
- **Distance (`ModulinoDistance`)**: Measures distance using a Time-of-Flight (ToF) sensor (VL53L0x).
22+
23+
## Library Initialization
24+
25+
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.
26+
27+
```cpp
28+
#include <Modulino.h>
29+
Modulino.begin(); // Initialize the Modulino library
30+
```
31+
32+
## Supported Modules
33+
34+
You can initialize a Modulino board easily. The basic setup requires just a call to the `begin()` method for each module. For example:
35+
36+
```cpp
37+
ModulinoType modulino_name;
38+
modulino_name.begin(); // Initialize the ModulinoType module
39+
```
40+
41+
### ModulinoButtons
42+
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.
43+
44+
![Modulino Buttons](./images/modulino-buttons.jpg)
45+
46+
```cpp
47+
ModulinoButtons buttons;
48+
buttons.begin();
49+
buttons.setLeds(true, false, true); // Turn on LED 1 and LED 3
50+
```
51+
52+
### ModulinoBuzzer
53+
Allows you to emit sounds through the buzzer. You can set the frequency and duration of the sound.
54+
55+
![Modulino Buzzer](./images/modulino-buzzer.jpg)
56+
57+
```cpp
58+
ModulinoBuzzer buzzer;
59+
buzzer.begin();
60+
buzzer.tone(440, 1000); // 440Hz frequency for 1000ms
61+
```
62+
63+
### ModulinoPixels
64+
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.
65+
66+
![Modulino Pixels](./images/modulino-pixels.jpg)
67+
68+
```cpp
69+
ModulinoPixels leds;
70+
leds.set(0, ModulinoColor(255, 0, 0)); // Set the first LED (Position: 0) to red
71+
leds.show(); // Display the LEDs
72+
```
73+
74+
### ModulinoKnob
75+
Manages a rotary encoder, allowing you to read the potentiometer value and check if the knob is pressed.
76+
77+
![Modulino Knob](./images/modulino-knob.jpg)
78+
79+
```cpp
80+
ModulinoKnob knob;
81+
knob.begin();
82+
int16_t value = knob.get(); // Get the value of the encoder
83+
```
84+
85+
### ModulinoMovement
86+
Interfaces with the LSM6DSOX IMU sensor to get acceleration readings.
87+
88+
![Modulino Movement](./images/modulino-movement.jpg)
89+
90+
```cpp
91+
ModulinoMovement movement;
92+
movement.begin();
93+
float x = movement.getX();
94+
```
95+
96+
### ModulinoThermo
97+
Reads temperature and humidity data from the HS300x sensor.
98+
99+
![Modulino Thermo](./images/modulino-thermo.jpg)
100+
101+
```cpp
102+
ModulinoThermo thermo;
103+
thermo.begin();
104+
float temperature = thermo.getTemperature();
105+
float humidity = thermo.getHumidity();
106+
```
107+
108+
### ModulinoDistance
109+
Measures distance using a ToF (Time-of-Flight) sensor.
110+
111+
![Modulino Distance](./images/modulino-distance.jpg)
112+
113+
```cpp
114+
ModulinoDistance distance;
115+
distance.begin();
116+
float distanceValue = distance.get();
117+
```
118+
119+
## Example Usage
120+
121+
Here’s an example of how to use some Modulino in a program:
122+
123+
```cpp
124+
// This sketch demonstrates how to use the Modulino library to control buttons, LEDs, and a buzzer.
125+
// It listens for a button press (Button A), turns on the LED 0, and plays a sound through the buzzer when pressed.
126+
127+
#include <Modulino.h>
128+
129+
ModulinoButtons buttons; // Declare a Buttons Modulino
130+
ModulinoPixels leds; // Declare a Pixels Modulino
131+
ModulinoBuzzer buzzer; // Declare a Buzzer Modulino
132+
133+
int frequency = 440; // Set frequency to 440Hz
134+
int duration = 1000; // Set duration to 1000ms
135+
136+
void setup() {
137+
Serial.begin(9600);
138+
139+
Modulino.begin(); // Initialize the Modulino library
140+
141+
buttons.begin(); // Initialize the Buttons module
142+
leds.begin(); // Initialize the Pixels module
143+
buzzer.begin(); // Initialize the Buzzer module
144+
}
145+
146+
void loop() {
147+
if (buttons.update()) { // Update the button states
148+
if (buttons.isPressed(0)) { // Check if Button A (button 0) is pressed
149+
Serial.println("Button A pressed!");
150+
leds.set(0, RED); // Turn on LED 0 to red
151+
leds.show();
152+
153+
buzzer.tone(frequency, duration); // Play buzzer sound with the specified frequency and duration
154+
delay(duration);
155+
} else {
156+
leds.clear(0); // Turn off LED 0
157+
leds.show();
158+
}
159+
}
160+
}
161+
```
162+
163+
## Examples
164+
165+
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).
166+
167+
You can explore the examples [here](../examples).
168+
169+
### Utilities
170+
171+
In the [Utilities](../examples/Utilities) folder, you will find programs designed to help you manage and manipulate the Modulino:
172+
173+
- [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.
174+
175+
## API
176+
177+
The API documentation can be found [here](./api.md).
178+
179+
## License
180+
181+
This library is released under the [MPL-2.0 license](../LICENSE).

examples/Modulino_Buttons/Basic/Basic.ino

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*
2+
* Modulino Buttons - Basic
3+
*
4+
* This example code is in the public domain.
5+
* Copyright (c) 2025 Arduino
6+
* SPDX-License-Identifier: MPL-2.0
7+
*/
8+
19
#include <Modulino.h>
210

311
ModulinoButtons buttons;

0 commit comments

Comments
 (0)