Introduction: BME280 Weather Station With ESP8266 SDK

The purpose of this project was to share my own C implementation of a BME280 driver and provide a demo application for it, using ESP8266 with the official Espressif SDK.

The sensor is connected directly to the ESP8266 without any other MCU in between, via I2C. Data is then sent to a ThingSpeak account for whatever purposes.

Hardware:

· ESP8266 module

· BME280 breakout

· 3.3V power supply

Software:

· Unofficial Development Kit for ESP8266

Step 1: Hardware

Sensor

For this project I’ve used a BME280 breakout that I’ve bought from eBay for $5. You can use other breakout’s (eventually needing to change the I2C address in SW or HW), but I’ve chosen this one because of the price.

This is the exact link of the listing I ordered from, but other sources should work as well: http://www.ebay.com/itm/1PCS-Breakout-Temperature...

Although the image shows a module with blue solder mask, mine was purple. On the front side it has the sensor and 3 pads for changing the I2C address. On the back it has what I suppose to be a voltage regulator and a logic level shifter, but I haven’t tried the module in a 5V system yet.

The breakout outputs only the I2C pins but this is OK as the ESP8266 doesn’t have too many pins to spare and the sensor doesn’t produce such a high data stream in order to need a faster interface like SPI.

Wi-Fi module

Because I only needed an I2C connection I thought it would be interesting to take an ESP-01 module and modify it. J This is described below, but if you do not want to do the modification you might as well use a different module that has all the pins pulled out, like the ESP-07. If you decide for a stock module, don’t forget to tie the CH_PD pin to Vcc.

For the I2C I needed GPIO2 for SDA and GPIO14 for SCL. The first one was already available, but the second one required some modification to do. As I usually do not actively use the CH_PD pin, I decided to modify the PCB in order to route GPIO14 (pin 9) to what used to be the CH_PD pin of the board and hardwired pin 7 (that was previously connected to CH_PD) of the SoC to Vcc. In the picture below I’ve marked with red the place where I scratched the PCB trace and with green the new connections I made (with 0.1mm wire).

This way I get a small and robust module that has 2 GPIOs, I do not have to worry about keeping CH_PD high and there is no interference with the connections required for programming the chip.

Connections

Sensor | Module

SDA à GPIO2

SCL à GPIO14

Vcc and GND of both modules go in parallel and to a 3.3V power supply. The power supply is not described in this project but I use a 5V phone charger with an APL1117-3.3 fixed voltage regulator and 2 capacitors.

For programming I connect the TX, RX, RST and GPIO0 pins to a USB-UART converter. I usually use the one with a CP2102 IC, but be careful that its 3.3V output can’t deliver enough current for the ESP8266. The ones with PL-2303HX seem to be able to supply the ESP8266.

Step 2: Software

For developing the software I used the Unofficial
Development Kit for Espressif ESP8266. You can find all the necessary info about downloading, installing and usage at this link: http://www.esp8266.com/viewtopic.php?t=820

I prefer this when it comes to ESP8266 as I have better control on the software, I can use the API that is released and documented by Espressif and I have all this integrated in Eclipse along with many examples that make your life easier.

The code is available on GitHub at https://github.com/cosminp12/BME280-Weather-Stati... You can download it, just import it into Eclipse and it should compile successfully.

The app consists mainly of a function that is executed once every minute and performs a reading of the sensor and uses the HTTP Client to put that data on ThingSpeak. The ThingSpeak Key, router SSID and password are configurable from user_config.h.

In order to make the library more portable on different platforms, it calls only 2 functions that perform I2C reading and writing of one or multiple bytes (I2C_WriteData and I2C_ReadData) and returns a zero value if everything was OK.

Step 3: Results

My device sends data to this channel: https://thingspeak.com/channels/96844

After leaving this running for a week, I’ve downloaded the whole feed in CSV format from ThingSpeak and plotted it into Excel for a better view.