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:
6:b38a0cbc1b3f
Parent:
5:f0dac0711070
Child:
8:a212185be55a
--- a/Source/main.cpp	Wed Feb 27 04:43:57 2019 +0000
+++ b/Source/main.cpp	Wed Feb 27 06:48:50 2019 +0000
@@ -14,11 +14,12 @@
  * limitations under the License.
  */
 #include "mbed.h"
-#define BH1790GLC_CONNECTED     1
+#define BH1790GLC_CONNECTED     0
 
 #include "BM1383AGLV.h"
 #include "BM1422AGMV.h"
 #include "KX224.h"
+#include "BH1749NUC.h"
 #include "rohm-rpr0521/rohm-rpr0521/rpr0521.h"
 #include "rohm-rpr0521/rohm-rpr0521/rpr0521_driver.h"
 #include "rohm-sensor-hal/rohm-sensor-hal/I2CCommon.h"
@@ -27,6 +28,7 @@
 BM1383AGLV pressure(I2C_SDA, I2C_SCL);
 BM1422AGMV magnetometer(I2C_SDA, I2C_SCL);
 KX224 accelerometer(I2C_SDA, I2C_SCL);
+BH1749NUC color(I2C_SDA, I2C_SCL);
 #if BH1790GLC_CONNECTED == 1
 RegisterWriter i2c_rw_bh(I2C_SDA, I2C_SCL);
 BH1790GLC heartrate(i2c_rw_bh);
@@ -41,7 +43,7 @@
     float axis_ac[3], temp1_bd1020hfv, temp2_bd1020hfv ;
     bool err_rpr0521;
     int ret;
-    uint16_t bh1790_data[2], rpr0521_data[3];
+    uint16_t buf[5];
 
     printf("\r\nExample program for using following Rohm sensor libraries\r\n");
     printf("      - BM1383AGLV: Pressure/Temperature sensor\r\n");
@@ -52,26 +54,34 @@
 #endif
     printf("      - RPR-0521RS: Light & Proximity Sensor\r\n");
     printf("      - BD1020HFV:  Temperature Sensor, Formula values should be calibrated before use.\r\n");
+    printf("      - BH1749NUC:  Color Sensor\r\n");
 
-    //init KX224-1053
+    // Initialize KX224-1053
     ret = accelerometer.initialize();
     if (ret != 0) {
     	printf("\r\nKX224-1053  :   Failed initialization \n");
     }
 
 #if BH1790GLC_CONNECTED == 1
-    do { //init BH1790GLC
+	// Initialize BH1790GLC
+    do {
         ret = heartrate.set_default_on();
         wait_ms(300);
     } while (ret);
 #endif
 
-    //init RPR-0521RS
+    // Initialize RPR-0521RS
     I2CCommonBegin();
     rpr0521_wait_until_found();
     printf("\nRPR-0521RS Sensor found.\r\n");
     rpr0521_initial_setup();
 
+	// Initialize BH1749NUC
+    ret = color.init();
+    if (ret != 0) {
+    	printf("\r\nBH1749NUC  :   Failed initialization \n");
+    }
+
     while (1) {
         printf("\r++++++++++++++++++\r");
         printf("BM1383AGLV  :   pressure=%7.2f,  temperature=%5.3f\r\n", pressure.getPressure(), pressure.getTemperature());
@@ -81,19 +91,19 @@
        	printf("KX224-1053  :   X=%7.2f,    Y=%7.2f,    Z=%7.2f\r\n", axis_ac[0], axis_ac[1], axis_ac[2]);
 
 #if BH1790GLC_CONNECTED == 1
-        ret = heartrate.getresults(&bh1790_data[0]);
+        ret = heartrate.getresults(buf);
         if (ret) {
             printf("BH1790GLC   :   Failed reading value from BH1790GLC\r\n");
         } else {
-            printf("BH1790GLC   :   value= %d, \t%d\n\r", bh1790_data[1], bh1790_data[0]);
+            printf("BH1790GLC   :   value= %d, \t%d\n\r", buf[1], buf[0]);
         }
 #endif
 
-        err_rpr0521 = rpr0521_read_data(&rpr0521_data[0]);
+        err_rpr0521 = rpr0521_read_data(buf);
         if (err_rpr0521) {
             printf("RPR-0521RS  :   Failed reading value from RPR-0521RS\r\n");
         } else {
-            printf("RPR-0521RS  :   PS= %4u,     Als0= %4u,   Als1= %4u\r\n", rpr0521_data[0], rpr0521_data[1], rpr0521_data[2]);
+            printf("RPR-0521RS  :   PS= %4u,     Als0= %4u,   Als1= %4u\r\n", buf[0], buf[1], buf[2]);
         }
 
         // Input voltage 0-3.3V == 0.0-1.0f
@@ -101,9 +111,13 @@
         //   0'C == 1.546V
         // 192'C == 0V (out of scale)
         // 1.87V / 232'C = 0.008060V/'C
-        temp1_bd1020hfv = -(1000 * (temperature * 3.3f) - 1546) / 8.2;
-        temp2_bd1020hfv = 192 - ( temperature * 3.3f / 0.008060 );
+        temp1_bd1020hfv = -(1000 * (temperature * 3.3f) - 1546) / 8.2f;
+        temp2_bd1020hfv = 192 - ( temperature * 3.3f / 0.008060f );
         printf("BD1020HFV   :   formula1= %5.3f,     formula2= %5.3f\r\n", temp1_bd1020hfv, temp2_bd1020hfv);
+
+        color.get_val(buf);
+        printf("BH1749NUC   :   [R] %04x, [G] %04x, [B] %04x, [IR] %04x, [G2] %04x\n", buf[0], buf[1], buf[2], buf[3], buf[4]);
+
         wait(3);
     }
 }