- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.py
More file actions
Latest commit
executable file
·43 lines (32 loc) · 1.05 KB
/
Copy pathexample.py
File metadata and controls
executable file
·43 lines (32 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/python3
"""
Examples of how to use the TSIC 206/306 temperature reading class
on a Raspberry PI.
"""
__author__='Holger Fleischmann'
__copyright__='Copyright 2019, Holger Fleischmann, Bavaria/Germany'
__license__='Apache License 2.0'
importtime
importpigpio
fromtsicimportTsicInputChannel, Measurement, TSIC306
# TsicInputChannel and ZacWireInputChannel require pigpio
# for GPIO access with precise timing:
pi=pigpio.pi()
tsic=TsicInputChannel(pigpio_pi=pi, gpio=17, tsic_type=TSIC306)
print('\nA. Single measurement:')
print(tsic.measure_once(timeout=1.0))
print('\nB. All measurements for 1 second:')
tsic.start(lambdameasurement: print(measurement))
time.sleep(1)
tsic.stop()
print('\nC. One measurement per second for 3 seconds:')
# start receiving in a context:
withtsic:
foriinrange(3):
time.sleep(1)
measurement=tsic.measurement
ifmeasurement==Measurement.UNDEF:
print(measurement)
else:
print('{:d} {:.1f}°C'.format(i+1, measurement.degree_celsius))
pi.stop()