Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Interface BMP180 Sensor with Raspberry Pi

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:

Hardware Setup

  1. Components Needed:

    • Raspberry Pi (any model with GPIO pins)
    • BMP180 sensor
    • Breadboard and jumper wires
  2. Wiring:

    • Connect the BMP180 sensor to the Raspberry Pi as follows:
      • VCC to 3.3V (pin 1 on the Raspberry Pi)
      • GND to GND (pin 6 on the Raspberry Pi)
      • SCL to SCL (pin 5 on the Raspberry Pi)
      • SDA to SDA (pin 3 on the Raspberry Pi)

Software Setup

  1. Update and Upgrade the System:

    sudo apt-get update
    sudo apt-get upgrade
  2. 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
  3. 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")
  4. Run the Script: Execute the Python script to read temperature and pressure data from the BMP180 sensor.

    python3 bmp180_read.py

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.