altb_pmic / Mbed 2 deprecated Grove-Barometric_Pressure_Sensor_Example

Dependencies:   HP206C mbed

Revision:
1:a6eded1f5043
Parent:
0:5119eeafd9ce
Child:
2:ecd5c6118888
--- a/main.cpp	Tue Jun 25 09:02:23 2019 +0000
+++ b/main.cpp	Tue Jun 25 11:46:33 2019 +0000
@@ -1,7 +1,21 @@
 #include "mbed.h"
 
-#define HP20X_SOFT_RST        0x06
+#define I2C_BAROMETER_ADDRESS 0x76 << 1 // 0xEC, device adress
+
+#define HP20X_SOFT_RST        0x06 // for initializing, takes longer than next
+#define HP20X_ANA_CAL         0x28 // recalibrate analog internal circuitries, for unstable environment
+
 #define HP20X_WR_CONVERT_CMD  0x40
+
+#define HP20X_READ_PT         0x10 // read pressure and altitude command
+#define HP20X_READ_A          0x31 // read altitude command
+
+#define HP20X_WR_REG_MODE     0xC0
+#define HP20X_RD_REG_MODE     0x80
+
+#define HP20X_OK_DEV          0X80 // successfully initialized
+#define HP20X_REG_PARA        0X0F // status register
+
 #define HP20X_CONVERT_OSR4096 0 << 2
 #define HP20X_CONVERT_OSR2048 1 << 2
 #define HP20X_CONVERT_OSR1024 2 << 2
@@ -9,24 +23,7 @@
 #define HP20X_CONVERT_OSR256  4 << 2
 #define HP20X_CONVERT_OSR128  5 << 2
 
-#define HP20X_READ_P          0x30 // read_p command
-#define HP20X_READ_A          0x31 // read_a command
-#define HP20X_READ_T          0x32 // read_t command
-#define HP20X_READ_PT         0x10 // read_pt command
-#define HP20X_READ_AT         0x11 // read_at command
-#define HP20X_READ_CAL        0X28 // RE-CAL ANALOG
-
-#define HP20X_WR_REG_MODE 0xC0
-#define HP20X_RD_REG_MODE 0x80
-
-#define HP20X_ANA_CAL  0x28 // recalibrate analog internal circuitries
-
-#define HP20X_OK_DEV   0X80 // successfully initialized
-#define HP20X_REG_PARA 0X0F // status register
-
-#define I2C_BAROMETER_ADDRESS 0x76 << 1 // 0xEC
-
-#define OSR_CFG HP20X_CONVERT_OSR2048
+#define OSR_CFG HP20X_CONVERT_OSR1024
 
 Serial serial(SERIAL_TX, SERIAL_RX);
 I2C i2c(I2C_SDA, I2C_SCL); // PB_9, PB_8
@@ -195,7 +192,9 @@
     if (result == HP20X_OK_DEV) {
         baro_found = true;
         softReset();
+        // recalibrate();
         disableCompensation();
+        // enableCompensation();
         serial.printf("barometer found\n");
     } else {
         serial.printf("barometer NOT found \n");
@@ -205,15 +204,16 @@
     while(1)
     {
         if (baro_found) {
-            recalibrate();
-            wait_us(70); // this delay is a must if we read temperature, pressure or altitude right after the recalibration (in tests, 60 didn't worked) in microseconds
+            // recalibrate();
+            // wait_us(70); // this delay is a must if we read temperature, pressure or altitude right after the recalibration (in tests, 60 didn't worked) in microseconds
             readTemperatureAndPressureStep1();
             wait_ms(getConversionTime(HP20X_READ_PRES)); // get only the pressure, because its the longest interval
             readTemperatureAndPressureStep2();
             readAltitude();
 
-            serial.printf("temperature %f, pressure %f, altitude %f\r\n", temperature, pressure, altitude);
-            wait_ms(100); // don't hammer the serial console
+            //serial.printf("temperature %f, pressure %f, altitude %f\r\n", temperature, pressure, altitude);
+            serial.printf("altitude %f\r\n", altitude);
+            // wait_ms(1); // don't hammer the serial console
         }
     }
 }