Skip to content

Commit 8936edf

Browse files
committed
Обновил service_pack. Небольшой редизайн TMP117.
1 parent e6f1ecf commit 8936edf

File tree

8 files changed

+457
-231
lines changed

8 files changed

+457
-231
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 Roman Shevchik [email protected]
3+
Copyright (c) 2024 Roman Shevchik [email protected]
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Supply voltage TMP117 3.3 or 5.0 volts! Use four wires to connect (I2C).
99
3. SDA
1010
4. SCL
1111

12-
Upload micropython firmware to the NANO(ESP, etc) board, and then two files: main.py and tmp117ti.py.
12+
Upload micropython firmware to the NANO(ESP, etc) board, and then files: main.py, tmp117timod.py and sensor_pack_2 folder.
1313
Then open main.py in your IDE and run it.
1414

1515
# Pictures

main.py

+28-32
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,27 @@
1-
# micropython
2-
3-
# MIT license
4-
5-
61
# Please read this before use!: https://www.ti.com/product/TMP117
7-
from machine import I2C
8-
import tmp117ti
2+
from machine import I2C, Pin
3+
import tmp117timod
94
import time
10-
from sensor_pack.bus_service import I2cAdapter
5+
from sensor_pack_2.bus_service import I2cAdapter
116

127
if __name__ == '__main__':
138
# пожалуйста установите выводы scl и sda в конструкторе для вашей платы, иначе ничего не заработает!
149
# please set scl and sda pins for your board, otherwise nothing will work!
1510
# https://docs.micropython.org/en/latest/library/machine.I2C.html#machine-i2c
1611
# i2c = I2C(0, scl=Pin(13), sda=Pin(12), freq=400_000) № для примера
1712
# bus = I2C(scl=Pin(4), sda=Pin(5), freq=100000) # на esp8266 !
18-
# Внимание!!!
19-
# Замените id=1 на id=0, если пользуетесь первым портом I2C !!!
20-
# Warning!!!
21-
# Replace id=1 with id=0 if you are using the first I2C port !!!
22-
i2c = I2C(id=1, freq=400_000) # on Arduino Nano RP2040 Connect tested
13+
# i2c = I2C(id=1, freq=400_000) # on Arduino Nano RP2040 Connect tested
14+
i2c = I2C(id=1, scl=Pin(7), sda=Pin(6), freq=400_000) # on Raspberry Pi Pico
2315
adapter = I2cAdapter(i2c)
24-
# ps - pressure sensor
25-
ts = tmp117ti.TMP117(adapter)
16+
# ts - temperature sensor
17+
ts = tmp117timod.TMP117(adapter)
2618

2719
# если у вас посыпались исключения EIO, проверьте все соединения!
2820
# if you're getting EIO exceptions, check all connections!
2921
res = ts.get_id()
30-
print(f"chip_id: {hex(res)}")
22+
print(f"chip_id: {res}")
3123
# Таинственное число :-) mysterious number :-)
32-
nist = [hex(x) for x in ts.get_nist()]
33-
print(f"NIST: {nist}")
24+
print(f"NIST: {ts.get_nist()}")
3425
res = ts.get_config()
3526
print(f"config after __init__: {hex(res)}")
3627
ts.conversion_cycle_time = 7
@@ -46,32 +37,37 @@
4637

4738
print(20*"*_")
4839
print("Continuous conversion mode!")
40+
ts.start_measurement(single_shot=False)
4941
for _ in range(5):
50-
val = ts.get_temperature()
42+
val = ts.get_measurement_value()
5143
print(f"Temperature: {val} \u2103.\tSleep time: {sleep_time} [ms]")
5244
sleep_time = ts.get_conversion_cycle_time()
5345
time.sleep_ms(sleep_time)
5446

5547
print(20*"*_")
5648
print("One-shot conversion mode!")
57-
ts.conversion_mode = 0x03
58-
ts.set_config() # change mode
59-
for _ in range(100):
60-
if ts.is_data_ready():
61-
val = ts.get_temperature()
49+
ts.start_measurement(single_shot=True)
50+
sleep_time = ts.get_conversion_cycle_time()
51+
for _ in range(10):
52+
if ts.get_data_status():
53+
val = ts.get_measurement_value()
6254
print(f"Temperature: {val} \u2103.\tSleep time: {sleep_time} [ms]")
63-
ts.conversion_mode = 0x03
64-
ts.set_config() # re-launch conversion
65-
sleep_time = ts.get_conversion_cycle_time()
66-
# print(f"conversion time: {sleep_time} ms")
55+
ts.start_measurement(single_shot=True) # re-launch conversion
6756
# тройное время сна. 1/3 времени датчик работает и 2/3 времени датчик находится в режиме сна!
6857
time.sleep_ms(3 * sleep_time)
6958

7059
print(20*"*_")
7160
print("Reading using an iterator!")
72-
ts.conversion_mode = 0x00 # Continuous conversion mode
73-
ts.set_config() # change mode
61+
# Continuous conversion mode
62+
ts.start_measurement(single_shot=False)
63+
sleep_time = ts.get_conversion_cycle_time()
64+
_lim = 100
65+
_min_old = _lim
66+
_max_old = -1 * _lim
7467
for val in ts:
75-
sleep_time = ts.get_conversion_cycle_time()
76-
print(f"Temperature: {val} \u2103.\tSleep time: {sleep_time} [ms]")
7768
time.sleep_ms(sleep_time)
69+
_min = min(val, _min_old)
70+
_max = max(val, _max_old)
71+
print(f"Temperature: {val} \u2103.\tmin: {_min}\tmax: {_max}")
72+
_min_old = _min
73+
_max_old = _max

sensor_pack/base_sensor.py

-91
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
NAME = "base sensor MicroPython package"
2-
VERSION = "1.1"
2+
VERSION = "2.0"

0 commit comments

Comments
 (0)