Etape 1 : Installer la librairie bmp280.py pour gérer le capteur bmp280
#
#Installer la librairie bmp280.py
#pour utiliser le capteur de pression atmosphérique
from machine import Pin
import urequests
from time import sleep
fichier = "bmp280.py"
get_lib = "http://217.182.207.90/ota1/"+fichier
reponse = urequests.get(get_lib)
f = open(fichier,"w")
f.write(reponse.text)
f.flush()
f.close
led = Pin(2, Pin.OUT)
print("Librairie ",fichier," installée sur l'ESP")
while True:
led.value(not led.value())
sleep(0.1)
Etape 2 : Tester le capteur bmp280
#
from machine import Pin, SoftI2C
from bmp280 import *
# ESP32 - Pin protocole i2c
i2c = SoftI2C(scl=Pin(22), sda=Pin(21))
bmp = BMP280(i2c_bus=i2c, addr=0x77)
print(bmp.temperature)
print(bmp.pressure)
print("ok")
Source : https://github.com/dafvid/micropython-bmp280