File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change 3737 https://github.com/adafruit/circuitpython/releases
3838"""
3939
40- # imports
41-
4240__version__ = "0.0.0-auto.0"
4341__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_US100.git"
4442
43+
4544class US100 :
4645 """Control a US-100 ultrasonic range sensor."""
4746
@@ -63,6 +62,9 @@ def distance(self):
6362 """
6463 self ._uart .write (bytes ([0x55 ]))
6564 data = self ._uart .read (2 ) # 2 bytes return for distance
65+ if not data :
66+ raise RuntimeError ("Sensor not found. Check your wiring!" )
67+
6668 if len (data ) != 2 :
6769 raise RuntimeError ("Did not receive distance response" )
6870 dist = (data [1 ] + (data [0 ] << 8 )) / 10
@@ -73,6 +75,9 @@ def temperature(self):
7375 """Return the on-chip temperature, in Celsius"""
7476 self ._uart .write (bytes ([0x50 ]))
7577 data = self ._uart .read (1 ) # 1 byte return for temp
78+ if not data :
79+ raise RuntimeError ("Sensor not found. Check your wiring!" )
80+
7681 if len (data ) != 1 :
7782 raise RuntimeError ("Did not receive temperature response" )
7883 temp = data [0 ] - 45
Original file line number Diff line number Diff line change 11import time
2+
3+ # For use with a microcontroller:
24import board
35import busio
46import adafruit_us100
5-
67uart = busio .UART (board .TX , board .RX , baudrate = 9600 )
7- # Create a US-100 module instance.
8+
9+ # For use with Raspberry Pi/Linux:
10+ # import serial
11+ # import adafruit_us100
12+ # uart = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=1)
13+
814us100 = adafruit_us100 .US100 (uart )
915
1016while True :
1117 print ("-----" )
1218 print ("Temperature: " , us100 .temperature )
19+ time .sleep (0.5 )
1320 print ("Distance: " , us100 .distance )
1421 time .sleep (0.5 )
You can’t perform that action at this time.
0 commit comments