Giter VIP home page Giter VIP logo

python_sensor_aht20's Introduction

AHT20 Temperature & Humidity for Python I2C

Standadone communication driver for the AHT20 Temperature & Humidity sensor, running on a Raspberry Pi on Python.

Pinout

The AHT20 sensor is connected to the Rasperry Pi via the following pins:

Pin # Pin Name Connection
1 3.3v Voltage in
3 GPIO2 I2C SDA
5 GPIO3 I2C SDL
9 GND Ground

The Raspberry Pi GPIO pinout map can be viewed here.

Pre-requistes

  • Raspberry Pi, but could run elsewhere
  • On the machine: python3-smbus installed
  • On Python: smbus2 installed

Notes

  • The I2C bus is 1 by default, as it's the default one for the Raspberry Pi. Another bus can be specified with the BusNum variable when calling the module.

Authors

Sources

python_sensor_aht20's People

Contributors

chouffy avatar xzf89718 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

python_sensor_aht20's Issues

Suggestion to change fixed SMBus bus address.

Lots of SBCs out there are NOT bus 1 for the default I2C bus.
Can I suggest changing:

def __init__(self):
    # Initialize AHT20
    self.cmd_soft_reset()

to

def __init__(self, I2CBusNum=1):
    # Initialize AHT20
    self.I2CBusNum = I2CBusNum
    self.cmd_soft_reset()

and all SMBus(1) to SMBus(self.I2CBusNum) ?
That should maintain backwards compatibility for anyone using this module and flexibility for people using boards like the Rock Pi 4

[Errno 121] Remote I/O error - AHT25 Sensor

Hi !

I try to write some python code for reading the AHT25 sensor.
The sensor is nothing special - only a humidity / temp sensor.

It´s connected to the Pi 4 directly with 15cm of wire cable to the I2C port of the Pi (Pin 3, 5).

If I use i2cdetect I can see the sensor:

pi@Pi4Test:~/python_sensor_aht20 $ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- 38 -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Using i2ctransfer works also with no problems:

pi@Pi4Test:~/python_sensor_aht20 $ i2ctransfer -y 1 w3@0x38 0xac 0x33 0x00 r6
0x98 0x74 0xeb 0x35 0xe4 0x92

And if I decode the resulting bytes I get plausible readings. I even can see that the temp rises when I touch the sensor.

Now I tried to read the sensor with your python lib but without any luck ...
I always got errors like this:

    i2cBus.write_i2c_block_data(AHT20_I2CADDR, 0x0, AHT20_CMD_SOFTRESET)
  File "/home/pi/messy/.virtualenvs/Source/lib/python3.11/site-packages/smbus2/smbus2.py", line 643, in write_i2c_block_data
    ioctl(self.fd, I2C_SMBUS, msg)
OSError: [Errno 121] Remote I/O error

Sometime I see Error 5, too (Input Output error)

I tried pullups with 2k2, 4k7 and 10k. But nothing seems to help.

Do you have any idea what can cause this errors? It´s frustrating ... All other sensors I try work like a charm. But this sensor drives me crazy :-)

Hope on any hint.

Dominik

Pinout for Raspberry Pi

Hello,

This looks like an awesome Python module to go along with the AHT20. Thanks for your work on this!

It looks like you are using hex values in the AHT20.py to define the pins on the Pi that the sensor is connected to.

Would it be possible to provide a pinout or picture of which pin is connected where?

That would be very helpful!

Thank you,
Cody Hill

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.