An example program for Rohm SensorShield-EVK-001 running with Mbed OS 5.

Dependencies:   BM1422AGMV rohm-rpr0521 rohm-sensor-hal rohm-bh1790glc-driver BH1749NUC KX224-1053 BM1383AGLV RegisterWriter

Getting Started with Rohm SensorShield-EVK-001

This example demonstrates how to use the SensorShield-EVK-001 component with multiple sensors. those measured values, which received through a serial connection from a mbed board, are printed out in a terminal software window.

Setup

/media/uploads/edamame22/img_5218.jpg

The SensorShield-EVK-001 is plugged on top of a mbed board and a serial connection should be set up between the mbed board and PC with the following parameters:

  • baud rate: 115200
  • data: 8 bit
  • parity: none
  • stop: 1bit
  • flow control: none

Terminal parameters

/media/uploads/edamame22/serial_port_setup.png /media/uploads/edamame22/terminal_setup.png

Measured Data Output

/media/uploads/edamame22/data_output_2.png

Revision:
3:d119901a65bd
Parent:
2:d022d883a31f
Child:
4:e1f9ba2da8af
--- a/Source/main.cpp	Tue Feb 19 16:08:49 2019 +0900
+++ b/Source/main.cpp	Thu Feb 21 16:55:15 2019 +0900
@@ -14,20 +14,51 @@
  * limitations under the License.
  */
 #include "mbed.h"
+
+#define BM1383AGLV_CONNECTED    1
+#define BM1422AGMV_CONNECTED    1
+#define KX224_1053_CONNECTED    1
+#define BH1790GLC_CONNECTED     0
+#define RPR_0521RS_CONNECTED    1
+#define BD1020HFV_CONNECTED     1
+
+#if BM1383AGLV_CONNECTED == 1
 #include "BM1383AGLV.h"
+#endif
+#if BM1422AGMV_CONNECTED == 1
 #include "BM1422AGMV.h"
+#endif
+#if KX224_1053_CONNECTED == 1
 #include "KX224.h"
+#endif
+#if BH1790GLC_CONNECTED == 1
 #include "rohm-bh1790glc-driver/bh1790glc.h"
+#endif
+#if RPR_0521RS_CONNECTED == 1
 #include "rohm-rpr0521/rohm-rpr0521/rpr0521.h"
 #include "rohm-rpr0521/rohm-rpr0521/rpr0521_driver.h"
 #include "rohm-sensor-hal/rohm-sensor-hal/I2CCommon.h"
+#endif
 
+#if BM1383AGLV_CONNECTED == 1
 BM1383AGLV bm1383aglv(I2C_SDA, I2C_SCL);
+#endif
+#if BM1422AGMV_CONNECTED == 1
 BM1422AGMV bm1422agmv(I2C_SDA, I2C_SCL);
+#endif
+#if KX224_1053_CONNECTED == 1
 KX224 kx224_1053(I2C_SDA, I2C_SCL);
+#endif
+#if BH1790GLC_CONNECTED == 1
 RegisterWriter i2c_rw_bh(I2C_SDA, I2C_SCL);
 BH1790GLC bh1790glc(i2c_rw_bh);
-AnalogIn bd1020hfv(A2);
+#endif
+#if BD1020HFV_CONNECTED == 1
+#ifdef TARGET_K66F
+#warning A2 pin is disabled on THIS BOARD, please use A0 pin!!
+#endif
+AnalogIn bd1020hfv(A0);
+#endif
 
 Serial pc(USBTX, USBRX);
 
@@ -38,38 +69,62 @@
     uint16_t bh1790_data[2], rpr0521_data[3];
 
     pc.printf("\r\nExample program for using following Rohm sensor libraries\r\n");
-    pc.printf("\n      - BM1383AGLV: Pressure/Temperature sensor\n");
-    pc.printf("\r      - BM1422AGMV: 3 axis magnetic sensor\n");
-    pc.printf("\r      - KX224-1053: 3 axis accelerometer\n");
-    pc.printf("\r      - BH1790GLC:  optical sensor for heart rate monitor\n");
-    pc.printf("\r      - RPR-0521RS: Light & Proximity Sensor\n");
-    pc.printf("\r      - BD1020HFV:  Temperature Sensor, Formula values should be calibrated before use.\n");
+#if BM1383AGLV_CONNECTED == 1
+    pc.printf("\n      - BM1383AGLV: Pressure/Temperature sensor\r\n");
+#endif
+#if BM1422AGMV_CONNECTED == 1
+    pc.printf("\r      - BM1422AGMV: 3 axis magnetic sensor\r\n");
+#endif
+#if KX224_1053_CONNECTED == 1
+    pc.printf("\r      - KX224-1053: 3 axis accelerometer\r\n");
+#endif
+#if BH1790GLC_CONNECTED == 1
+    pc.printf("\r      - BH1790GLC:  optical sensor for heart rate monitor\r\n");
+#endif
+#if RPR_0521RS_CONNECTED == 1
+    pc.printf("\r      - RPR-0521RS: Light & Proximity Sensor\r\n");
+#endif
+#if BD1020HFV_CONNECTED == 1
+    pc.printf("\r      - BD1020HFV:  Temperature Sensor, Formula values should be calibrated before use.\r\n");
+#endif
+
+#if KX224_1053_CONNECTED == 1
     //init KX224-1053
     err_KX224=kx224_1053.initialize();
     if (err_KX224!=0){
-        pc.printf("\r\nkx224_1053  :   Failed initialization \r\n");
+        pc.printf("\r\nkx224_1053  :   Failed initialization \n");
     }
-
+#endif
+#if BH1790GLC_CONNECTED == 1
     do{ //init BH1790GLC
         err_bh1790 = bh1790glc.set_default_on();
         wait_ms(300);
     } while (err_bh1790);
-
+#endif
+#if RPR_0521RS_CONNECTED == 1
     //init RPR-0521RS
     I2CCommonBegin();
     rpr0521_wait_until_found();
     pc.printf("\nRPR-0521RS Sensor found.\r\n");
     rpr0521_initial_setup();
+#endif
 
     while(1) {
         pc.printf("\r++++++++++++++++++\r");
+#if BM1383AGLV_CONNECTED == 1
         pc.printf("\r\nbm1383aglv  :   pressure=%7.2f,  temperature=%5.3f\r\n", bm1383aglv.getPressure(), bm1383aglv.getTemperature());
+#endif
+#if BM1422AGMV_CONNECTED == 1
         memset(&axis_ac[0], 0, sizeof(axis_ac));
         bm1422agmv.get_val(&axis_ac[0]);
-        pc.printf("\r\nbm1422agmv  :   X=%7.2f,    Y=%7.2f,    Z=%7.2f\n\r", axis_ac[0], axis_ac[1], axis_ac[2]);
+        pc.printf("\r\nbm1422agmv  :   X=%7.2f,    Y=%7.2f,    Z=%7.2f\r\n", axis_ac[0], axis_ac[1], axis_ac[2]);
+#endif
+#if KX224_1053_CONNECTED == 1
         memset(&axis_ac[0], 0, sizeof(axis_ac));
         kx224_1053.get_val(&axis_ac[0]);
-       	pc.printf("\r\nkx224_1053  :   X=%7.2f,    Y=%7.2f,    Z=%7.2f\n\r", axis_ac[0], axis_ac[1], axis_ac[2]);
+       	pc.printf("\r\nkx224_1053  :   X=%7.2f,    Y=%7.2f,    Z=%7.2f\r\n", axis_ac[0], axis_ac[1], axis_ac[2]);
+#endif
+#if BH1790GLC_CONNECTED == 1
        	memset(&bh1790_data[0], 0, sizeof(bh1790_data));
         err_bh1790 = bh1790glc.getresults(&bh1790_data[0]);
         if(err_bh1790) {
@@ -77,6 +132,8 @@
         } else {
             pc.printf("\r\nBH1790GLC   :   value= %d, \t%d\n\r", bh1790_data[1], bh1790_data[0]);
         }
+#endif
+#if RPR_0521RS_CONNECTED == 1
         memset(&rpr0521_data[0], 0, sizeof(rpr0521_data));
         err_rpr0521 = rpr0521_read_data(&rpr0521_data[0]);
         if(err_rpr0521) {
@@ -84,6 +141,8 @@
         } else {
             pc.printf("\r\nRPR-0521RS  :   PS= %4u,    Als0= %4u,    Als1= %4u\r\n", rpr0521_data[0], rpr0521_data[1], rpr0521_data[2]);
         }
+#endif
+#if BD1020HFV_CONNECTED == 1
         //Input voltage 0-3.3V == 0.0-1.0f
         //-40'C == 1.87V
         //  0'C == 1.546V
@@ -92,6 +151,7 @@
         temp1_bd1020hfv = -(1000 * (bd1020hfv * 3.3f) - 1546) / 8.2;
         temp2_bd1020hfv = 192 - ( bd1020hfv * 3.3f / 0.008060 );
         pc.printf("\r\nBD1020HFV   :   formula1= %5.3f,     formula2= %5.3f\r\n", temp1_bd1020hfv, temp2_bd1020hfv);
+#endif
         wait(3);
     }
 }