For this week's assignment, the goal was to measure something by adding a sensor to a custom microcontroller board and reading its data. I used my custom board based on the Seeed Studio XIAO RP2350 to read the microcontrollers.
I decided to work with a microphone modules, as sound detection is a critical part of my final project. Additionally, I integrated an I2C proximity sensor to test a different type of digital communication protocol.
An input device is a transducer that converts a physical parameter (e.g., temperature, pressure, sound, or light) into a measurable electrical signal that a processor can understand and act upon.
An analog sensor is a device that provides a continuous output signal, typically in the form of voltage, which is proportional to the physical quantity it measures (such as sound, light, or pressure).
Since the XIAO is a digital device, it cannot understand a continuous voltage directly. It uses an ADC (Analog-to-Digital Converter) to translate the incoming voltage into a digital number. On the RP2350, this process has a 12-bit resolution, meaning the microcontroller converts the sensor's voltage (0V to 3.3V) into a numerical scale from 0 to 4095.
I2C (Inter-Integrated Circuit) is a synchronous serial communication protocol that allows a Main Controller like the XIAO RP2350 to communicate with multiple Peripheral sensors using only two shared wires: SDA (Serial Data) for bidirectional data transfer and SCL (Serial Clock) for synchronization.
To program the XIAO RP2350, I used Arduino IDE following these steps:
The VL53L0X is a Time-of-Flight (ToF) distance sensor that uses a vertical-cavity surface-emitting laser (VCSEL) to measure the exact time it takes for light photons to bounce off an object and return to the detector. I integrated this sensor using the I2C protocol, allowing the XIAO RP2350 to receive digital distance data through the SDA and SCL lines.
#include "Adafruit_VL53L0X.h" // Includes the library for the sensor
#include "Wire.h" // Includes the library for I2C communication
// Create the sensor object
Adafruit_VL53L0X lox = Adafruit_VL53L0X();
void setup() {
Serial.begin(115200); // Starts the serial communication
while (!Serial); // Waits for the Serial Monitor to open
// Start I2C using the standard XIAO pins: D4 (SDA) and D5 (SCL)
Wire.begin(D4, D5);
// Initialize the sensor
if (!lox.begin()) {
Serial.println("Error: Sensor not found!");
while (1); // Stops the code if the sensor is missing
}
}
void loop() {
VL53L0X_RangingMeasurementData_t measure; // Variable to store measurement data
lox.rangingTest(&measure, false); // Perform a distance test
// Check if the measurement is valid (Status 4 means out of range)
if (measure.RangeStatus != 4) {
Serial.print("Distance: ");
Serial.print(measure.RangeMilliMeter); // Print the distance in millimeters
Serial.println(" mm");
} else {
Serial.println("Out of range"); // Print this if the object is too far
}
delay(100);
}