ESP8266 Library Released for AM2315 Temp/Humidity Sensor

ESP8266 Library Released for AM2315 IMG_3366Temp/Humidity Sensor

SwitchDoc Labs has just released a modified Adafruit library for the AM2315 Encased I2C Temperature and Humidity sensor for the ESP8266.   The current set of Adafruit drivers do not work reliably with ESP8266 products and so we went in and figured out what was wrong.

Download the SDL_ESP8266_AM2315 libraries here on github.

What is the ESP8266?

The ESP8266 is made by a privately held company in China called Espressif.   They are a fabless semiconductor company that just came out of nowhere and Figure3shook up the whole industry.   Now all the major players are working on inexpensive versions of an IOT chip with WiFi connectivity.  And they are all struggling to make it as inexpensive as the ESP8266.

SwitchDoc has produced a series of tutorials on the ESP8266 software here and building a solar powered ESP8266 here.

What is the AM2315 Temp/Humidity Sensor?

The AM2315 I2C encased capacitive humidity sensing digital temperature and humidity sensor contains a temperature and humidity combined sensor calibrated digital signal device. It uses special temperature and humidity acquisition technology, to ensure that the sensor has high reliability and excellent long-term stability. The sensor includes a capacitive sensor and an integrated high-precision temperature measurement device.

This probe has been used in numerous SwitchDoc Labs projects including Project CuracaoWeatherPi and the  SunRover solar powered robot.

What was changed in the libraries?

There were two major things that had to be changed.

First, there are ESP8266-12 modules that have pins 4 and 5 reversed. Early boards from Adafruit had this problem and the problem exists in other boards out there on the market. The ESP8266 module we are testing has these lines reversed, hence the statement

Wire.begin(5,4);

If you have a board with the correct lines, put in the statement

Wire.begin(4,5);

Secondly, as written, the drivers would not work reliably with the ESP8266.  Occasionally a value might come through, but by and large, the AM2315 would not work.   After serious experimenting, it was found to be a timing problem with talking to the AM2315 from the ESP8266.   The AM2315 is well known for being sensitive to timing issues, and by the way, will rarely respond to an I2C scan (such as I2cScanner) even though it is connected correctly to the I2C bus.

Adding 50 msec delays between the reads inside the driver fixed the problem:

 delay(50);

2 Comments

  1. Great info. It’s nice to know that these more accurate devices are also supported. Fortunately for me, my needs are currently met with the dht-22 for less than 1/10th the price of the AM2315. For those requiring more accurate and an encased solution, the AM2315 might be just the thing.

    • Completely understand your points. We used the DHT-22 on Project Curacao but it did not work so well on the Raspberry Pi with all of the other processes running on the Pi A. Using a multitasking operating system like Linux (as on the Raspberry Pi) WILL cause occasional errors. However, you can apply a “reasonableness test with the checksum” to the data after getting the DHT22 data and catch most, if not all, of those errors. We also wanted something more weather resistant with more accuracy. And for a lot of reasons, the ease of using an I2C interface allows us to put things farther away from the computer. All those reasons That’s why we started using the AM2315. By the way, the AM2315 is $23. Can you get the DHT22 for $2.30? Wow. The cheapest we have seen it is about $5.00. The same company (AOSONG) makes both the DHT22 and the AM2315.

      Best regards,
      SDL

Comments are closed.