Temperature Sensor Wireling Python Tutorial
This Wireling features the PCT2075 Temperature Sensor. This sensor has a range of -55°C up to 125°C and communicates over the I²C bus.
- Temperature range from -55°C up to +125°C
- 11 bit ADC that offers a temperature resolution of 0.125°C
- Temperature accuracy of:
- ±1 °C (max.) from -25 °C to + 100 °C
- ±2 °C (max.) from -55 °C to + 125 °C
- Programmable temperature threshold and hysteresis set points during operation
- Supply current of <1.0 µA in shut-down mode for power conservation
- Stand-alone operation as thermostat at power-up
- Voltage: 3.0V - 5.5V
- Current: 70.0 µA (Normal Mode). Due to the low current, this board can be run using the TinyDuino coin cell option
- Current: <1.0 µA (Shut-Down Mode)
- A5/SCL - I²C Serial Clock line
- A4/SDA - I²C Serial Data line
- 10mm x 10mm (.393 inches x .393 inches)
- Max Height (from the lower bottom of Wireling to upper top Wireling Connector): 3.70mm (0.15 inches)
- Weight: 1 gram (.04 ounces)
- Raspberry Pi and any other cables you'll need!
- Wireling Pi Hat
- (1) Wireling Cable
- Temperature Sensor Wireling
- Python 3 (Python 2 is not supported!)
- All Python packages mentioned in the Pi Hat setup tutorial (tinycircuits-wireling, adafruit-circuitpython-pct2075, adafruit-circuitpython-ads1x15, and adafruit-circuitpython-busdevice)
- Temperature Sensor Wireling Python Example
Plug your Wireling into the port you plan on using! The default in the included program is port 0.
If you want to use a different port, you just need to change the port value in the program mentioned later.
Note: Essential Modification
Due to the peripherals included on the Pi Hat, an addressing resistor must be removed from the Wireling to be compatible. For this tutorial, we removed resistor A0 to set an address of 0x2C. This is different from the 0x48 address used by default. If the Wireling is modified by removing the A0 resistor, there will be no conflicts with any other Wirelings.
Be mindful of this address change if trying to use this Wireling with our sample Arduino code!
Install the necessary Python package:
pip3 install adafruit-circuitpython-pct2075
Then you can download (above under Software) the Ambient Light Sensor Wireling example:
# TinyCircuits Temperature Sensor Wireling Example # Prints temperature value every 2 seconds. # Initialized: 01-24-2020 # Last Updated: 01-24-2020 import time import board import busio import tinycircuits_wireling import adafruit_pct2075 # Initialize and enable power to Wireling Pi Hat wireling = tinycircuits_wireling.Wireling() # Toggle this variable to use the Light Sensor Wireling on a different port (0-3) port = 0 wireling.selectPort(port) i2c = busio.I2C(board.SCL, board.SDA) pct = adafruit_pct2075.PCT2075(i2c, address=0x2c) pct.high_temperature_threshold = 35.5 pct.temperature_hysteresis = 30.0 pct.high_temp_active_high = False print("High temp alert active high? %s"%pct.high_temp_active_high) # Attach an LED with the Cathode to the INT pin and Anode to 3.3V with a current limiting resistor while True: print("Temperature: %.2f C"%pct.temperature) time.sleep(2)
The program by default is written to work with Port 0 on the Wireling Pi Hat.
Navigate in the terminal to the directory where you downloaded or saved the python example and run:
Be sure pigpiod is running before you attempt to run the python program. This is done by running the following command:
The program will print the temperature reading from the sensor every 2 seconds.
Thanks for making with us!