mcauser / micropython-am2320

MicroPython driver for the Aosong AM2320 temperature and humidity sensor
MIT License
25 stars 6 forks source link

am2320.py got error: File "<stdin>", line 5, in <module>, File "am2320.py", line 22, in measure #3

Closed ds2k5 closed 6 years ago

ds2k5 commented 6 years ago

Hello, tryed to use you am2320.py

  1. wget https://raw.githubusercontent.com/mcauser/micropython-am2320/master/am2320.py
  2. ampy --port /dev/ttyUSB0 put am2320.py
  3. picocom --port /dev/ttyUSB0
  4. Cnrtl+E
  5. "input your code"
  6. Cntrl+D

Traceback (most recent call last): File "", line 5, in File "am2320.py", line 22, in measure OSError: [Errno 19] ENODEV

mcauser commented 6 years ago

The script can't find the sensor on your I2C bus. What dev board are you using? What ports are you using? Are you using I2C pull ups on the SCL+SDA lines?

ds2k5 commented 6 years ago

The script can't find the sensor on your I2C bus.

What dev board are you using?

Board: ESP8266, NodeMcu v3 https://dziadalnfpolx.cloudfront.net/blog/wp-content/uploads/2015/09/esp8266-nodemcu-dev-kit-v3-pins.jpg

D1 (GPIO5)

D1 ---> DHT-22 PIN2 3V ---> DHT-22 PIN1 G ----> DHT-22 PIN4

import am2320 from machine import I2C, Pin i2c = I2C(scl=Pin(5), sda=Pin(4)) sensor = am2320.AM2320(i2c) sensor.measure() print(sensor.temperature()) print(sensor.humidity())

mcauser commented 6 years ago

Few problems here. a) This is a driver for the AM2320, not the DHT22. The AM2320 is a newer black version of the DHT22. b) This driver only supports the I2C interface, not 1-wire. c) You need pull-ups on the I2C bus, on pins D1 (GPIO5) and D2 (GPIO4), or switch to pins D3 (GPIO0) and D4 (GPIO2) and use the onboard pull-ups.

ds2k5 commented 6 years ago

Thanks mcauser, i have a white AM2302 - sorry