Currently, I am working on a code to show the temperature and humidity in my Gui which will be imported to the main code. at first, I followed the tutorial on how to use the aht20: https://learn.adafruit.com/adafruit-aht ... cuitpython.
The example code is working well but my own code has a lot of errors.
Many thanks!
Code: Select all
import time
import board
import adafruit_ahtx0
class Temperature_Sensor:
def __init__(self):
i2c = board.I2C()
self.sensor = adafruit_ahtx0.AHTx0(i2c)
def run(self):
while True:
print("\nTemperature: %0.1f C" % self.read_temperature())
print("Humidity: %0.1f %%" % self.read_humidity())
# Code for temperature gauges...
temperature_top = self.read_temperature()
temperature_bottom = self.read_temperature()
# Code for humidity gauges...
humidity_top = self.read_humidity()
humidity_bottom = self.read_humidity()
time.sleep(2)
def read_temperature(self):
return self.sensor.temperature
def read_humidity(self):
return self.sensor.relative_humidity
# Creates an instance of the Temperature_Sensor class
sensor = Temperature_Sensor()
# Starts reading temperature and humidity
sensor.run()
[errors from this code]
Traceback (most recent call last):
File "/usr/local/lib/python3.9/dist-packages/adafruit_bus_device/i2c_device.py", line 175, in __probe_for_device
self.i2c.writeto(self.device_address, b"")
File "/usr/local/lib/python3.9/dist-packages/busio.py", line 196, in writeto
return self._i2c.writeto(address, buffer, stop=stop)
File "/usr/local/lib/python3.9/dist-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 52, in writeto
self._i2c_bus.write_bytes(address, buffer[start:end])
File "/usr/local/lib/python3.9/dist-packages/Adafruit_PureIO/smbus.py", line 320, in write_bytes
self._device.write(buf)
TimeoutError: [Errno 110] Connection timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/dist-packages/adafruit_bus_device/i2c_device.py", line 181, in __probe_for_device
self.i2c.readfrom_into(self.device_address, result)
File "/usr/local/lib/python3.9/dist-packages/busio.py", line 186, in readfrom_into
return self._i2c.readfrom_into(address, buffer, stop=stop)
File "/usr/local/lib/python3.9/dist-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 59, in readfrom_into
readin = self._i2c_bus.read_bytes(address, end - start)
File "/usr/local/lib/python3.9/dist-packages/Adafruit_PureIO/smbus.py", line 187, in read_bytes
return self._device.read(number)
TimeoutError: [Errno 110] Connection timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/Fiberneering/Desktop/rpi files GUI/temperature_Sense_FIB.py", line 35, in <module>
sensor = Temperature_Sensor()
File "/home/Fiberneering/Desktop/rpi files GUI/temperature_Sense_FIB.py", line 10, in __init__
self.sensor = adafruit_ahtx0.AHTx0(i2c)
File "/usr/local/lib/python3.9/dist-packages/adafruit_ahtx0.py", line 93, in __init__
self.i2c_device = I2CDevice(i2c_bus, address)
File "/usr/local/lib/python3.9/dist-packages/adafruit_bus_device/i2c_device.py", line 62, in __init__
self.__probe_for_device()
File "/usr/local/lib/python3.9/dist-packages/adafruit_bus_device/i2c_device.py", line 184, in __probe_for_device
raise ValueError("No I2C device at address: 0x%x" % self.device_address)
ValueError: No I2C device at address: 0x38