Skip to content

Commit 6a2a095

Browse files
authored
Create simpletest.py
1 parent 03e4ae0 commit 6a2a095

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

examples/simpletest.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Simple demo of printing the temperature from the first found DS18x20 sensor every second.
2+
# Author: Tony DiCola
3+
import time
4+
5+
import board
6+
7+
from adafruit_onewire.bus import OneWireBus
8+
from adafruit_ds18x20 import DS18X20
9+
10+
11+
# Initialize one-wire bus on board pin D5.
12+
ow_bus = OneWireBus(board.D5)
13+
14+
# Scan for sensors and grab the first one found.
15+
ds18 = DS18X20(ow_bus, ow_bus.scan()[0])
16+
17+
# Main loop to print the temperature every second.
18+
while True:
19+
print('Temperature: {0:0.3f}C'.format(ds18.temperature)))
20+
time.sleep(1.0)

0 commit comments

Comments
 (0)