9. Input Devices

The objective this week was to integrate two distinct data input methods using the Seeed Studio XIAO RP2350. This week's assignment consisted of capturing distance through an analog sensor and obtaining the current time via a Real-Time Clock (RTC) module using digital communication.

For more information on how input devices function, you can visit our GROUP PAGE.

Analog sensors

Analog sensors (such as potentiometers, LDR light sensors, or temperature sensors) output a continuous voltage signal. The XIAO RP2350 features a high-resolution Analog-to-Digital Converter (ADC).

If the sensor outputs 1.65V (which is exactly half of the 3.3V reference), the ADC references its internal "ruler" to assign a digital value. In this case, with a 12-bit resolution, it would correspond to level 2048.

The specific sensor I am using is the Sharp GP2Y0E02A (you can find its datasheet here). It has an effective measuring range of 4 to 50 cm.

RTC Module (Real Time Clock) via I2C

Unlike the main processor, which loses track of time if it loses power, the RTC module maintains the exact time thanks to an external battery. To communicate it with the XIAO RP2350, I used the I2C protocol.

I used the dedicated pins on the XIAO (SDA and SCL). The microcontroller requests information from a specific address (e.g., 0x68), and the RTC responds by sending packets of bytes representing seconds, minutes, and hours.

RTCs typically deliver data in Binary Coded Decimal (BCD) format, which requires a small mathematical conversion in the code to display the numbers in standard decimal format.

The image below shows the registers through which the RTC operates; you can find this map in the datasheet.

RTC datasheet

1. Programming the XIAO RP2350

To program the XIAO RP2350 in the Arduino IDE, I followed these steps:

  1. Go to File > Preferences.
  2. In the Additional Boards Manager URLs section, paste the following link: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
    RTC datasheet
  3. Go to Tools > Board > Boards Manager...
  4. RTC datasheet
  5. Search for Raspberry Pi Pico/RP2040/RP2350 and install it.
  6. RTC datasheet
  7. Once installed, select your specific hardware:
  8. Board: Tools > Board > Raspberry Pi RP2350 Boards > Seeed XIAO RP2350.
  9. RTC datasheet
  10. Connect the XIAO to your computer via USB-C.
  11. Press and hold the BOOT button.
  12. Press and release the RESET button.
  13. Release the BOOT button.

2. INPUTS

FILES

Here you can download the source files created during this week: