Video Tutorial: BME820 Environmental Sensor and MQTT under Micropython
This week we’re starting to make our Micropython powered Wemos D1 truly useful with a sensor and data collection. We’ll wire up a BME280 sensor which measures temperature, humidity and air pressure. After we know it works, we’ll use Wifi and MQTT to send the data to a website for viewing.
Links & Commands
- Bosch product page for the BME280
- BME280 available on Aliexpress
- “Wide range of Hygrometers:
DHT22, AM2302, AM2320, AM2321, SHT71, HTU21D, Si7021, BME280”
git clone https://github.com/catdog2/mpy_bme280_esp8266.git
git clone https://github.com/obviateio/micropython.git
- Delete the default feed
- Create the following feeds: ‘temp’, ‘pres’, ‘humid’
- The feed names must exactly match that which is in the code.
- Wikipedia on MQTT
- Wiring is VIN (on BME280) to 3.3v (on Wemos D1), GND to GND, SCL to D1 & SDA to D2
ampy run i2cscanner.py
ampy put bme280.py bme280.py
ampy put bme280-print.py main.py
screen /dev/cu.wchusbserial1450 115200
ampy put wificlient-boot.py boot.py
ampy put bme280-mqtt.py main.py
The above seems like a fairly long list of commands and links, but a lot of it is just background information – not to mention the usual “build up” of a tutorial. Realistically you can wire a BME280 to the controller, load the code and be fully “up and running” in just a few minutes. This code could also be used on a “bring your own MQTT server”, but I wanted to keep it simple for the purposes of the tutorial (hence Adafruit). This also shows that with the proper application of libraries, we could send data from just about any sensor to the internet with ease (and just a few lines of code).
If you enjoyed it, please like / subscribe / comment. Let me know what you’d like to see next! I’ve gotten some great content requests already so keep the suggestions coming!