Air Preasure Sensor
[1] Pembukaan
BMP390L (seri module Ari Preasure Sensor) adalah sensor tekanan barometrik digital khusus industri yang baru dikembangkan oleh Bosch yang memiliki stabilitas suhu yang sangat tinggi, drift rendah, serta konsumsi daya yang rendah.[2] Wiring
2. BMP390L with Mini PC
1. Arduino IDE
#include <DFRobot_BMP3XX.h>
DFRobot_BMP390L_IIC sensor(&Wire, sensor.eSDOVDD);
#define CALIBRATE_ABSOLUTE_DIFFERENCE
void setup(void)
{
Serial.begin(115200);
int rslt;
while( ERR_OK != (rslt = sensor.begin()) ){
if(ERR_DATA_BUS == rslt){
Serial.println("Data bus error!!!");
}else if(ERR_IC_VERSION == rslt){
Serial.println("Chip versions do not match!!!");
}
delay(3000);
}
Serial.println("Begin ok!");
while( !sensor.setSamplingMode(sensor.eUltraPrecision) ){
Serial.println("Set samping mode fail, retrying....");
delay(3000);
}
delay(100);
#ifdef CALIBRATE_ABSOLUTE_DIFFERENCE
/**
* Calibrate the sensor according to the current altitude
* In this example, we use an altitude of 540 meters in Wenjiang District of Chengdu (China).
* Please change to the local altitude when using it.
* If this interface is not called, the measurement data will not eliminate the absolute difference.
* Notice: This interface is only valid for the first call.
*/
if( sensor.calibratedAbsoluteDifference(540.0) ){
Serial.println("Absolute difference base value set successfully!");
}
#endif
/* Get the sampling period of the current measurement mode, unit: us */
float sampingPeriodus = sensor.getSamplingPeriodUS();
Serial.print("samping period : ");
Serial.print(sampingPeriodus);
Serial.println(" us");
/* Get the sampling frequency of the current measurement mode, unit: Hz */
float sampingFrequencyHz = 1000000 / sampingPeriodus;
Serial.print("samping frequency : ");
Serial.print(sampingFrequencyHz);
Serial.println(" Hz");
Serial.println();
delay(1000);
}
void loop()
{
/* Read currently measured temperature date directly, unit: °C */
float temperature = sensor.readTempC();
Serial.print("temperature : ");
Serial.print(temperature);
Serial.println(" C");
/* Directly read the currently measured pressure data, unit: pa */
float Pressure = sensor.readPressPa();
Serial.print("Pressure : ");
Serial.print(Pressure);
Serial.println(" Pa");
/* Read altitude, unit: m */
float altitude = sensor.readAltitudeM();
Serial.print("Altitude : ");
Serial.print(altitude);
Serial.println(" m");
Serial.println();
delay(1000);
}
2. MicroPhyton
import time
from machine import Pin, I2C
from micropython_bmpxxx import bmpxxx
#i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
i2c = I2C(id=1, scl=Pin(27), sda=Pin(26))
i2c1_devices = i2c.scan()
if i2c1_devices:
for d in i2c1_devices: print(f"i2c1 device at address: {hex(d)}")
else:
print("ERROR: No i2c1 devices")
print("")
bmp = bmpxxx.BMP390(i2c=i2c, address=0x76)
sea_level_pressure = bmp.sea_level_pressure
print(f"initial sea_level_pressure = {sea_level_pressure:.2f} hPa")
sea_level_pressure = bmp.sea_level_pressure
print(f"Initial sea_level_pressure = {sea_level_pressure:.2f} hPa")
# reset driver to contain the accurate sea level pressure (SLP) from my nearest airport this hour
bmp.sea_level_pressure = 1017.0
print(f"Adjusted sea level pressure = {bmp.sea_level_pressure:.2f} hPa")
# Alternatively set known altitude in meters and the sea level pressure will be calculated
bmp.altitude = 111.0
print(f"Adjusted SLP using {bmp.altitude:.2f} meter altitude = {bmp.sea_level_pressure:.2f} hPa\n")
while True:
print(f"Pressure = {bmp.pressure:.2f} hPa")
temp = bmp.temperature
print(f"temp = {temp:.2f} C")
meters = bmp.altitude
print(f"Altitude = {meters:.2f} meters")
feet = meters * 3.28084
feet_only = int(feet)
inches = int((feet - feet_only) * 12)
print(f"Altitude = {feet_only} feet {inches} inches")
time.sleep(2.5)
Reverensinya bisa dilihat di sini
https://wiki.dfrobot.com/Fermion_BMP390L_Digital_Barometric_Pressure_Sensor_SKU_SEN0423
https://github.com/bradcar/MicroPython_BMPxxx
Komentar
Posting Komentar