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.

Comments

author
bluestreak101 made it!(author)2016-09-08

Hi, This is a great little project. I have made something similar using only a DHT22 and an ESP-01 which works fairly well also going to thingspeak, but I was on the lookout for a pressure sensor to add to the mix as well. I have got myself a BMP280 but have not yet got to playing with it.

When I found your solution it intrigued me. The only issue I had was that the modules needed to be modified to use the SDA/SCL and I was hoping to make something that I could make fairly quickly and be able to switch the ESP modules really easily.

Then I did some research and found this article. Now I'm using the Arduino programming for my sensor and thought it may come in handy for you also.

I've got some more ESP's on the way now so will have more of a play and I'm hoping to put some instructable's up about them at some point too.

Thanks for inspiring me!

author
cosminp12 made it!(author)2016-09-19

Hello,

Thanks for your feedback!

Rerouting the PCB might be tricky, but nevertheless you can always use another module like the ESP-201 or ESP-07 mounted on a breakout. The software is the same. I just used this one because I had it since before the SDK was released.

Thanks for the info regarding the Arduino core, but I already knew about it:) I tried it some time ago, it is great for fast prototyping and has all the Arduino libraries, but once the project grows,
it becomes difficult to develop. With the Unofficial SDK, the compiling
and flashing takes way less time and you have access to some more low
level features. Bonus: better IDE:).

Have fun and happy coding!