Skip to content

Commit c6506ac

Browse files
author
Holger Fleischmann
committed
Packaged using setuptools for PyPi pip installation
1 parent c6f029e commit c6506ac

5 files changed

Lines changed: 116 additions & 15 deletions

File tree

README.md

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,78 @@ Supported:
77
* TSic 506
88
* TSic 706
99

10-
The module `tsic.py` requires Python 3 and the great library `pigpio` for GPIO access with precise timing.
10+
Don't forget the bypass capacitor as near as possible to the sensor's power supply pins to get stable behavior.
1111

12-
Note: Python 2 will not work.
12+
## Dependencies
1313

14-
It provides the following classes:
14+
The package `tsic` requires Python 3 and the great library `pigpio` for GPIO access with precise timing. Note that Python 2 will not work.
15+
16+
## Installation
17+
18+
Install from Python package index [PyPI](https://pypi.org):
19+
```
20+
pip3 install tsic
21+
```
22+
23+
## Usage
24+
25+
The module `tsic` provides the following classes:
1526
* `TsicInputChannel` receive temperature measurements
1627
* `Measurement` a temperature measurement
1728
* `TsicType` TSic type definition with instances `TSIC206`, `TSIC306`, `TSIC506`, `TSIC716` (206 and 306 are currently equivalent)
18-
* `ZacWireInputChannel` receive byte packets over ZACWire protocol (low-level handler for TsicInputChannel)
29+
* `ZacWireInputChannel` receive byte packets over ZACWire protocol (low-level handler for `TsicInputChannel`)
30+
31+
### Command Line Test Tool
1932

20-
See `example.py` for API usage or start `tsic.py <gpio-bcm> [--type {206,506,716,306}] [--loop]` to read temperatures from a GPIO pin (Broadcom numbering). See `tsic.py --help` for command line usage.
33+
Run `tsic <gpio-bcm> [--type {206,506,716,306}] [--loop]` to read temperatures from a GPIO pin (Broadcom numbering). See `tsic --help` for command line usage.
2134

22-
Example:
2335
```
24-
pi@raspi3:~/python-tsic $ sudo ./tsic.py 19 --type 306
36+
pi@raspi3:~ $ sudo tsic 19 --type 306
2537
Receiving data from TSic 206/306...
2638
Measurement 17.90°C at 2018-11-10 16:16:11.419573
2739
```
2840

29-
Greetings from Bavaria
41+
### Examples
42+
43+
From file `example.py`:
44+
```python
45+
import time
46+
import pigpio
47+
48+
from tsic import TsicInputChannel, Measurement, TSIC306
49+
50+
# TsicInputChannel and ZacWireInputChannel require pigpio
51+
# for GPIO access with precise timing:
52+
pi = pigpio.pi()
53+
54+
tsic = TsicInputChannel(pigpio_pi=pi, gpio=17, tsic_type=TSIC306)
55+
56+
print('\nA. Single measurement:')
57+
print(tsic.measure_once(timeout=1.0))
58+
59+
print('\nB. All measurements for 1 second:')
60+
tsic.start(lambda measurement: print(measurement))
61+
time.sleep(1)
62+
tsic.stop()
63+
64+
print('\nC. One measurement per second for 3 seconds:')
65+
66+
# start receiving in a context:
67+
with tsic:
68+
for i in range(3):
69+
time.sleep(1)
70+
measurement = tsic.measurement
71+
if measurement == Measurement.UNDEF:
72+
print(measurement)
73+
else:
74+
print('{:d} {:.1f}°C'.format(i+1, measurement.degree_celsius))
75+
76+
pi.stop()
77+
```
78+
79+
## Source Code
80+
81+
Hosted on [github.com/grillbaer/python-tsic](https://github.com/grillbaer/python-tsic)
82+
83+
With greetings from Bavaria,
3084
Holger

example.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
"""
77

88
__author__ = 'Holger Fleischmann'
9-
__copyright__ = 'Copyright 2018, Holger Fleischmann, Bavaria/Germany'
9+
__copyright__ = 'Copyright 2019, Holger Fleischmann, Bavaria/Germany'
1010
__license__ = 'Apache License 2.0'
1111

12+
import time
1213
import pigpio
14+
1315
from tsic import TsicInputChannel, Measurement, TSIC306
14-
import time
1516

1617
# TsicInputChannel and ZacWireInputChannel require pigpio
1718
# for GPIO access with precise timing:

setup.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import setuptools
2+
3+
with open("README.md", "r") as file:
4+
long_description = file.read()
5+
6+
setuptools.setup(
7+
name="tsic",
8+
version="1.2.0",
9+
author="grillbaer",
10+
author_email="holgflei+tsic@gmail.com",
11+
description="Receive temperature readings from TSic 206/306/506/716 sensor chips on Raspberry Pi",
12+
long_description=long_description,
13+
long_description_content_type="text/markdown",
14+
keywords=['raspberrypi', 'raspberry', 'tsic', 'gpio', 'temperature', 'sensor'],
15+
url="https://github.com/grillbaer/python-tsic",
16+
packages=setuptools.find_packages(),
17+
entry_points = {
18+
'console_scripts': ['tsic=tsic.tsic:main']
19+
},
20+
install_requires=[
21+
'pigpio'
22+
],
23+
classifiers=[
24+
"Programming Language :: Python :: 3",
25+
"License :: OSI Approved :: Apache Software License",
26+
"Operating System :: Other OS",
27+
"Topic :: Software Development :: Embedded Systems",
28+
"Topic :: Scientific/Engineering :: Physics"
29+
]
30+
)

tsic/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
__name__ = "tsic"
2+
3+
from .tsic import *

tsic.py renamed to tsic/tsic.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,26 @@
55
May be used as a command line tool for testing TSIC input.
66
"""
77

8-
__all__ = [ 'ZacWireInputChannel', 'Measurement', 'TsicInputChannel', 'Error', 'PigpioNotConnectedError' ]
8+
__all__ = [
9+
'ZacWireInputChannel',
10+
'Measurement',
11+
'TsicInputChannel',
12+
'Error',
13+
'PigpioNotConnectedError',
14+
'TSIC206',
15+
'TSIC306',
16+
'TSIC306',
17+
'TSIC716'
18+
]
919

1020
__author__ = 'Holger Fleischmann'
11-
__copyright__ = 'Copyright 2018, Holger Fleischmann, Bavaria/Germany'
21+
__copyright__ = 'Copyright 2019, Holger Fleischmann, Bavaria/Germany'
1222
__license__ = 'Apache License 2.0'
1323

1424
from datetime import datetime
1525
from functools import partial
16-
import argparse
1726
import logging
27+
import argparse
1828

1929
import pigpio
2030
import threading
@@ -379,8 +389,7 @@ def __repr__(self, *args, **kwargs):
379389
return self.__class__.__name__ + ' for GPIO ' + str(self.__zacwire_channel.gpio)
380390

381391

382-
if __name__ == '__main__':
383-
392+
def main():
384393
tsic_types = { '206' : TSIC206,
385394
'306' : TSIC306,
386395
'506' : TSIC506,
@@ -413,3 +422,7 @@ def __repr__(self, *args, **kwargs):
413422
pass
414423
finally:
415424
pi.stop()
425+
426+
427+
if __name__ == '__main__':
428+
main()

0 commit comments

Comments
 (0)