Exemple #1
0
#通过I2C连接bmp388和esp32
#download bmp388.py and downloadAndRun this demo

import bmp388
import time
from machine import Pin, I2C

#create I2C object
i2c = I2C(scl=Pin(22), sda=Pin(21), freq=100000)

#create I2C通信的bmp388 object
bmp388 = bmp388.DFRobot_BMP388_I2C(i2c)

#read temperature and print it
while 1:
    temp = bmp388.readTemperature()
    print("Temperature : %s" % temp)
    time.sleep(0.5)
    rateOfTurn = (currentHeading - previousHeading) / LP
    # print ('Raw Rateof Turn: %4.0f' % rateOfTurn)

    ##################### BMP388 Code ######################################

    # You can use an accurate altitude to calibrate sea level air pressure.
    # And then use this calibrated sea level pressure as a reference to obtain the calibrated altitude.
    # In this case,525.0m is chendu accurate altitude.
    seaLevel = bmp388.readSeaLevel(218.8)
    # print("seaLevel : %s Pa" %seaLevel)

    # If there is no need to calibrate altitude, calibrated_altitude = False
    calibrated_altitude = True

    # Read temperature and print it
    temp = (bmp388.readTemperature() + 273.15)  # Deg C Converted to Kelvin (K)
    # print("Temperature : %s C" %temp)
    pres = bmp388.readPressure()
    # print("Pressure : %s Pa" %pres)
    if (calibrated_altitude):
        # Read the calibrated altitude
        altitude = bmp388.readCalibratedAltitude(seaLevel)
        # print("calibrate Altitude : %s m" %altitude)
    else:
        # Read the altitude
        altitude = bmp388.readAltitude()
        # print("Altitude : %s m" %altitude)
    ############################ END ##################################

    if config["Heading"]:  # Change to 'false' to stop sending the heading
        skDataTx = '{"updates": [{ "values": [{ "path": "navigation.headingCompass", "value" :%01.3f' % (