from machine import I2C, Pin
from bmp180 import BMP180
import time
# Configuracion I2C - pines ESP32
i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=100000)
# Inicializar sensor
sensor = BMP180(i2c)
sensor.oversample = 2
print("BMP180 listo!")
print("-" * 40)
while True:
temp = sensor.temperature
pres = sensor.pressure / 100.0
print(f"Temp: {temp:.1f} C | Presion: {pres:.1f} hPa")
# High temperature alert
if temp > 40:
print("-" * 40)
print("*** ALERT: HIGH temperature ***")
print(f" {temp:.1f} C° - greater than 40 C°")
print(" Check the environment!")
print("-" * 40)
# Low temperature alert
elif temp < 10:
print("-" * 40)
print("*** ALERT: LOW temperature ***")
print(f" {temp:.1f} C - Less than 10° C")
print(" Risk of freezing!")
print("-" * 40)
# Normal temperature
else:
print(" Status: Normal")
time.sleep(2)
Loading
bmp180
bmp180