🛠 Lire un capteur I2C (température/humidité) sur le bus 1

Raspberry Pi Model B (Rev 1, 2012) — Board Sheet · intermediaire · Schéma : IMG-model-b-rev1-intermediaire-2-modelb1-i2c-capteur.svg — Capteur I2C sur SDA0 (GPIO0, broche 3) et SCL0 (GPIO1, broche 5), 3,3 V et GND, résistances de pull-up externes 4,7 kΩ, adresses listées dans i2cdetect

Objectives

Enable the I2C bus on the BCM2835 (only one hardware bus is exposed on P1: I2C0 on GPIO0/1), scan the bus with i2cdetect, and read a digital sensor in Python. Early revisions do not have wired I2C pull-up resistors — a topic discussed on official forums — so we add external 4.7 kΩ pull-ups for safety.

Hardware

Complete Code

# 1) Activer I2C : sudo raspi-config > Interfacing > I2C
#    ou manuellement dans /boot/config.txt :
#    dtparam=i2c_arm=on
sudo reboot

# 2) Scanner le bus (le capteur doit apparaître, ici 0x77)
sudo i2cdetect -y 1
#!/usr/bin/env python3
"""Lecture brute d'un registre capteur via SMBus (adaptez l'adresse)."""
import smbus

BUS = smbus.SMBus(1)       # bus I2C1 cote linux (peripherique i2c-bcm2708)
ADDR = 0x77                # sortie de i2cdetect -y 1

val = BUS.read_byte_data(ADDR, 0x10)   # exemple de registre
print("registre 0x10 =", hex(val))

Expected Verification

i2cdetect -y 1 displays a grid with the sensor's address (never 00, nor reserved addresses). The Python script prints a non-zero value that changes if you warm the sensor between your fingers.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials