Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
The BMP180 is a high-precision, low-power barometric pressure sensor that can measure atmospheric pressure and temperature. It is widely used in weather stations, altimeters, and other applications where accurate pressure measurements are essential. In the context of Raspberry Pi, the BMP180 can be a valuable addition for projects that require environmental data collection. This article will guide you on how to interface the BMP180 sensor with a Raspberry Pi, including wiring, installing necessary libraries, and running a Python script to read data from the sensor.
Examples:
Components Needed:
Wiring:
Update and Upgrade the System:
sudo apt-get update
sudo apt-get upgrade
Install Required Libraries: The BMP180 sensor communicates over the I2C protocol. Therefore, you need to enable I2C on the Raspberry Pi and install the necessary Python libraries.
Enable I2C:
sudo raspi-config
Navigate to Interfacing Options
-> I2C
-> Enable
.
Install Python libraries:
sudo apt-get install python3-smbus python3-dev
sudo pip3 install RPi.bme280
Python Script to Read Data:
Create a new Python script (e.g., bmp180_read.py
) and add the following code:
import smbus
import time
# BMP180 default address
BMP180_ADDR = 0x77
# Register addresses
REG_CONTROL = 0xF4
REG_RESULT = 0xF6
REG_TEMP = 0x2E
REG_PRESSURE = 0x34
# Initialize I2C (SMBus)
bus = smbus.SMBus(1)
def read_raw_data(addr):
high = bus.read_byte_data(BMP180_ADDR, addr)
low = bus.read_byte_data(BMP180_ADDR, addr+1)
val = (high << 8) + low
return val
def read_temperature():
bus.write_byte_data(BMP180_ADDR, REG_CONTROL, REG_TEMP)
time.sleep(0.005) # Wait for conversion
raw_temp = read_raw_data(REG_RESULT)
temp = raw_temp / 340.0 + 36.53 # Example conversion formula
return temp
def read_pressure():
bus.write_byte_data(BMP180_ADDR, REG_CONTROL, REG_PRESSURE)
time.sleep(0.005) # Wait for conversion
raw_pressure = read_raw_data(REG_RESULT)
pressure = raw_pressure / 256.0 # Example conversion formula
return pressure
if __name__ == "__main__":
temp = read_temperature()
pressure = read_pressure()
print(f"Temperature: {temp:.2f} C")
print(f"Pressure: {pressure:.2f} hPa")
Run the Script: Execute the Python script to read temperature and pressure data from the BMP180 sensor.
python3 bmp180_read.py