🛠 Lire l'ADC 12 bits sans griller le SoC : la règle des 1,8 V

BeagleBone Black (TI Sitara AM3358) · intermediaire · Schéma : IMG-beaglebone-black-intermediaire-1-adc-1-8v-lecture-iio.svg — pont diviseur de résistance sur la BeagleBone Black : signal 3,3 V entrant, deux résistances, point milieu vers P9_33 (AIN4), P9_32 VDD_ADC 1,8 V et P9_34 AGND repérés, badge « 1,8 V MAX ».

Objectives

Use the AM335x 8-channel 12-bit ADC via the mainline IIO subsystem, and above all, avoid the number one pitfall on the BeagleBone Black regarding analog inputs: the AIN inputs accept 1.8 V AT MOST (analog supply VDD_ADC = 1.8 V on P9_32), while the rest of the board operates at 3.3 V. Exceeding 1.8 V damages the SoC.

Hardware

Complete Code

# Repérer le device IIO et les canaux activés
ls /sys/bus/iio/devices/iio:device0/
cat /sys/bus/iio/devices/iio:device0/in_voltage0_label   # vérifier quel AIN
#!/usr/bin/env python3
"""Lit AIN4 (P9_33) sur une BBB mainline. Entrée MAX : 1,8 V !"""
import glob, time

dev = glob.glob("/sys/bus/iio/devices/iio:device*")[0]  # "ti_am335x_adc"
# L'index N dépend des canaux activés dans le DT : vérifier les labels !
CHAN = "in_voltage0_raw"

while True:
    raw = int(open(f"{dev}/{CHAN}").read)     # code 12 bits : 0..4095
    mv  = raw * 1800 / 4095                       # référence pleine échelle 1,8 V
    print(f"raw={raw}  {mv:.0f} mV (entrée directe ; diviseur ?)")
    time.sleep(0.2)

Expected Verification

With the potentiometer wiper connected between P9_32 (1.8 V) and P9_34 (AGND) to AIN4, the raw value follows 0 to 4095 and the calculated millivolts follow 0 to 1800. Touching the pin with a finger: the value drifts (floating input) — proof that the measurement is live.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials