BMP180
Wiring a BMP180 sensor to an ESP32 microcontroller
Like with every sensor, use the PINOUT diagram of ESP32 to make sure of the microcontroller’s pins’ names.
Connect the sensor’s GND pin with the GND pin of the microcontroller, 3.3V pin with the 3.3V pin, SDA pin of the sensor with the SDA pin of the microcontroller
(on the PINOUT diagram marked as the 21), and finally the sensor’s SCL pin with the microcontroller’s SCL pin (marked as the 22).
Testing BMP180 sensor
Download the BMP180 library for the sensor. Before uploading the library to the microcontroller, take a look at line 55 of the library.
self._bmp_addr = 119 # fix
119 is the sensor’s address on the microcontroller. This address is very important, as it allows the microcontroller to communicate specifically with that sensor, which is key when you need to read data from the sensor or send him commands on how to behave.
Your sensor’s address on your microcontroller can differ from this one, so do the following to check the address:
- Using MobaXTerm, connect to the microcontroller.
- In the command prompt that appears after the connection, run the following commands, one by one:
After the last command is run, in the next line you should see “[”the sensor’s address”]”.
The address of my sensor is 119, just like in the library. If your sensor's address is different, replace 119 with this address and save the change. Now upload the library to the microcontroller, just like the other libraries, using ampy.
To test if sensor is working, connect to the microcontroller again and run the following commands in the terminal:
from bmp085 import BMP180
from machine import SoftI2C, Pin
i2c = SoftI2C(scl=Pin(22), sda=Pin(21))
bmp = BMP180(i2c)
bmp.oversample = 2
bmp.sealevel = 101325
bmp.blocking_read()
bmp.temperature #in the next line, you should see the measured temperature
bmp.pressure #in the next line, you should see the measured pressure
bmp.altitude #in the next line, you should see the measured altitude
According to the documentation, the temperature is expressed in degrees C, the pressure in hPa, and the altitude in meters.