ds18x20_simpletest.py
1 # Simple demo of printing the temperature from the first found DS18x20 sensor every second. 2 # Author: Tony DiCola 3 4 # A 4.7Kohm pullup between DATA and POWER is REQUIRED! 5 6 import time 7 import board 8 from adafruit_onewire.bus import OneWireBus 9 from adafruit_ds18x20 import DS18X20 10 11 12 # Initialize one-wire bus on board pin D5. 13 ow_bus = OneWireBus(board.D5) 14 15 # Scan for sensors and grab the first one found. 16 ds18 = DS18X20(ow_bus, ow_bus.scan()[0]) 17 18 # Main loop to print the temperature every second. 19 while True: 20 print("Temperature: {0:0.3f}C".format(ds18.temperature)) 21 time.sleep(1.0)