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

Committer:
MACRUM
Date:
Wed Feb 27 04:43:57 2019 +0000
Revision:
5:f0dac0711070
Parent:
4:e1f9ba2da8af
Child:
6:b38a0cbc1b3f
Code clean-up

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MACRUM 5:f0dac0711070 1 /* Rohm SensorShield-EVK-001 Example
Ren Boting 0:a9aeed8cd62e 2 * Copyright (c) 2019 ARM Limited
Ren Boting 0:a9aeed8cd62e 3 *
Ren Boting 0:a9aeed8cd62e 4 * Licensed under the Apache License, Version 2.0 (the "License");
Ren Boting 0:a9aeed8cd62e 5 * you may not use this file except in compliance with the License.
Ren Boting 0:a9aeed8cd62e 6 * You may obtain a copy of the License at
Ren Boting 0:a9aeed8cd62e 7 *
Ren Boting 0:a9aeed8cd62e 8 * http://www.apache.org/licenses/LICENSE-2.0
Ren Boting 0:a9aeed8cd62e 9 *
Ren Boting 0:a9aeed8cd62e 10 * Unless required by applicable law or agreed to in writing, software
Ren Boting 0:a9aeed8cd62e 11 * distributed under the License is distributed on an "AS IS" BASIS,
Ren Boting 0:a9aeed8cd62e 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Ren Boting 0:a9aeed8cd62e 13 * See the License for the specific language governing permissions and
Ren Boting 0:a9aeed8cd62e 14 * limitations under the License.
Ren Boting 0:a9aeed8cd62e 15 */
Ren Boting 2:d022d883a31f 16 #include "mbed.h"
Ren Boting 4:e1f9ba2da8af 17 #define BH1790GLC_CONNECTED 1
Ren Boting 3:d119901a65bd 18
Ren Boting 0:a9aeed8cd62e 19 #include "BM1383AGLV.h"
Ren Boting 0:a9aeed8cd62e 20 #include "BM1422AGMV.h"
Ren Boting 0:a9aeed8cd62e 21 #include "KX224.h"
Ren Boting 4:e1f9ba2da8af 22 #include "rohm-rpr0521/rohm-rpr0521/rpr0521.h"
Ren Boting 4:e1f9ba2da8af 23 #include "rohm-rpr0521/rohm-rpr0521/rpr0521_driver.h"
Ren Boting 4:e1f9ba2da8af 24 #include "rohm-sensor-hal/rohm-sensor-hal/I2CCommon.h"
MACRUM 5:f0dac0711070 25 #include "rohm-bh1790glc-driver/bh1790glc.h"
MACRUM 5:f0dac0711070 26
MACRUM 5:f0dac0711070 27 BM1383AGLV pressure(I2C_SDA, I2C_SCL);
MACRUM 5:f0dac0711070 28 BM1422AGMV magnetometer(I2C_SDA, I2C_SCL);
MACRUM 5:f0dac0711070 29 KX224 accelerometer(I2C_SDA, I2C_SCL);
Ren Boting 3:d119901a65bd 30 #if BH1790GLC_CONNECTED == 1
MACRUM 5:f0dac0711070 31 RegisterWriter i2c_rw_bh(I2C_SDA, I2C_SCL);
MACRUM 5:f0dac0711070 32 BH1790GLC heartrate(i2c_rw_bh);
Ren Boting 3:d119901a65bd 33 #endif
Ren Boting 0:a9aeed8cd62e 34
Ren Boting 3:d119901a65bd 35 #ifdef TARGET_K66F
Ren Boting 4:e1f9ba2da8af 36 #warning A2 pin is disabled on THIS BOARD, please use A0 pin for BD1020HFV!!
Ren Boting 3:d119901a65bd 37 #endif
MACRUM 5:f0dac0711070 38 AnalogIn temperature(A0); // BD1020HFV
Ren Boting 0:a9aeed8cd62e 39
Ren Boting 0:a9aeed8cd62e 40 int main() {
Ren Boting 2:d022d883a31f 41 float axis_ac[3], temp1_bd1020hfv, temp2_bd1020hfv ;
Ren Boting 2:d022d883a31f 42 bool err_rpr0521;
MACRUM 5:f0dac0711070 43 int ret;
Ren Boting 2:d022d883a31f 44 uint16_t bh1790_data[2], rpr0521_data[3];
Ren Boting 0:a9aeed8cd62e 45
MACRUM 5:f0dac0711070 46 printf("\r\nExample program for using following Rohm sensor libraries\r\n");
MACRUM 5:f0dac0711070 47 printf(" - BM1383AGLV: Pressure/Temperature sensor\r\n");
MACRUM 5:f0dac0711070 48 printf(" - BM1422AGMV: 3 axis magnetic sensor\r\n");
MACRUM 5:f0dac0711070 49 printf(" - KX224-1053: 3 axis accelerometer\r\n");
Ren Boting 3:d119901a65bd 50 #if BH1790GLC_CONNECTED == 1
MACRUM 5:f0dac0711070 51 printf(" - BH1790GLC: optical sensor for heart rate monitor\r\n");
Ren Boting 3:d119901a65bd 52 #endif
MACRUM 5:f0dac0711070 53 printf(" - RPR-0521RS: Light & Proximity Sensor\r\n");
MACRUM 5:f0dac0711070 54 printf(" - BD1020HFV: Temperature Sensor, Formula values should be calibrated before use.\r\n");
Ren Boting 3:d119901a65bd 55
Ren Boting 0:a9aeed8cd62e 56 //init KX224-1053
MACRUM 5:f0dac0711070 57 ret = accelerometer.initialize();
MACRUM 5:f0dac0711070 58 if (ret != 0) {
MACRUM 5:f0dac0711070 59 printf("\r\nKX224-1053 : Failed initialization \n");
Ren Boting 0:a9aeed8cd62e 60 }
Ren Boting 4:e1f9ba2da8af 61
Ren Boting 3:d119901a65bd 62 #if BH1790GLC_CONNECTED == 1
MACRUM 5:f0dac0711070 63 do { //init BH1790GLC
MACRUM 5:f0dac0711070 64 ret = heartrate.set_default_on();
Ren Boting 0:a9aeed8cd62e 65 wait_ms(300);
MACRUM 5:f0dac0711070 66 } while (ret);
Ren Boting 3:d119901a65bd 67 #endif
Ren Boting 4:e1f9ba2da8af 68
Ren Boting 0:a9aeed8cd62e 69 //init RPR-0521RS
Ren Boting 0:a9aeed8cd62e 70 I2CCommonBegin();
Ren Boting 0:a9aeed8cd62e 71 rpr0521_wait_until_found();
MACRUM 5:f0dac0711070 72 printf("\nRPR-0521RS Sensor found.\r\n");
Ren Boting 0:a9aeed8cd62e 73 rpr0521_initial_setup();
Ren Boting 0:a9aeed8cd62e 74
MACRUM 5:f0dac0711070 75 while (1) {
MACRUM 5:f0dac0711070 76 printf("\r++++++++++++++++++\r");
MACRUM 5:f0dac0711070 77 printf("BM1383AGLV : pressure=%7.2f, temperature=%5.3f\r\n", pressure.getPressure(), pressure.getTemperature());
MACRUM 5:f0dac0711070 78 magnetometer.get_val(&axis_ac[0]);
MACRUM 5:f0dac0711070 79 printf("BM1422AGMV : X=%7.2f, Y=%7.2f, Z=%7.2f\r\n", axis_ac[0], axis_ac[1], axis_ac[2]);
MACRUM 5:f0dac0711070 80 accelerometer.get_val(&axis_ac[0]);
MACRUM 5:f0dac0711070 81 printf("KX224-1053 : X=%7.2f, Y=%7.2f, Z=%7.2f\r\n", axis_ac[0], axis_ac[1], axis_ac[2]);
Ren Boting 4:e1f9ba2da8af 82
Ren Boting 3:d119901a65bd 83 #if BH1790GLC_CONNECTED == 1
MACRUM 5:f0dac0711070 84 ret = heartrate.getresults(&bh1790_data[0]);
MACRUM 5:f0dac0711070 85 if (ret) {
MACRUM 5:f0dac0711070 86 printf("BH1790GLC : Failed reading value from BH1790GLC\r\n");
Ren Boting 2:d022d883a31f 87 } else {
MACRUM 5:f0dac0711070 88 printf("BH1790GLC : value= %d, \t%d\n\r", bh1790_data[1], bh1790_data[0]);
Ren Boting 2:d022d883a31f 89 }
Ren Boting 3:d119901a65bd 90 #endif
Ren Boting 4:e1f9ba2da8af 91
Ren Boting 2:d022d883a31f 92 err_rpr0521 = rpr0521_read_data(&rpr0521_data[0]);
MACRUM 5:f0dac0711070 93 if (err_rpr0521) {
MACRUM 5:f0dac0711070 94 printf("RPR-0521RS : Failed reading value from RPR-0521RS\r\n");
Ren Boting 2:d022d883a31f 95 } else {
MACRUM 5:f0dac0711070 96 printf("RPR-0521RS : PS= %4u, Als0= %4u, Als1= %4u\r\n", rpr0521_data[0], rpr0521_data[1], rpr0521_data[2]);
Ren Boting 2:d022d883a31f 97 }
Ren Boting 4:e1f9ba2da8af 98
MACRUM 5:f0dac0711070 99 // Input voltage 0-3.3V == 0.0-1.0f
MACRUM 5:f0dac0711070 100 // -40'C == 1.87V
MACRUM 5:f0dac0711070 101 // 0'C == 1.546V
MACRUM 5:f0dac0711070 102 // 192'C == 0V (out of scale)
MACRUM 5:f0dac0711070 103 // 1.87V / 232'C = 0.008060V/'C
MACRUM 5:f0dac0711070 104 temp1_bd1020hfv = -(1000 * (temperature * 3.3f) - 1546) / 8.2;
MACRUM 5:f0dac0711070 105 temp2_bd1020hfv = 192 - ( temperature * 3.3f / 0.008060 );
MACRUM 5:f0dac0711070 106 printf("BD1020HFV : formula1= %5.3f, formula2= %5.3f\r\n", temp1_bd1020hfv, temp2_bd1020hfv);
Ren Boting 2:d022d883a31f 107 wait(3);
Ren Boting 0:a9aeed8cd62e 108 }
Ren Boting 0:a9aeed8cd62e 109 }