Arduino board run on Mbed-os6.8.1 (only test purpose not official). Need Mbed Studio(1.3.1) not online compiler. If you compile on the online compiler, you can get a hex file but it does NOT work!!!

Dependencies:   APDS_9960 LPS22HB LSM9DS1 HTS221

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main3.cpp Source File

main3.cpp

00001 /*
00002  * Mbed Application program
00003  *  Nano 33 BLE Sense board runs on mbed-OS6
00004  *  LPS33HB -> MEMS nano pressure sensor:
00005  *    260-1260 hPa absolute Digital output barometer
00006  *      by STMicroelectronics
00007  *
00008  * Copyright (c) 2020,'21 Kenji Arai / JH1PJL
00009  *      http://www7b.biglobe.ne.jp/~kenjia/
00010  *      https://os.mbed.com/users/kenjiArai/
00011  *      Started:    January   22nd, 2020
00012  *      Revised:    February  28th, 2021
00013  */
00014 
00015 //  Pre-selection --------------------------------------------------------------
00016 #include    "select_example.h"
00017 //#define EXAMPLE_3_CHECK_LPS22HB
00018 #ifdef EXAMPLE_3_CHECK_LPS22HB
00019 
00020 //  Include --------------------------------------------------------------------
00021 #include    "mbed.h"
00022 #include    "nano33blesense_iodef.h"
00023 #include    "LPS22HB.h"
00024 
00025 //  Definition -----------------------------------------------------------------
00026 
00027 //  Constructor ----------------------------------------------------------------
00028 DigitalOut      sen_pwr(PIN_VDD_ENV, 1);
00029 DigitalOut      i2c_pullup(PIN_I2C_PULLUP, 1);
00030 I2C             i2c(PIN_SDA1, PIN_SCL1);
00031 LPS22HB         *baro = NULL;
00032 Timer           t;
00033 
00034 //  RAM ------------------------------------------------------------------------
00035 
00036 //  ROM / Constant data --------------------------------------------------------
00037 
00038 //  Function prototypes --------------------------------------------------------
00039 
00040 //  subroutin (must be at this below line and do NOT change order) -------------
00041 #include    "usb_serial_as_stdio.h"
00042 #include    "check_revision.h"
00043 #include    "common.h"
00044 
00045 //------------------------------------------------------------------------------
00046 //  Control Program
00047 //------------------------------------------------------------------------------
00048 int main()
00049 {
00050     usb_serial_initialize();
00051     print_revision();
00052     i2c_pullup = 1;
00053     sen_pwr = 1;
00054     print_usb("Check LSM9DS1\r\n");
00055     ThisThread::sleep_for(200ms);
00056     //  check I2C line
00057     check_i2c_connected_devices();
00058     baro = new LPS22HB(i2c, LPS22HB_G_CHIP_ADDR);
00059     uint8_t id = baro->read_id();
00060     if (id == I_AM_LPS22HB) {
00061         print_usb("LPS22H is ready. ID = 0x%x\r\n", id);
00062     } else {
00063         print_usb("LPS22H is NOT ready. return value = 0x%x\r\n", id);
00064     }
00065     baro->set_odr();
00066     uint32_t n = 0;
00067     while(true) {
00068         t.reset();
00069         t.start();
00070         baro->get();
00071         while (baro->data_ready() == 0){
00072                  ThisThread::sleep_for(2ms);
00073         }
00074         print_usb("Pressure:,%6.1f,[hPa],Temperature:,%+4.1f,[degC],",
00075                   baro->pressure(), baro->temperature());
00076         ++n;
00077         uint32_t passed_time = chrono::duration_cast<chrono::milliseconds>(
00078                                t.elapsed_time()).count();
00079         print_usb("processing time:,%2d,[ms],count:,%4d\r\n", passed_time, n);
00080         if (passed_time < 999){
00081             ThisThread::sleep_for(chrono::milliseconds(1000 - passed_time));
00082         }
00083     }
00084 }
00085 
00086 #endif // EXAMPLE_3_CHECK_LPS22HB