Skip to content

9. Input Devices

Group Assignment

  • probe an input device’s analog levels and digital signals

1. Oscilloscope Calibration

Before starting, we calibrated the oscilloscope using its built-in calibration signal (1kHz square wave). We connected the probe tip to the CAL terminal on the front panel and adjusted the probe compensation until the waveform showed a clean square wave with flat tops.

oscillo calibration

We first reviewed how to use an oscilloscope by probing a blinking LED circuit. By placing the probe at two different points — before and after the resistor — we were able to observe two different voltage levels and see how the resistor causes a voltage drop.

Wiring:

  • XIAO D10 (GPIO3) → resistor → LED anode (long leg)
  • LED cathode (short leg) → GND

How to probe:

  1. Connect the probe tip to the measurement point
  2. Connect the probe ground clip to GND
  3. Press Autoset to automatically adjust the time and voltage scales

MicroPython code:

from machine import Pin
import utime

led = Pin(3, Pin.OUT)  # D10 = GPIO3

while True:
    led.value(1)     # ON
    utime.sleep(1)
    led.value(0)     # OFF
    utime.sleep(1)

Probing before the resistor (directly at the GPIO pin) showed a clean 3.3V square wave. Probing after the resistor (at the LED anode) showed a lower voltage (~2V) because of the voltage drop across the resistor and LED. This confirmed that the resistor is limiting current as expected.

before and after resistor

3. Potentiometer and LED

Next, we built a circuit that controls LED brightness with a potentiometer. This allowed us to probe both an analog input signal (potentiometer output) and a digital PWM signal (LED control) simultaneously.

We asked ChatGPT to write the test code by giving it the wiring schema.

Components:

Component Specification
Potentiometer 10KΩ type B
LED Standard through-hole LED
Resistor Current limiting resistor
Microcontroller Seeed XIAO RP2040

10KΩ B Potentiometer

Wiring:

  • Potentiometer
  • VCC → 3.3V
  • GND → GND
  • Output → D0 (GPIO26)
  • LED
  • D10 (GPIO3) → resistor → LED anode (long leg)
  • LED cathode (short leg) → GND

MicroPython code:

from machine import Pin, ADC, PWM
import utime

# Potentiometer (D0 = GPIO26)
pot = ADC(Pin(26))

# LED with PWM (D10 = GPIO3)
led = PWM(Pin(3))
led.freq(1000)  # 1kHz PWM frequency

while True:
    # Read ADC value (0–65535)
    adc_val = pot.read_u16()

    # Map ADC value directly to PWM duty cycle (0–65535)
    led.duty_u16(adc_val)

    utime.sleep_ms(10)

Oscilloscope observations:

When probing the potentiometer output (D0), we observed a steady DC voltage that changed smoothly as we rotated the knob — a classic analog signal. When probing the LED pin (D10), we observed a PWM square wave whose duty cycle changed in response to the potentiometer position.

Potentiometer position Analog voltage at D0 PWM duty cycle at D10
High (max) ~3.3V ~100%
Low (min) ~0V ~0%

Potentiometer high

Potentiometer low

Note

The XIAO RP2040’s ADC reference voltage is 3.3V, so the potentiometer must be connected to the 3.3V pin (not 5V) to avoid exceeding the ADC input range.

AI usage

  • ChatGPT for generating the test code.
  • Claude Code for brushing up the report.

Reference