Wednesday, October 28, 2015

ESP8266 temperature sensor final form

After toying with Lua on the ESP8266 and finding that it was not stable (stopped answering web requests after an hour or so) I went back to Arduino.  That seems stable, I let it run for two days hitting the server once a minute and it stayed up the whole time.

I cleaned up the code and am happy with the results now.  Here's a rundown of all the steps needed to replicate this.

First, I have the ESP8266 module, the one with an 8 pin header.  The wiring for it is as follows:

I created a home for it using a bit of perfboard. I really love these little board, you can buy them for pennies on eBay. I use them for all kinds of little junk like this.

On the left there is the power input.  The ESP board is plugged into a female header so it can be removed. Under the ESP board is a little slide switch; moving the switch up pulls GPIO0 down which puts it into bootloader mode.  The DS18B20 is plugged into the little 3 pin socket on the upper right there, the resistor is required for its operation.  The big black 5 pin connector on top goes to the serial programming interface.

Since taking that picture I've added a voltage regulator, which is mostly underneath, there's a capacitor on top now as well.
This is just a standard AMS1117 low dropout voltage regulator.

All the wiring was done underneath using wirewrap wire, which is convenient for simple circuits like this.

I'll try to do a schematic for this eventually, but mean time:

The power input (usually 5V) goes through the regulator and capacitors. 

The 3.3V output from the regulator then goes to the ESP module's VCC and CH_PD lines, the "not programming" side of the slide switch", one end of the resistor and the DS18B20's VCC.

Ground goes to the regulator's ground, ESP's ground, the "programming" side of the slide switch and the DS18B20's ground.

The other end of the resistor goes to the data pin on the temp sensor, then into GPIO2 on the ESP module.

GPIO0 on the ESP module goes to the center of the switch.

The TX line on the ESP goes to the RX on the serial programmer, and RX on the ESP goes to TX on the programmer.

Here's the code for this:

There are instructions in the comments right at the top of that code on how to set up the Arduino environment and how to install the Dallas Temperature module.

YOU WILL HAVE TO PUT IN YOUR WIFI NETWORK'S SSID AND PASSWORD IN THE CODE. You may also opt to change the IP address up top too.  If you just comment out the "WiFi.config()" line, the module will automatically get an IP address from your network, but the downside is that you won't know what it is, though if you go to the router's configuration page you might see a connected device called ESP_(something)

To program, throw the switch so that GPIO is pulled to ground. Plug the serial programmer into the socket, then into the USB on your computer. Apply power to the module.  Now you should be able to hit "compile and upload"

Once it's done uploading, remove power and unplug the serial interface. Move the switch back to the position where GPIO is held high and reapply power.  When the system connects to your wifi (takes 5 to 10 seconds usually) the blue LED will come on.

You can now hit the IP address ( unless you've changed it) and see this:
Temperature=22.94 celcius

No comments: