import machine
import onewire
import ds18x20
import time
# ────────────────────────────────────────────────
# Configuration – use ONE pin for ALL sensors
# ────────────────────────────────────────────────
DATA_PIN = 2 # ← Connect ALL data lines (yellow/white) here
# + one 4.7 kΩ pull-up from this pin to 3.3 V
# All sensors share same VCC --> 3.3 V, GND --> GND, DQ --> DATA_PIN
# Setup single 1-Wire bus
pin = machine.Pin(DATA_PIN)
ow = onewire.OneWire(pin)
ds = ds18x20.DS18X20(ow)
# Discover all connected sensors (should find 3)
roms = ds.scan()
print("Found devices:", [r.hex() for r in roms]) # nicer printing
if len(roms) == 0:
print("No sensors found – check wiring & pull-up resistor")
elif len(roms) < 3:
print(f"Warning: only {len(roms)} sensor(s) detected (expected 3)")
else:
print(f"Starting measurements – {len(roms)} sensors found")
while True:
ds.convert_temp() # Start conversion on ALL sensors at once
time.sleep_ms(750) # Wait (750 ms = safe for 12-bit resolution)
print("─" * 40) # visual separator
for rom in roms:
temp = ds.read_temp(rom)
short_id = rom.hex()[-8:] # last 8 chars usually enough to distinguish
print(f"{short_id} → {temp:5.2f} °C")
time.sleep(1)