Wemos D1 Mini + AM2320

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
br0t
Posts: 12
Joined: Tue Dec 05, 2017 1:23 pm

Wemos D1 Mini + AM2320

Post by br0t » Mon Jan 22, 2018 6:14 pm

Hi everyone,

I am trying to connect an ESP8226 chip (~ Wemos D1 Mini) running Micropython to an AM2320 temperature/humidity sensor. I would like to make a few "remote sensors" that way and hook them up to small web app on a Pi to monitor that data across the house over the year.

I am having trouble reading the sensor data, even with an existing driver (https://github.com/mcauser/micropython-am2320); this stuff being pretty new to me I am not sure how to debug where the problem exactly is.

These are the exact products I bought, I hope it is okay to post them: Layout Image

Testing
I copied the am2320.py from https://github.com/mcauser/micropython-am2320 to the board and ran the following code to scan for anything found via the I2C protocol, but it always prints an empty list. This worked on my pyboard-lite, so the sensor seems to work, but I dont want to use that due to the missing wifi capabilities.

Code: Select all

import time
from machine import I2C, Pin
import am2320

while True:
    i2c = I2C(scl=Pin(5), sda=Pin(4))
    print(i2c.scan())
    time.sleep_ms(250)
The Problem
I can run the driver on the ESP8266 with the sensor being connected correctly (as far as I can tell, please see image below). I am not able to read any data from it, though. The thing is, I can read data from it on my pyboard-lite, so the sensor seems to be working. Maybe the problem is one the board or the way I put it together.

My Questions
  • Is there anything obviously wrong in my setup?
  • Do I need resistors or something else?
  • How would you go and debug hardware or software problems like this?
Any help would be greatly appreciated, I am here to learn and I am a little stuck right now :/

Thanks!
Last edited by br0t on Tue Jan 23, 2018 5:27 pm, edited 1 time in total.

User avatar
Frida
Posts: 45
Joined: Sat Jan 30, 2016 2:20 pm
Location: Middelfart, Denmark

Re: Wemos D1 Mini + AM2320

Post by Frida » Mon Jan 22, 2018 6:26 pm

On the picture is the orange wire and scl at one end and sda in the other.
With i2c, scl must be connected to scl and sda connected to sda.
In addition, pullup resistors are missing.
Yes Frida is my watchdog!

br0t
Posts: 12
Joined: Tue Dec 05, 2017 1:23 pm

Re: Wemos D1 Mini + AM2320

Post by br0t » Tue Jan 23, 2018 5:29 pm

Hi Frida and thanks for your response, it really helps. Now looking at it it is blatantly obvious and a bit embarassing really. The cables are correct though, I just got the markers mixed up in the image. I have now corrected that, thanks for pointing out.

Okay so I will figure out what those pull up resistors are and how to integrate them. If you have any tips for me how to calculate what kind of resistor I need, that would help a lot.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Wemos D1 Mini + AM2320

Post by pythoncoder » Tue Jan 23, 2018 5:42 pm

A value of around 4.7KΩ to 3.3V is typical but it's not critical.
Peter Hinch
Index to my micropython libraries.

br0t
Posts: 12
Joined: Tue Dec 05, 2017 1:23 pm

Re: Wemos D1 Mini + AM2320

Post by br0t » Tue Jan 23, 2018 7:07 pm

Thanks Peter, will get those and report back :)

User avatar
mcauser
Posts: 507
Joined: Mon Jun 15, 2015 8:03 am

Re: Wemos D1 Mini + AM2320

Post by mcauser » Wed Jan 24, 2018 2:28 am

Another option is, you can use the D1 mini's onboard 10k pull-up resistors instead of external ones on your breadboard.
Use D3 and D4 for SCL and SDA as they are have SMD pull-ups.
Doesn't matter which you use for SCL/SDA.

The downside is D4 is also used by the onboard LED, so it will flicker when you toggle it.

People typically use D1/GPIO5 and D2/GPIO4 for I2C, but you don't have to.
The I2C implementation is in software, so you can use any digital pin.

https://wiki.wemos.cc/products:d1:d1_mini

D3 = GPIO0, 10k pull-up - use this for SCL
D4 = GPIO2, 10k pull-up - use this for SDA

You should also move the i2c definition outside the while loop - you only need to define it once to use it.

Code: Select all

import time
from machine import I2C, Pin

i2c = I2C(scl=Pin(0), sda=Pin(2))
while True:
    print(i2c.scan())
    time.sleep_ms(250)

User avatar
mcauser
Posts: 507
Joined: Mon Jun 15, 2015 8:03 am

Re: Wemos D1 Mini + AM2320

Post by mcauser » Wed Jan 24, 2018 2:33 am

One thing I try to do with all of my breadboard wirings is use a standard colouring scheme.
Black = GND
Red = VCC
White = SDA
Yellow = SCL

Colour scheme borrowed from my adventures with Seeed Studio's Grove products:
https://www.seeedstudio.com/Grove-4-pin ... -1565.html

br0t
Posts: 12
Joined: Tue Dec 05, 2017 1:23 pm

Re: Wemos D1 Mini + AM2320

Post by br0t » Thu Jan 25, 2018 9:40 pm

Hi mcauser, thanks for your advice and all the background info, I really do appreciate that you took the time! This evening was full of learning and a bit of frustration.

Before I saw your comment I tried a setup very similar to what you used here https://github.com/mcauser/MicroPython- ... Nokia-5110, adding 4.7k and then 10k pull-up resistors in between the SDA/VCC and SCL/VCC. No success though.

I have then tried to use the onboard pull-ups as you described, by connecting to D3 and D4 (also changed to the color theme :D I think it is a great idea to standardize that):

Image

I used your exact code snippet from above, but I am still always printing an empty list (it did flicker on every iteration though, just as you said, so it is kind of doing something with that Pin at least). I tried two swap the sensor for another AM2320, also tried two different set of cables on different breadboards. Either I am doing something really wrong or I am starting to think that the board may have issues.

What do you think? Is there any way for me to debug that somehow? I have some other parts like LEDs lying around here that I could use maybe if that helped to find the actual problem. Or should I just try my luck and buy another board :/ ?

User avatar
mcauser
Posts: 507
Joined: Mon Jun 15, 2015 8:03 am

Re: Wemos D1 Mini + AM2320

Post by mcauser » Thu Jan 25, 2018 10:21 pm

Try reducing the I2C bus frequency and see if you scan picks up anything.

Code: Select all

i2c = I2C(scl=Pin(0), sda=Pin(2), freq=100000)
i2c.scan()
i2c = I2C(scl=Pin(0), sda=Pin(2), freq=50000)
i2c.scan()
i2c = I2C(scl=Pin(0), sda=Pin(2), freq=20000)
i2c.scan()
i2c = I2C(scl=Pin(0), sda=Pin(2), freq=10000)
i2c.scan()
Do you have any other i2c devices you can use to test?

br0t
Posts: 12
Joined: Tue Dec 05, 2017 1:23 pm

Re: Wemos D1 Mini + AM2320

Post by br0t » Thu Jan 25, 2018 10:39 pm

Ah cool, I did not realize that parameter was there. I just gave it a try, but for all frequencies it still does not find anything... sigh.

I have two other sensors but I think none of them are I2C compatible
- DSB1820 https://www.amazon.de/gp/product/B013GB27HS
- DHT22/AM2302 https://www.amazon.de/gp/product/B06XF4TNT9

I could still try and make them work via one-wire tomorrow, if that would give any insight?

Post Reply