0

members

Easy Basics: Project 086n ESP32 Development board, BME 280 - MicroPython Web Server

of Acoptex.com in ESP8266 ESP-32

Basics: Project 086n

Project name: ESP32 Development board, BME 280 - MicroPython Web Server

Tags: Arduino, Arduino IDE, ESP32 Development board, WI FI module, SP32 Dev Module, ESP32 development board, ESP32 Development board with WiFi and Bluetooth, ESP32-DevKitC V4 development board, ESP-WROOM-32 module with ESP32‑D0WDQ6 chip, Espressif Systems, ESP32-based development board, ESP32 modules, ESP32-WROOM-32, ESP32-WROOM-32U, ESP32-WROOM-32D, ESP32-SOLO-1, USB-UART bridge, IOT, ESP-WROOM-32 Dev Module, ESP32 DEVKITV1, BME280, temperature, humidity,pressure, BME280  sensor, micropython, web server

Attachments: main.pyBME280.pyboot.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. ESP32 development board with WiFi and Bluetooth and USB A / micro USB B 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 ESP32 development board to get pressure, temperature and humidity readings. You will be able to access the web server on local network.

In order to program the ESP32 Development board with MicroPython you need to:

  1. Install uPyCraft IDE or Thonny IDE in your PC;
  2. Upload MicroPython firmware to your ESP32 Development board;
  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.

There are a lot of different development boards made. You can find more information about them here

Understanding the ESP32 Development board with WiFi and Bluetooth

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 ESP32 Development board with WiFi and Bluetooth

You can find more information (datasheets, schematics, pins descriptions, functional desgn descriptions) about each board (made by Espresiff Systems) by pressing Getting started link close to each board here.

Let's check our development board - ESP32 DEVKITV1with ESP-WROOM-32 module from Espressif Systems:

Pinout diagram for the ESP Wroom 32 breakout:

ESP32-WROOM-32 - ESP32-WROOM-32 module soldered to the development board. Optionally ESP32-WROOM-32D, ESP32-WROOM-32U or ESP32-SOLO-1 module may be soldered instead of the ESP32-WROOM-32.

USB-UART Bridge - A single chip USB-UART bridge provides up to 3 Mbps transfers rates.

BOOT button - Download button: holding down the Bootbutton and pressing the EN button initiates the firmware download mode. Then user can download firmware through the serial port.

EN button - Reset button: pressing this button resets the system.

Micro USB Port - USB interface. It functions as the power supply for the board and the communication interface between PC and the ESP module.

TX0, TX2 - transmit pin. GPIO pin

RX0, RX2  - receive pin.  GPIO pin

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

GND - ground pin.

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

Vin - External power supply 5VDC.

Wiring

BME280 sensor mudue ESP32 development board

GND                 G (GND)

Vin                   3V3

SDA                 GPIO 21 (D21)

SCL                  GPIO 22 (D22)

Step by Step instruction

  1. Do wiring.
  2. Install uPyCraft IDE on your PC;
  3. Plug the ESP32 development board to your PC and wait for the drivers to install (or install manually any that might be required).
  4. ESP32 development board - 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 ESP32 development board select esp32.
  7. Go to Tools -> Serial and select your ESP32 development board COM port (in our case it’s COM7). 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 ESP32 development board. 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 ESP32 development board. 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 ESP32 development board. You should see a message download ok in the Shell window.
  26. Your ESP32 development board has three files - boot.py, BME280.py and main.py stored now. 
  27. Press the ESP32 development board on-board EN 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.117).
  29. Open any internet browser and type your IP address (we have 192.168.0.117). 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 ESP32 development board 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 ESP32 development board 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 use the BME280 sensor module with the ESP32 development board to get pressure, temperature and humidity readings using MicroPython firmware.

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 ESP32 development board.

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 30-07-2019
Viewed: 380 times