Warning: Declaration of Db::query($query) should be compatible with mysqli::query($query, $resultmode = NULL) in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 29

Deprecated: Function get_magic_quotes_runtime() is deprecated in /var/www/u1300519/data/www/acoptex.com/_lib/CacheLite/Lite.php on line 757

Deprecated: Function get_magic_quotes_runtime() is deprecated in /var/www/u1300519/data/www/acoptex.com/_lib/CacheLite/Lite.php on line 757

Warning: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP) in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 64

Warning: mysqli_fetch_array() expects parameter 2 to be int, string given in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 64

Deprecated: Function get_magic_quotes_runtime() is deprecated in /var/www/u1300519/data/www/acoptex.com/_lib/CacheLite/Lite.php on line 757

Deprecated: Function get_magic_quotes_runtime() is deprecated in /var/www/u1300519/data/www/acoptex.com/_lib/CacheLite/Lite.php on line 757

Warning: Cannot modify header information - headers already sent by (output started at /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php:0) in /var/www/u1300519/data/www/acoptex.com/_config/config.php on line 168

Warning: session_start(): Cannot start session when headers already sent in /var/www/u1300519/data/www/acoptex.com/_config/config.php on line 169

Warning: Use of undefined constant MYSQL_NUM - assumed 'MYSQL_NUM' (this will throw an Error in a future version of PHP) in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 92

Warning: mysqli_fetch_array() expects parameter 2 to be int, string given in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 92

Warning: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP) in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 64

Warning: mysqli_fetch_array() expects parameter 2 to be int, string given in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 64
jobs.html_title
4

members

Easy Basics: Project 086l ESP32 Development board, BME 280 - MicroPython

of Acoptex.com in ESP8266 ESP-32

Basics: Project 086l

Project name: ESP32 Development board, BME 280 - MicroPython

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

Attachments: main.pyBME280.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 use the BME280 sensor module with the ESP32 Development board to get pressure, temperature and humidity readings using MicroPython firmware.

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

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 button to save the changes.
  19. Press Stop button to stop any script from running in your board.
  20. Press Download and run button to upload the file to your ESP32 development board. The device directory should now load the main.py file. Your ESP32 development board has three files - boot.py, BME280.py and main.py stored now. You should see a message download ok in the Shell window.
  21. Press the ESP32 development board on-board EN button to reboot it.
  22. The temperature, humidity and pressure will be printed into the shell every 5 seconds.

Code

First, we need to import the necessary libraries, including the BME280 module library. Set the I2C pins. In this case, we will be using the default I2C pins. In the while loop, create a BME280 object called bme with the I2C pins defined earlier. Reading temperature, humidity and pressure is as simple as using the temperature, humidity and pressure methods on the bme object. Finally, we print the readings on the shell. At the end, we add a delay for 5 seconds.

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
Medium Basics: Project 083w Sipeed Maixduino board - Using PlatformIO IDE of Acoptex.com in Sipeed Maixduino 08-08-2019
Medium Basics: Project 083e Sipeed Maixduino board - Uploading MaixPy of Acoptex.com in Sipeed Maixduino 04-08-2019
Medium Basics: Project 083f Sipeed Maixduino board - Using MycroPython of Acoptex.com in Sipeed Maixduino 04-08-2019

jobs.published_at
jobs.viewed