members
Basics: Project 072o ESP32 Development board with BMP280 sensor module Web Server
of Acoptex.com in ESP8266 ESP-32
Basics: Project 072o
Project name: ESP32 Development board with BMP280 sensor module Web Server
Tags: ESP32 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, Installing the ESP32 Board in Arduino IDE, Uploading sketch, BMP280, GY-BMP280, Digital Sensor, SPI I2C Temperature and Barometric Pressure Sensor Module, Web Server, GY-BMP280-3.3
Attachments: I2Cscannersketch, library1, library2
I2C communication: bmp280testsketch1, e32webbmp280sketch2,
SPI communication: e32webbmp280sketch3, e32webbmp280sketch4
In this project, you need these parts :
1. ESP32 development board with WiFi and Bluetooth and USB A / micro USB B cable 1 pc
2.Arduino IDE ( you can download it from here )
3.Jumper cables F-F
4. BMP280 sensor module 1 pc
We will learn how to create a web server with the ESP32 development board to display readings from the BMP280 sensor module. The BMP280 sensor measures temperature and pressure. You can easily build a mini and compact weather station and monitor the measurements using your ESP32 web server.
Please note that temperature & humidity & pressure readings - BME280, temperature & pressure readings - BMP280.
There are a lot of different development boards made. You can find more information about them here.
Understanding the BMP280 module
BMP280 is an absolute barometric pressure sensor especially designed for mobile applications. The sensor module is housed in an extremely compact package. Its small dimensions and its low power consumption allow for the implementation in battery powered devices such as mobile phones, GPS modules or watches.
As that is the next generation upgrade to the BMP085/BMP180/BMP183, BMP280 is based on Bosch’s proven Piezo-resistive pressure sensor technology featuring high accuracy and linearity as well as long term stability and high EMC robustness. Numerous device operation options offer highest flexibility to optimize the device regarding power consumption, resolution and filter performance. A tested set of default settings for example use case is provided to the developer in order to make design-in as easy as possible.
This precision sensor from Bosch is the best low-cost, precision sensing solution for measuring barometric pressure with ±1 hPa absolute accuraccy, and temperature with ±1.0°C accuracy. Because pressure changes with altitude, and the pressure measurements are so good, you can also use it as an altimeter with ±1 meter accuracy.
The BMP280 is the next-generation of sensors from Bosch with a low altitude noise of 0.25m and the same fast conversion time. It has the same specifications, but can use either I2C or SPI. For simple easy wiring, go with I2C. If you want to connect a bunch of sensors without worrying about I2C address collisions, go with SPI.
Applications:
- Enhancement of GPS navigation (e.g. time-tofirst-fix improvement, dead-reckoning, slope detection)
- Indoor navigation (floor detection, elevator detection)
- Outdoor navigation, leisure and sports applications
- Weather forecast
- Health care applications (e.g. spirometry)
- Vertical velocity indication (e.g. rise/sink speed)
There are several versions of this sensor module, but we will use the one shown below.
Understanding the ESP32 Development board with WiFi and Bluetooth
We will discuss here an Espressif Systems products. Our development board is using ESP-WROOM-32 module from Espressif Systems.
Espressif offers a wide range of fully-certified Wi-Fi & BT modules powered by their own advanced SoCs.
1. Dual-core Modules with Wi-Fi & Dual-mode Bluetooth
Features
- Two independently-controlled CPU cores with adjustable clock frequency, ranging from 80 MHz to 240 MHz
- +19.5 dBm output at the antenna ensures a good physical range
- Classic Bluetooth for legacy connections, also supporting L2CAP, SDP, GAP, SMP, AVDTP, AVCTP, A2DP (SNK) and AVRCP (CT)
- Support for Bluetooth Low Energy (BLE) profiles including L2CAP, GAP, GATT, SMP, and GATT-based profiles like BluFi, SPP-like, etc
- Bluetooth Low Energy (BLE) connects to smart phones, broadcasting low-energy beacons for easy detection
- Sleep current is less than 5 μA, making it suitable for battery-powered and wearable-electronics applications
- Integrates 4 MB flash
- Peripherals include capacitive touch sensors, Hall sensor, low-noise sense amplifiers, SD card interface, Ethernet, high-speed SPI, UART, I2S and I2C
- Fully certified with integrated antenna and software stacks
2. Single-core Modules with Wi-Fi & Dual-mode Bluetooth
Features
- High-performance 160 MHz single-core CPU
- +19.5 dBm output at the antenna ensures a good physical range
- Classic Bluetooth for legacy connections, also supporting L2CAP, SDP, GAP, SMP, AVDTP, AVCTP, A2DP (SNK) and AVRCP (CT)
- Support for Bluetooth Low Energy (BLE) profiles including L2CAP, GAP, GATT, SMP, and GATT-based profiles like BluFi, SPP-like, etc
- Bluetooth Low Energy (BLE) connects to smart phones, broadcasting low-energy beacons for easy detection
- Sleep current is less than 5 μA, making it suitable for battery-powered and wearable-electronics applications
- Peripherals include capacitive touch sensors, Hall sensor, low-noise sense amplifiers, SD card interface, Ethernet, high-speed SPI, UART, I2S and I2C
- Fully certified with integrated antenna and software stacks
3. Single-core Modules with 802.11b/g/n 2.4 GHz Wi-Fi
Features
- High-performance 160 MHz single-core CPU
- +19.5 dBm output at the antenna ensures a good physical range
- Sleep current is less than 20 μA, making it suitable for battery-powered and wearable-electronics applications
- Peripherals include UART, GPIO, I2C, I2S, SDIO, PWM, ADC and SPI
- Fully certified with integrated antenna and software stacks
There are different development Boards made by Espressif Systems and other manufacturers. We will publish some information about Espressif Systems boards but you can also find out more information about other development boards here.
1. 2.4 GHz Wi-Fi & BT/BLE Development Boards
Features
- PC connectivity: USB
- Power supply options: USB (by default), or 5V/GND header pins, or 3V3/GND header pins
- SDK: ESP-IDF source code and example applications
2. 2.4 GHz Wi-Fi Development Boards
Features
- PC connectivity: USB
- SDK: ESP8266 SDK source code and example applications
3. 2.4 GHz Wi-Fi + BT/BLE + Sensor Development Boards
Features
- PC connectivity: USB
- SDK: ESP-IOT-SOLUTION source code and example applications
You can find more information (datasheets, schematics, pins descriptions, functional desgn descriptions) about each board by pressing Getting started link close to each board here.
ESP32 chip
ESP32 is a series of low cost, low power system on a chip microcontrollers with integrated Wi-Fi and dual-mode Bluetooth. The ESP32 series employs a Tensilica Xtensa LX6 microprocessor in both dual-core and single-core variations and includes in-built antenna switches, RF balun, power amplifier, low-noise receive amplifier, filters, and power management modules. ESP32 is created and developed by Espressif Systems, a Shanghai-based Chinese company, and is manufactured by TSMC using their 40 nm process. It is a successor to the ESP8266 microcontroller.
ESP32 can perform as a complete standalone system or as a slave device to a host MCU, reducing communication stack overhead on the main application processor. ESP32 can interface with other systems to provide Wi-Fi and Bluetooth functionality through its SPI / SDIO or I2C / UART interfaces.
ESP32 is highly-integrated with in-built antenna switches, RF balun, power amplifier, low-noise receive amplifier, filters, and power management modules. ESP32 adds priceless functionality and versatility to your applications with minimal Printed Circuit Board (PCB) requirements.
ESP32 is capable of functioning reliably in industrial environments, with an operating temperature ranging from –40°C to +125°C. Powered by advanced calibration circuitries, ESP32 can dynamically remove external circuit imperfections and adapt to changes in external conditions.
Engineered for mobile devices, wearable electronics and IoT applications, ESP32 achieves ultra-low power consumption with a combination of several types of proprietary software. ESP32 also includes state-of-the-art features, such as fine-grained clock gating, various power modes and dynamic power scaling.
Functional Block Diagram:

Features of the ESP32 include the following:
Processors:
- CPU: Xtensa dual-core (or single-core) 32-bit LX6 microprocessor, operating at 160 or 240 MHz and performing at up to 600 DMIPS
- Ultra low power (ULP) co-processor
- Memory: 520 KiB SRAM
Wireless connectivity:
- Wi-Fi: 802.11 b/g/n
- Bluetooth: v4.2 BR/EDR and BLE
Peripheral interfaces:
- 12-bit SAR ADC up to 18 channels
- 2 × 8-bit DACs
- 10 × touch sensors (capacitive sensing GPIOs)
- Temperature sensor
- 4 × SPI
- 2 × I²S interfaces
- 2 × I²C interfaces
- 3 × UART
- SD/SDIO/CE-ATA/MMC/eMMC host controller
- SDIO/SPI slave controller
- Ethernet MAC interface with dedicated DMA and IEEE 1588 Precision Time Protocol support
- CAN bus 2.0
- Infrared remote controller (TX/RX, up to 8 channels)
- Motor PWM
- LED PWM (up to 16 channels)
- Hall effect sensor
- Ultra low power analog pre-amplifier
Security:
- IEEE 802.11 standard security features all supported, including WFA, WPA/WPA2 and WAPI
- Secure boot
- Flash encryption
- 1024-bit OTP, up to 768-bit for customers
- Cryptographic hardware acceleration: AES, SHA-2, RSA, elliptic curve cryptography (ECC), random number generator (RNG)
Power management:
- Internal low-dropout regulator
- Individual power domain for RTC
- 5uA deep sleep current
- Wake up from GPIO interrupt, timer, ADC measurements, capacitive touch sensor interrupt
You can find ESP32 chip datasheet here, hardware design here, technical reference manual here.
Signals and connections of the BMP280 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 DEVKITV1 with 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 Boot button 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
1. I2C communication with the BMP280 sensor module. We are using the ESP32 default I2C pins (GPIO 21 (SDA) and GPIO 22 (SCL)).
2. SPI communication with the BMP280 sensor module. We are using the ESP32 default VSPI pins:
BMP280 sensor module ESP32 development board
VCC 3V3
GND G
SCL GPIO 18
SDA GPIO 23
CSB GPIO 5
SDO GPIO 19
3. SPI communication with the BMP280 sensor module. We are using the ESP32 default HSPI pins:
BMP280 sensor module ESP32 development board
VCC 3V3
GND G
SCL GPIO 14
SDA GPIO 13
CSB GPIO 15
SDO GPIO 12
Step by Step instruction
The ESP32 is currently being integrated with the Arduino IDE like it was done for the ESP8266. There’s an add-on for the Arduino IDE that allows you to program the ESP32 using the Arduino IDE and its programming language.
- Download and install the latest Arduino IDE Windows Installer from arduino.cc
- Download and install Git and Git GUI from git-scm.com
- Search for Git GUI, right-click the icon and select “Run as administrator“
- Select the Clone Existing Repository option.
- Select source and destination. Source Location: https://github.com/espressif/arduino-esp32.git
- Target Directory:C:/Users/[YOUR_USER_NAME]/Documents/Arduino/hardware/espressif/esp32
- Do not create the espressif/esp32 folders, because they will be created automatically.
- Click Clone to start cloning the repository.Wait a few seconds while the repository is being cloned.
- Open the folder: C:/Users/[YOUR_USER_NAME]/Documents/Arduino/hardware/espressif/esp32/tools
- Right-click the get.exe file and select “Run as administrator“.
- You will see that necessary files will be downloaded and upzipped. It will take some time.
- When get.exe finishes, you should see the following files in the directory.
- Do wiring.
- Plug the ESP32 development board to your PC and wait for the drivers to install (or install manually any that might be required).
- Open Arduino IDE.
- Open Boards manager. Go to Tools -> Board -> Boards Manager… (in our case it’s the DOIT ESP32 DEVKIT V1)
- Select COM port that the board is attached to (if you don’t see the COM Port in your Arduino IDE, you need to install the ESP32 CP210x USB to UART Bridge VCP Drivers)
- Find your BMP280 I2C address. Each device has an I2C address that it uses to accept commands or send messages. Compile and upload the I2Cscannersketch to your ESP32 development board. If everything went as expected, you should see a “Done uploading” message. (You need to hold the ESP32 on-board Boot button while uploading).
- Press the ESP32 on-board EN button to reboot it.
- Open the Serial Monitor at a baud rate of 115200. Arduino will scan the address range looking for a reply. Even though the documentation said it was 0x77, this scanner can detect different (in our case 0x76). Adafruit_BMP280 library has default I2C address 0x77 and if you are getting 0x76 you need to modify line of code in bmp280testsketch1: status = bmp.begin(); to status = bmp.begin(0x76);
- Compile and upload the bmp280testsketch1 to your ESP32 development board. If everything went as expected, you should see a “Done uploading” message. (You need to hold the ESP32 on-board Boot button while uploading).
- Press the ESP32 on-board EN button to reboot it.
- Open the Serial Monitor at a baud rate of 115200. You should see the readings displayed on the Serial Monitor.
- We need to create table as we will display readings on the web page with a table accomodated by the ESP32 development board. Let's write HTML text to build a table. To create a table in HTML you use the and tags. To create a row you use the and tags. The table heading is defined using the and tags, and each table cell is defined using the and tags.
-
We create the header of the table with a cell called MEASUREMENT, and another called VALUE.Then, we create six rows to display each of the readings using the and tags.Inside each row, we create two cells, using the and tags, one with the name of the measurement, and another to hold the measurement value. The three dashes “—” should then be replaced with the actual measurements from the BME sensor.You can save this text as table.html, drag the file into your browser and see what you have. The previous HTML text creates the following table.We made the header of the table with a cell called MEASUREMENT and another called VALUE, five rows to display each of the readings using the and tags. Inside each row, we create two cells, using the and tags, one with the name of the measurement, and another to hold the measurement value. The two dashes “—” should then be replaced with the actual measurements from the BMP sensor module.The previous HTML text creates the following table. You can open the file here.
- Let's build the web server now. Modify e32webbmp280sketch2 with your SSID and password data.
- Compile and upload the e32webbmp280sketch2 to your ESP32 development board. If everything went as expected, you should see a “Done uploading” message. (You need to hold the ESP32 on-board Boot button while uploading).
- Press the ESP32 on-board EN button to reboot it.
- Open the Serial Monitor at a baud rate of 115200. You should see the ESP32 IP address displayed on the Serial Monitor (we have 192.168.0.116).
- You can access your web server, if you type your ESP32 development board IP address in your browser. In our case it is http://http://192.168.0.116. You will see the latest sensor readings. To update the readings, you just need to refresh the web page.
- If you want to use SPI communication do corresponding wiring and upload e32webbmp280sketch3 (VSPI pins) or e32webbmp280sketch4 (HSPI pins)
Code
bmp280testsketch. First we include required libraries. As we are going to use I2C communication you can comment the following lines:
/*#include
#define BMP_SCK 18
#define BMP_MISO 19
#define BMP_MOSI 23
#define BMP_CS 5*/
Note: if you are using SPI communication, you need to change the pin definition to use the ESP32 GPIOs. For SPI communication on the ESP32 you can use either the HSPI or VSPI pins, as shown in the following table.
A variable called SEALEVELPRESSURE_HPA used to save the pressure at the sea level in hectopascal (is equivalent to milibar). This variable is used to estimate the altitude for a given pressure by comparing it with the sea level pressure. This example uses the default value, but for more accurate results, replace the value with the current sea level pressure at your location. This sketch uses I2C communication by default. As you can see, you just need to create an Adafruit_BMP280 object called bme: Adafruit_BMP280 bmp;
If you would like to use SPI, you need to comment this previous line and uncomment one of the following lines depending on whether you’re using hardware or software SPI:
//Adafruit_BMP280 bmp(BMP_CS); // hardware SPI
//Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK); // software SPI
In the setup() you start a serial communication
Serial.begin(115200);
And the sensor is initialized. Adafruit_BMP280 library has default I2C address 0x77 and if you are getting 0x76 you need to modify this line of code : status = bmp.begin(); to status = bmp.begin(0x76);
In the loop(), the printValues() function reads the values from the BMP280 and prints the results in the Serial Monitor.
Reading temperature, humidity, pressure, and estimate altitude is as simple as using:
bmp.readTemperature() – reads temperature in Celsius;
bmp.readPressure() – reads pressure in hPa (hectoPascal = millibar);
bmp.readAltitude(SEALEVELPRESSURE_HPA) – estimates altitude in meters based on the pressure at the sea level.
e32webbmp280sketch2. First we include the WiFi library and required libraries to read from the BMP280 sensor. Then define a variable to save the pressure at the sea level. For more accurate altitude estimation, replace the value with the current sea level pressure at your location. Next you create an Adafruit_BMP280 object called bme that by default establishes a communication with the sensor using I2C: Adafruit_BMP280 bmp; // I2C
You need to insert your ssid and password in the following lines inside the double quotes: const char* ssid = ""; const char* password = "";
Set your web server to port 80.The following line creates a variable to store the header of the HTTP request: String header;
In the setup(), we start a serial communication at a baud rate of 115200 for debugging purposes. You also check that the BMP280 sensor was successfully initialized. Next lines begin the Wi-Fi connection with WiFi.begin(ssid, password), wait for a successful connection and print the ESP32 IP address in the Serial Monitor.
In the loop() we program what happens when a new client establishes a connection with the web server. The ESP is always listening for incoming clients. When a request is received from a client, we’ll save the incoming data. The while loop that follows will be running as long as the client stays connected. The next thing you need to do is to send a response to the client with the HTML text to build the web page. The web page is sent to the client using this expression client.println(). You should enter what you want to send to the client as an argument.
To display the sensor readings on the table, we just need to send them between the corresponding and tags. The tag is useful to style a particular part of a text. In this case, we’re using the tag to include the sensor reading in a class called "sensor".
By default the table is displaying the temperature readings in both Celsius degrees and Fahrenheit. Of course you can comment unnec essary lines to display the temperature in Fahrenheit degrees only.
Finally, when the response ends, we clear the header variable, and stop the connection with the client with client.stop().
Troubleshooting
If you are getting getting readings of 0.00 or "nan". Check the wiring first. If it doesn't help use tips below:
1. You probably have wrong I2C address - find your BMP280 I2C address. Each device has an I2C address that it uses to accept commands or send messages. Compile and upload the I2Cscannersketch to your ESP32 development board. The scanner will detect your BMP280 I2C address (in our case it was 0x76). Adafruit_BMP280 library has default I2C address 0x77 and if you are getting 0x76 you need to modify line of code in bmp280testsketch1: status = bmp.begin(); to status = bmp.begin(0x76);
2. If you do not have any response from sensor module it means that it is dead (broken).
3. If your are getting "nan" more often than not the problem can be in power supply - it should be 3.3V DC. Adafruit's BMP280 board has an onboard I2C level shifter. The chinese clone has not. The clone therefore must be used with a 3.3volt Arduino.
We have learnt how to create a web server with the ESP32 development board to display readings from the BMP280 sensor module.
Libraries
- All libraries attached on the begining of this project description.
- Wire library included in your Arduino IDE.
- SPI library included in your Arduino IDE.
- WiFi library included in your Arduino IDE.
- Adafruit_BMP280 library included.Download, unzip and add to libraries in our PC, for example C:\Users\toshiba\Documents\Arduino\libraries. This link you can find in Preferences of Adruino IDE program which installed in your PC. You can read more about it here.
- Adafruit_Sensor library included.Download, unzip and add to libraries in our PC, for example C:\Users\toshiba\Documents\Arduino\libraries. This link you can find in Preferences of Adruino IDE program which installed in your PC. You can read more about it here.
Sketch
- See attachments on the begining of this project
Other projects of Acoptex.com










Viewed: 12625 times