Seeed XIAO SAMD21 · xiao-analog-i2c

Read an analog sensor and an I²C module

Question: How do you tell a changing sensor signal from a wiring or scaling problem?

Understand the idea

An analog input produces a number from a voltage using the board's ADC. The number is not automatically volts, percent, temperature, or distance. First record the raw values at known conditions; only then decide on calibration and conversion. Avoid driving an input outside the XIAO's 3.3 V logic range.

For I²C, SDA carries data and SCL carries the clock. The XIAO SAMD21 pin map assigns D4 as SDA and D5 as SCL. Connect ground as well as the two signal wires, check the sensor's supply and pull-up voltage, and make sure pull-ups do not pull the bus to 5 V.

A scan can show whether a device acknowledges on the bus, but it cannot prove every register setting or sensor reading is correct. Test one device at a time, note its address, then read a documented register and compare with the device datasheet.

Worked example

If an ADC reading moves from 120 to 800 as a potentiometer turns, that establishes a repeatable range. Convert it to a voltage only after confirming ADC resolution and reference assumptions for the selected core; map it to physical units only after calibration against known measurements.

Try it at the bench

  1. Connect a potentiometer between 3V3 and GND with its wiper to a documented analog-capable XIAO pin. Print raw readings while turning it slowly.
  2. Record the lowest, middle, and highest readings. Repeat, then check whether the values are stable or noisy before adding smoothing.
  3. If you have a 3.3 V-compatible I²C sensor, connect its SDA/SCL to D4/D5 and ground to ground. Run a scanner, record the address, and compare it with the sensor's documentation.

Check your understanding

What does finding an I²C address prove, and what does it not prove?

Show the answer

It shows that a device acknowledged at that address during the scan. It does not prove the wiring is reliable under load, the register configuration is correct, or the sensor data is valid.

Browse all course lessons