Simple test¶
Ensure your device works with this simple test.
examples/tmp75_simpletest.py¶
1 2 3 4 5 6 7 8 9 10 11 12 | """Sample code and test for barbudor_tmp75"""
import time
import board
from barbudor_tmp75 import TMP75
i2c_bus = board.I2C()
tmp75 = TMP75(i2c_bus)
while True:
print("Temperature is %.2fC and %.2fF" % (tmp75.temperature_in_C, tmp75.temperature_in_F))
time.sleep(2.0)
|
Memory check¶
Show memory usage of the library.
examples/tmp75_memorycheck.py¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | """Memory test for barbudor_tmp75"""
# pylint: disable=unnecessary-semicolon,multiple-statements,wrong-import-position,no-member
import gc
import board
i2c_bus = board.I2C()
gc.collect(); gc.collect(); gc.collect(); before = gc.mem_free();
from barbudor_tmp75 import TMP75
gc.collect(); gc.collect(); gc.collect(); after = gc.mem_free();
tmp75 = TMP75(i2c_bus)
gc.collect(); gc.collect(); gc.collect(); instance = gc.mem_free();
print("Import used : %d bytes" % (before - after))
print("Instance used : %d bytes" % (after - instance))
|
Adafruit IO (RPi/BB only)¶
Publish temperature on Adafruit IO from Raspberry Pi or Beagle-Board.
examples/tmp75_adafruitio.py¶
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | """
'tmp75_adafruitio.py'
==================================
Testing TMP75 library on RaspberryPi using blinka and AdafruitIO
Author(s): Barbudor, Based on Brent Rubel "temp_humidity.py"
Dependencies:
- Adafruit Blink (CircuitPython on Raspberry PI)
(https://github.com/adafruit/Adafruit_Blinka)
- Adafruit IO Python Client
(https://github.com/adafruit/io-client-python)
- Adafruit_Python_DHT
(https://github.com/adafruit/Adafruit_Python_DHT)
"""
# import standard python modules.
import time
# import barbudor TMP75 library
import board
import barbudor_tmp75
# import Adafruit IO REST client.
from Adafruit_IO import Client, Feed, errors
# Set to your Adafruit IO username.
# Set to your Adafruit IO key.
# Remember, your key is a secret,
#ADAFRUIT_IO_USERNAME = 'YOUR_AIO_USERNAME'
#ADAFRUIT_IO_KEY = 'YOUR_AIO_KEY'
# keep your username and secret key in a shared module
from aoi_key import ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY
# Delay in-between sensor readings, in seconds.
READ_TIMEOUT = 5
# Name of the Adafruit IO feed
FEED_NAME = "tmp75"
# Create an instance of the REST client.
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
# Set up Adafruit IO Feeds.
try:
tmp75_feed = aio.feeds(FEED_NAME)
except errors.RequestError:
feed = Feed(name=FEED_NAME)
tmp75_feed = aio.create_feed(feed)
print("Created feed %s" % FEED_NAME)
# Set up TMP75 Sensor
tmp75_sensor = barbudor_tmp75.TMP75(board.I2C())
tmp75_error = False
while True:
try:
if tmp75_error: # if an error occured, re-write config register with 12 bits mode
# pylint: disable=protected-access
tmp75_sensor.config = barbudor_tmp75._CONFIG_CONVERTER_12BITS
# pylint: enable=protected-access
temp = '%.2f'%(tmp75_sensor.temperature_in_C)
print('Temp2=%sC'%(temp))
aio.send(tmp75_feed.key, temp)
tmp75_error = False
except OSError:
print('Failed to read TMP75, trying again in ', READ_TIMEOUT, 'seconds')
tmp75_error = True
# Timeout to avoid flooding Adafruit IO
time.sleep(READ_TIMEOUT)
|