ESP32 Devlog 3 — Barometric Sensor
Senses going hot, high, and tense
A big thank you for an article about BMP180 barometric sensor on Random Nerd Tutorials. It comprehensively describes the steps on installing the BMP180 module on Arduino IDE, the wiring schema of BMP180, and so on.
My lecturer told me to buy a BMP180 module. It is a digital pressure sensor and it measures the absolute air pressure around it, which could be further calculated for determine temperature and altitude.
And yea, here it is, the BMP180. Sadly enough, i might get a different devboard setup (or maybe another vendor are producing the similiar chip). I’ve only got 4 pins for the BMP180 whereas the legit one has 5 pins. But, it works fine and could use the official library from Adafruit.
As usual, i won’t describe the details of the product. But i found the corresponding data sheet from the Adafruit web.
A. BMP180 Wiring Schema
As stated from the reference article, the BMP180 uses I2C communication protocol. From the ESP32 Pinout Reference, We are using GPIO21 and GPIO22 (P21 and P22 in my devboard) for the I2C SCL and SDA, then use the GND and 3V3 port.
B. Arduino IDE Library for BMP180 — Adafruit BMP085 Library
The BMP085 library has several public methods, but limited to read temperature, read pressure, and read altitude. This library is compatible with the BMP085 and the BMP180 sensors. Here is the steps to install the library:
- Open your Arduino IDE and press Ctrl + Shift + I to open the Manage Libraries Window.
- Then search for “BMP085” on the Search box and install the BMP085 library from Adafruit.
- After installing, restart the IDE
C. Code
The library provides an example showing how to get temperature, pressure, and altitude. Go to File > Examples > Adafruit BMP085 Library > BMP085test. Right after this section, it becomes straightforward.
#include <Wire.h>
#include <Adafruit_BMP085.h>Adafruit_BMP085 bmp;
void setup() {
Serial.begin(9600);
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085 sensor!");
while (1) {}
}
}
void loop() {
Serial.print("Temperature = ");
Serial.print(bmp.readTemperature());
Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(bmp.readPressure());
Serial.println(" Pa");
Serial.print("Altitude = ");
Serial.print(bmp.readAltitude());
Serial.println(" meters"); Serial.print("Pressure at sealevel (calculated) = ");
Serial.print(bmp.readSealevelPressure());
Serial.println(" Pa"); Serial.print("Real altitude = ");
Serial.print(bmp.readAltitude(101500));
Serial.println(" meters");
Serial.println();
delay(500);
}
The Adafruit_BMP085.h library documentation and implementation can be found here.
The code above uses Adafruit_BMP085 object called bmp. It has a begin method on the setup section of .ino file that outputs a boolean which return false if the wiring has not been properly set.
Then, the library also includes several methods for sensing the environment temperature, pressure, and altitude by simply invoking these methods:
- readTemperature() — Reads temperature in celcius.
- readPressure() — Reads atmospheric air pressure in pascals.
- readAltitude() — Estimates your current altitude based by comparing the with the pressure at the sea level. By default, it assumes that the sea level air pressure is 10132 Pascal. You can pass an integer for this method to customize the sea level air pressure for more accurate readings.
D. Demonstration
After uploading the code to the ESP32, open the serial monitor while the ESP32 Devboard still connected to your USB Port. Select the 9600 baud rate and expect to see the output.
E. Tweaking Notes
Well, i really hate soldering to be honest. I have a serious problem concerning precision on the real world. I remember the past me that always messes up almost every single step of origami arts. Even now i cannot properly cut a paper in half using a scissor. And BMP180 is not kind enough for me because they come in parts: a PCB and the pins. For the soldering part, i entrust the module to my electrical engineering colleague.
This is the 4th week of the embedded design and the class is going to tweak the sensors. I haven’t make an article about the promised web server lamp switch. I might slip the article to the decimal devlog series (Devlog 2.5 incoming).
The sensor lecture is really neat. I’ve learned about the serial connection, such as I2C method. The next step for this series depends on my class. I think, next week, we are going to tweak the 16 x 2 digital display.