0

members

Easy Basics: Project 086m ESP8266 ESP-12E module, BME 280 - MicroPython web server

of Acoptex.com in ESP8266 ESP-12

Basics: Project 086m

Project name: ESP8266 ESP-12E module, BME 280 - MicroPython web server

Tags: Arduino, Arduino IDE, ESP8266 ESP-12E module, ESP, ESP8266, WI FI module, ESP-12E, LoLin NODEMCU V3, NODEMCU, BME280, temperature, humidity, pressure, BME280  sensor, micropython, web server

Attachments: main.pyBME280.py, boot.py

In this project, you needed these parts (Dear visitors. You can support our project buy clicking on the links of parts and buying them or donate us to keep this website alive. Thank you):

1.ESP8266 ESP-12E module with micro USB cable 1 pc

2. Jumper cables F-M

3. Breadboard 1 pc

4. BME280 sensor module 1 pc

5. uPyCraft IDE (you can download and read more about it here)

General

We will learn how to make the MicroPython web server by using the BME280 sensor module with the ESP8266 ESP-12E module to get pressure, temperature and humidity readings. You will be able to access the web server on local network.

In order to program the ESP8266 ESP-12E module with MicroPython you need to:

  1. Install uPyCraft IDE or Thonny IDE in your PC;
  2. Upload MicroPython firmware to your ESP8266 ESP-12E module
  3. Have three files: main.py, boot.py and BME280.py

 

BME280.py contains all the methods to use the BME280 sensor.

boot.py runs when the device starts and sets up several configuration options like your network credentials, importing libraries, setting the pins, etc.

main.py is the main script where we will handle the web server. It executes after the boot.py.

Understanding the ESP8266 ESP-12E WI FI module (LoLin NODEMCU V3)

You can read more about it here.

Understanding the BME280 module

The BME280 is the next-generation of sensors from Bosch, and is the upgrade to the BMP085/BMP180/BMP183 - with a low altitude noise of 0.25m and the same fast conversion time. 

The BME280 sensor module reads temperature, humidity, and pressure. You can also estimate altitude as the pressure changes with altitude. 

The sensor can communicate using either SPI (supports 3-, 4-wire SPI) or I2C communication protocols (there are modules of this sensor that just communicate with I2C, these just come with four pins).

The sensor comes with an on-board LM6206 3.3V regulator and I2C Voltage Level Translator, so you can use it with a 3.3V or 5V logic microcontroller like Arduino without worry.

The BME280 consumes less than 1mA during measurements and only 5μA during idle. This low power consumption allow the implementation in battery driven devices such as handsets, GPS modules or watches.

Specifications:

  • Supply Voltage: 1.8 - 5V DC
  • Interface: I2C (up to 3.4MHz), SPI (up to 10 MHz)
  • Operational Range: Temperature: -40 to +85° C
  • Humidity: 0-100%
  • Pressure: 300-1100 hPa
  • Resolution:Temperature: 0.01°C Humidity: 0.008% Pressure: 0.18Pa
  • Accuracy:Temperature: +-1°C Humidity: +-3% Pressure: +-1Pa
  • I2C address SDO LOW : 0x76 SDO HIGH: 0x77 

The module features a simple two-wire I2C interface which can be easily interfaced with any microcontroller of your choice. The default I2C address of the BME280 module is 0x76 and can be changed to 0x77 easily with the solder jumper besides chip.

How to change I2C Address?

  1. Locate the solder jumper besides chip. By default the middle copper pad is connected to the left pad.
  2. Scratch the connection between the middle and the left copper pad to disconnect those using a sharp knife.
  3. Add a solder blob between the middle and the right copper pad to join them. It allows you to set the I2C address 0x77.

Signals and connections of the BME280 sensor module

To use SPI communication protocol, you must have the following pins:

VIN -  power supply 3.3V DC

GND - ground

CLK (or SCK or SCL) (Serial Clock) - The clock pulses which synchronize data transmission generated by the master

MISO (or DO or SO or SDO) (Master In Slave Out) - The Slave line for sending data to the master

MOSI (or DI or SI or CMD or SDI or SDA) (Master Out Slave In) - The Master line for sending data to the peripherals

CS (or SS or D3 or CSB) (Chip Select or Slave Select) - the pin on each device that the master can use to enable and disable specific devices

If your BME280 sensor module has 4 pins it can use I2C communication protocol only: 

VIN -  power supply  3.3V DC

GND - ground

SDA - Serial Data Line

SCL  - Serial Clock Line 

Signals and connections of the ESP8266 ESP-12E WI FI module (LoLin NODEMCU V3)

TX - transmit pin. GPIO pin

RX  - receive pin.  GPIO pin

3V3 (or 3V or 3.3V) - power supply pin (3-3.6V). 

GND ( or G) - ground pin.

RST - reset pin. Keep it on high (3.3V) for normal operation. Put it on 0V to reset the chip.

EN - Chip enable. Keep it on high (3.3V) for normal operation.

Vin - External power supply 5VDC.

D0-D8 - GPIO (General Purpose Input Output) pins 

D5-D8 - SPI interface

D1-D2– I²C/TWI Interface

SC (or CMD) - (Chip Select) - the pin that the master can use to enable and disable specific devices. GPIO pin

SO (or SDO) - Master In Slave Out (MISO) - SPI communication. The Slave line for sending data to the master. GPIO pin

SK (or CLK) - SCK (Serial Clock) - SPI communication.The clock pulses which synchronize data transmission generated by the master. GPIO pin

S1 (or SD1) - Master Out/Slave In (MOSI). SPI communication. The Master line for sending data to the peripherals. GPIO pin

S2 (or SD2) - GPIO pin

S3 (or SD3) - GPIO pin

VU (or VUSB) - external power 5VDC.

A0 - ADC output.

RSV - reserved

Wiring

BME280 sensor mudue Nodemcu 1.0

GND                 G (GND)

Vin                   3V3

SDA                 GPIO 4 (D2)

SCL                  GPIO 5 (D1)

Step by Step instruction

  1. Do wiring.
  2. Install uPyCraft IDE on your PC;
  3. Plug the ESP8266 ESP-12E module to your PC and wait for the drivers to install (or install manually any that might be required).
  4. ESP8266 ESP-12E module - Uploading MicroPython firmware.
  5. Open uPyCraft IDE. Double-click uPyCraft_V1.1.exe file. A new window opens with the uPyCraft IDE software.
  6. Go to Tools -> Board. If you are using ESP8266 ESP-12E module select esp8266.
  7. Go to Tools -> Serial and select your ESP8266 ESP-12E module COM port (in our case it’s COM6). If you don’t see the COM Port, you need to install the ESP32 CP210x USB to UART Bridge VCP Drivers , check your USB cable too (it should be data cable).
  8. You have established a serial communication with your board. The >>> should appear in the Shell window after a successful connection with your board.
  9. Press New file button to create a new file.
  10. Press Save file button to save the file in your PC. Input file name BME280.py and press ok button.
  11. Copy the following BME280.py to the Editor on the BME280.py file.

  12. Press Save file button to save the file in your PC. 
  13. Press Download and run button to upload the file to your ESP8266 ESP-12E module. The device directory should now load the BME280.py file. You should see a message download ok in the Shell window.
  14. Press New file button to create a new file.
  15. Press Save file button to save the file in your PC. Input file name main.py and press ok button.
  16. You should see a new tab with the main.py file.
  17. Copy the following main.py to the Editor on the main.py file.

  18. Press Save file button to save the file in your PC. 
  19. Press Download and run button to upload the file to your ESP8266 ESP-12E module. You should see a message download ok in the Shell window.
  20. Press Save button to save the changes.
  21. Press Stop button to stop any script from running in your board.
  22. Select boot.py file stored on your board and copy the following boot.py to the Editor on the boot.py file. You need to modify the SSID and password with your local WiFi network data.
  23. Press Save button to save the changes.
  24. Press Stop button to stop any script from running in your board.
  25. Press Download and run button to upload the file to your ESP8266 ESP-12E module. You should see a message download ok in the Shell window.
  26. Your ESP8266 ESP-12E module has three files - boot.py, BME280.py and main.py stored now. 
  27. Press the ESP8266 ESP-12E module on-board RST button to reboot it.
  28. You can see that connection successful and IP address in the shell (in our case that is 192.168.0.116).
  29. Open any internet browser and type your IP address (we have 192.168.0.116). You will see the temperature, pressure, humidity readings from your BME280 sensor module.

Code

boot.py

 

We import the necessary libraries, define the I2C pins to connect to the sensor and connect to your network. In the code, we are using the ESP8266 ESP-12E module I2C pins. Insert your local WiFi network data in the following variables - ssid and password.

main.py

We made the web server and handle the requests in this file. This code creates a socket server that sends an HTML page with the latest sensor readings when it receives a request on the ESP8266 ESP-12E module IP address. We have a function called web_page() that returns the HTML to build up the web page with the latest sensor readings. This HMTL text builds a table to display the readings. We create a socket server that sends the HTML when it gets a request. The HTML text is then saved on the response variable and sent to the client.

You need to refresh the web page to see the latest readings. If add the next meta tag inside the HTML tags, your web page will auto refresh every 5 seconds:  //<meta http-equiv="refresh" content="5">//

Summary

We have learnt how to make the MicroPython web server by using the BME280 sensor module with the ESP8266 ESP-12E module to get pressure, temperature and humidity readings.

Libraries

  • All libraries attached on the begining of this project description.
  • BME280 MicroPython library. This library is not a part of the standard MicroPython library by default. You will need to upload the BME280.py to your ESP8266 ESP-12E module.

Sketch

  • See on the begining of this project


Other projects of Acoptex.com

« Go back to category
Is this project fake? Report it!   
Recommend to a friend
Published at 29-07-2019
Viewed: 299 times