Back to Hub | RP2040 MicroPython Lab
1-Wire Bus Active

🌊 Waterproof DS18B20 & 16-Bit Register Math

Simulate submerged thermal sensing, 3.0V–5.5V supply voltage, Parasite Power Mode, 64-bit ROM addressing, and Hex → 16-Bit → 12-Bit Fixed Point Conversion.

🧪 Submerged Stainless Steel Probe Tank Power: 3.3V Normal (3-Wire)
RP2040 BOARD 3V3 ──┐ GP22 ──┼── DQ GND ──┼── GND 4.7kΩ DS18B20 Die Temp: 25.00°C VCC: 3.3V Normal
📊 Live Hex → 16-Bit → 12-Bit Fixed Point Conversion 1 LSB = 0.0625°C
Byte 0 (LSB): 0x90
Byte 1 (MSB): 0x01
16-Bit Scratchpad Register Layout: 0x0190
S
S
S
S
S
2⁶
2⁵
2⁴
2³
2²
2¹
2⁰
2⁻¹
2⁻²
2⁻³
2⁻⁴
0000 0001 1001 0000
Step 3: Convert 16-Bit Signed Integer to Temperature (°C):
Temp (°C) = 400 / 16 = 400 × 0.0625°C = 25.00°C
🎛️ Interactive Wiring & Thermal Controls
25.00 °C
-10°C (Freezing Ice) 25°C (Room Temp) 100°C (Boiling Point)
60 % Submerged
📡 Dallas 1-Wire ROM & Scratchpad RAM Addressable

Every DS18B20 contains a unique 64-bit laser-etched ROM code. Multiple waterproof sensors can share the exact same GP22 data wire:

Unique 64-Bit ROM ID (roms[0]):
bytearray(b'\x28\xFF\x64\x1E\x82\x22\x04\x9B')
Family: 0x28 Serial: 48-Bit Unique CRC: 0x9B
Scratchpad Temperature Register (Bytes 0 & 1):
Raw Hex: 0x0190 12-Bit Temp: 25.00°C
🐍 MicroPython 1-Wire Driver Code RP2040 Executing
import machine, onewire, ds18x20, time

# Configure 1-Wire bus on GP22 (4.7kΩ pull-up)
ow = onewire.OneWire(machine.Pin(22))
ds = ds18x20.DS18X20(ow)

# Scan bus for sensor ROM IDs
roms = ds.scan()

while True:
  ds.convert_temp() # Start 12-bit ADC conversion
  time.sleep_ms(750) # Required 750ms conversion delay
  for i in range(len(roms)):
    t = ds.read_temp(roms[i]) # 25.00°C
    print("Sensor:", roms[i], "Temp:", t)
  time.sleep(1)
📝 Power & 1-Wire Protocol Quiz
How does MicroPython derive temperature in °C from the DS18B20 16-bit raw integer register?