Flying Weather bits – the ESP-01 and sensors

The last few years I have been helping support an enterprise wireless network of 2,000+ access points. It is an interesting, challenging, nightmarish world wireless/RF is. When I started my Arduino adventure it was nice to be grounded in what I was working on. The wires carried all of the data I needed. I just need to make sure the wire was connected, not like those nasty RF signals that bump into other signals that might mess with this or that.

Alas, during my 1st weather project, while I was running back and forth with my data written to a SD card, I thought how much easier this would be if only I could do this with wireless.

In my research, I found information scattered hither and yon, each yielding news clues. I will try and link to those sites (I have remembered and bookmarked) throughout. I will post, what I thought, are the more important bits and pieces.

Project Goal

My requirements are simple. Use a DHT22 to take temp and humidity readings every 5 minutes. Take that data to a central point and log it with the ability to graph and compare it. Initially using USB and a converter for power, moving to own power supply.

** NOTE: I am going to be also working with a BME/P280 to see how to setup and work with I2C on the ESP-01. There are a couple of methods I will point out later on. 

I have seen where people use cloud services to keep their data. I have taken this into serious consideration, but am leaning towards a local solution. I have seen one that look promising, Domoticz. It is open source and can be run off of multiple platforms. I have recently received my Raspberry Pi 3 so I am going to try and it get it working there, but that is another day and another post.

Down to business

I crawled down into my abyss of a workbench and dug around. I knew that there was this 8266 thing what was supposed to do wireless and that I could hook it up to my Arduino. And in one of my orders I had tossed on a couple of different ESP8266 modules. There are plenty to choose from. I chose these 2 because they seemed pretty popular and I couldn’t beat the price. I have the ESP-01 and ESP-12E. The later is in the form of the NodeMCU v1.0 board with plenty of pins to work with. The ESP-01 is a simple, 8-pin module, yet with all the power of the 12E. After about 20 minutes of digging how to get the Arduino to talk to the EPS, I found out I could just write my code to the ESP and use it as both the processor and wireless device. Jack Pot! A temp sensor is always seems to be laying around somewhere and a DHT22 will work prefect.

A Quick BOM

  • 1 x ESP-01S
  • 1 X DHT22 (or whatever temp sensor you have around – be sure and sure the correct libraries.)
  • 1 x USB – UART convertor

 

The ESP-01

The ESP-01, as I have stated is the lowest, if you will, of the ESP8266 family. There is still plenty that can be done with it. Below is a diagram I found on deviantart of the pinouts.

For programming reference, pins TX and RX are GPIO 1 and 3. I found this useful when trying to get my I2C setup working. See my link at the end.

Also, the ESP-01 is pretty picky about its’ 3.3v limitation on pins. One of my first times working with it went up in the puff of magic smoke. Good thing I always oder at least 2.

Here is one of the sources I found for pin information. It is a very useful Instructable on the ESP-01.

The Plan

Here is a schematic of it from my notes. I was at work and the pencil and paper were quicker. I haven’t had the time to whip it up in Fritz’ yet.

I took to the internet and dug up a wiring diagram for the ESP for programming it. I like to take multiple approaches to this part of the process. There is the quick and dirty, plug it in and get it going and then the old school way I will call it. I did old school first.

** an error was pointed out to me during this project. The CH_PD pin should be pulled high during operation and low for programming. Currently I have mine floating, but will fix it in the next revision. It does work, but I am not sure what impact it may have in extended operation. I will update my documentation when I get it in Fritzing. 

In this example, the ESP is wired to an Arduino Uno. The two buttons are for Reset and Flash. Don’t mind the second ESP in the background, it was for another experiment.

Here is one of the sites I found useful in my quest for an ESP programmer.

*schematic from allaboutcircuits.com Next was the quick and dirty way, which wasn’t so quick an dirty in the end. Even it took some work. The board I got doesn’t have the CH_PD pin set to ground, which is required for programming. No problem since I have two of them, I took one of them and soldered a short wire connecting CH_PD pin to the Ground pin. I have it labeled for quick ID and use it for programming and the other for quick testing.

Coding

Next was how to make this little devil do something. Through my research much of the code can work, along with some of the Arduino libraries. Work has been done so that one can write a sketch and upload it through the Arduino IDE. There are other toolchains one can use as and they work quite well.

I found a couple of quick sketches where I poked around the code, uploaded them to see what and how they worked. I find that between reading the .h file of the library and an short example is the best way to learn what one can get done. I started to work on a sketch that would take a reading every minute and post it to a web page. Pretty simple and straight forward, but that is all I need right now. I only have a temp sensor and ESP.

On one of the forums I found a link to ESP Easy and it aims to be what the name claims. Essentially it is a sketch that one uploads to a ESP module. From there connect to it via wireless to initially set it up for the local wireless and then reconnect to it to control the configuration of devices and the such. Really quite fun to play around with. I need up using this for the time being. I was able to put something together over a couple hours in the lab.

Here is the link to the github for setting up the Arduino IDE for use the the ESP8266 family. The quick and dirty to setting it up is as follows.

  1. Quit the IDE or install the Arduino IDE from the Arduino website.
  2. Launch the Terminal.app.
  3. Enter in the command sudo pip install pyserial and hit return.
  4. Enter in the command sudo pip install esptool and hit return.
  5. Start Arduino and open Preferences window.
  6. Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into Additional Board Manager URLs field. You can add multiple URLs by separating them with commas.
  7. Open Boards Manager from Tools > Board menu and install esp8266 platform (and don’t forget to select your specific ESP8266 board from Tools > Board menu after installation).

The ESP is wired on the breadboard by the following. This will be the same wiring used on the protoboard final.

ESP

  •         Gnd -> Gnd
  •         Vcc -> 3.3v (from USB converter)
  •        Pin GPIO2 -> Signal from DHT22

DHT22

  •        Gnd -> Gnd
  •        Vcc -> 3.3V
  •        Signal -> GPIO2

Well, it is working on the breadboard and pretty cool for a first time ESP project. It would look pretty silly in it current state hanging from the wall. Time to go digging around in my Sanford and Son section of the lab. I dug up one of the covers that was used in an original Apple Airport. Seems like it will fit the bill. With two brass standoffs and some hot glue I mounted everything neat and orderly.

For this first station I have it mounted outside the door of my lab in the basement. It fires right up and works like a charm.

Here I took a brief fork in my academic travels. I took a day off from the above project. I did a little writing, working with the Nodemcu (but that is another post altogether), and thinking about the next sensor module I wanted to put together. I have it breadboarded and it works, it should be easy enough to put it on a protoboard; so he says.

I start with the basic layout. I think it is nice during this stage to start to think about how one would layout the traces for a PCB. My mind is already thinking that I might get 3-5 made as I need a few more for my project. The connections are as follows:

 

I layout and dry fit all of the components. For this version I didn’t have any female headers laying around so I solder the ESP-01 module directly to the board. I layed out the wire for the programming pins so I can make any changes I might want to it.

I used 24awg solid core wire for the wired connections.

My original plan has my own power supply. It is mostly working, but I have a leak somewhere. The power supply is straight forward. I use a LD1117 to convert 5v down to 3.3v. The capacitors are added to help smooth the power line. And of all times my Fluke is down, so this is on the sidelines right now. In the mean time, I am using the USB-Serial converter for my power supply. It provides an nice, steady 3.3v.

Here is the final product. The ESP comes up and I can connect to it via the web, but the sensor is not providing data. I have check my connections and voltages and the are working, but now it is time to dive deeper into hardware troubleshooting when it is all soldered together.

Well, after a pat on my back when it all powered up and the blue light started to blink, my smile quickly left. I launched the browser and went to the IP address and got nothing from the sensor. I know that it worked on the breadboard, what it up here? It was too late, time to head to slumber and figure it out tomorrow. A second look the next day and it popped out at me pretty quick. I soldered the signal wire at the wrong end of the resistor. Instead of pulling a little power from the Vcc line, it was getting flooded. 

Once I made the change, things are up and going. In the mail today, the charger/battery boards showed up. The last thing is to solder it up and connect the battery. I will be leaving in indoors for a couple of days while I work on a case for it for outside. I am not yet lucky enough for a 3D printer, but plenty creative with what I have buried away.

I also got some feedback on my power supply. There seems to be an issue with one of the caps I am using. Tonight I will replace it and see if that fixes it. I will be sure and update this and let you know.

I2C and the ISP-01

And on an ending note (???) one of my next remote sensors will include an I2C sensor, the BME280. It adds the feature of barometric pressure as well as the temperature and humidity. It is pretty straight forward. I have used it on the Arduino Uno. It was figuring out how to implement I2C on the ESP-01 that had me scratching my head for a spell.

Then I stumbled upon the magic pins web site. This is a great site on using the available pins on the ESP-01. With some creativity there is quite a bit one can pull out of the small module.

My current attempt at getting this to work is using the TX and RX pins for the I2C. I have it drawn up and ready to try. I will be back with more when I have it working.

The WeatherProject

A simple project has run into that infamous scope-creep but in a good way. To that end, I decided to take the little bits and pieces I have scattered on the web and condenses them into one place, a domain I have had sitting around just looking for a purpose and these does seem to be at great one.

 

Arduino Basic Indoor Weather Station

This project is for a basic, Arduino based, weather monitoring station. While this project is for indoor use only, one could easily find an appropriate weather proof case; and using battiers or solar power with wireless place it outside. This kit is meant as an introduction to the Arduino platform, using sensors, and a door to a fun world.

Parts needed:

1 x Arduino Uno clone
1 x 25cm micro USB data cable
1 x DHT22 sensor
1 x BMP280 sensor
1 x 5110 84×48 LCD screen
xx x Male to Female Jumper Cables
xx xx Female to female Jumper Cables
2 x 10k resistors – for sensors
1 x 470Ohm resistor – for LCD

Software needed:

Arduino IDE 1.6.x Various Libraries, find links in the docs.

Let’s get started!

The order of the parts listed below are the order I wired up and tested each part. It makes trouble shooting easier to take each component, wire it up, install the library, load a test sketch, and make sure it works. Nothing is more frustrating than plugging in 14 wires and nothing happening.

Be sure and check your connections. I will admit to pulling an oops and damaging a component by not paying attention to where those pesky Vcc and ground wires were going. If you have issues, check your wiring first. If you have a multimeter, you can also make sure you have continuity and expected voltages.

The DHT22

DHT22 Pins Arduino Pins
1 – Vcc 5v
2 – Signal + 10k 2
3 – Open Open
4 – Gnd Ground

The DHT22 is a low-cost, but accurate, digital temperature and humidity sensor. It has a captive humidity sensor and a thermistor for reading the ambient temperature. It is 3-6v tolerant for both the Vcc (power in) and digital signal line (pin 2). The pins are 1 -4, left to right, looking at the front (the grill side).

Arduino pin 2 is used in this sketch, but any other pin could be used.

Here is a link to the DHT22 datasheet.

The BMP280

BMP280 Pins Arduino Pins
Vcc 5v
Gnd Ground
SCL A5
SDA A4
CSB Open
SD0 High – 0x76
Low – 0x77

The BMP280 is a barometric pressure and temperature sensor. It is a sensor with great accuracy. In fact with a little work one can obtain an altimeter reading within +/- 1M the sensors are so accurate. (I haven’t tested that claim yet) It communicates with the Arduino via the I2C interface. The address must be set either high or low as if it is left at default it won’t work. To set the address high (0x76) use a 10k resistor and connect it to power. If you connect it to ground in the same fashion it will use the low address (0x77).

A good troubleshooting tool to use when first working with I2C is an I2C Scanner. There is a copy of it in my github. I have started a cheatsheet list of the devices I have and what addresses they have. Each time I get a new one I will run it against i2c to make sure it works and see what address to use. 

Here is a link to the BMP280 datasheet.

And here is the link to the BME280 library used here.

The LCD

LCD Pin Arduino Pin
1 – RST 12
2 – CE 11
3 – DC 10
4 – Dir 9
5 -Clk 8
6 – Vcc 3.3v
7 – BL 7 – with 470Ohm resistor
8 – GND Ground

The LCD is based on the old Nokia 5110 LCD screen used in their past phones. It is a decent sreen and easy to find. Its’ display is 48 rows by 84 columns. It has a PCD8544 controller used for all LCD functions. This model uses SPI for its communication with the Arduino. There are other ones out there that use the I2C protocol which only requires 4 pins. There are some different libraries out there too. I used xxx in this project. The basic functions are well-documented and they also have an additional library with graphical functions.

To Do:
Keeping some historical data and being able to graph them over time is a good additional project. One could store the data on an SD card or rely it via wireless. There is a section of code that shows how to output data in a CVS format for later analysis. 

The library used is located here.

Code it up

As of this writing the lastest version of the sketch is 0.6. Check back for updated versions. I have tried to comment the code to make it easy to follow. I know that good comments make it easier to follow along what is happening. And when one is learning this is a good thing.

Launch the Arduino IDE, open up the sketch Weather0.6.ino found in this github. From the Tools, make sure you are working with the right board, both model and serial port used. A quick verify and compile, then upload. If you have not used the Arduino IDE before there are several great tutorials out there. Here is a good starting point for the first timers, head to this Instructable. Launch the Arduino IDE, open the weather sketch.