🛠 Premier capteur I2C sur GPIO0/GPIO1

Raspberry Pi Model A (2013) — Board Sheet · intermediaire · Schéma : IMG-model-a-intermediaire-5-modela-i2c-capteur.svg — Raspberry Pi Model A relié en I2C à un petit module capteur : SDA sur GPIO0 (broche 3), SCL sur GPIO1 (broche 5), 3,3 V et masse, résistances de pull-up sur le bus

Objectives

Hardware

Complete code

# 1) Activer I2C : sudo raspi-config > Interface I2C
#    ou à la main dans /boot/config.txt :
echo "dtparam=i2c_arm=on" | sudo tee -a /boot/config.txt
echo "i2c-dev" | sudo tee /etc/modules-load.d/i2c.conf
sudo apt-get install -y i2c-tools python3-smbus && sudo reboot

# 2) Balayer le bus (bus 1)
sudo i2cdetect -y 1
#!/usr/bin/env python3
import smbus, time
bus = smbus.SMBus(1)
ADDR = 0x76                      # adresse vue avec i2cdetect
WHO = bus.read_byte_data(ADDR, 0xD0)
print("chip id:", hex(WHO))
while True:
    t = bus.read_word_data(ADDR, 0x22)   # registre d'exemple
    print("brut température:", t, flush=True)
    time.sleep(1)

Expected verification

i2cdetect -y 1 displays the sensor's address (e.g., 76) in the grid; the Python script reads values that change when you warm the sensor with your finger. >

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials