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:
Ren Boting
Date:
Tue Feb 19 16:08:49 2019 +0900
Revision:
2:d022d883a31f
Parent:
0:a9aeed8cd62e
Child:
3:d119901a65bd
reform and shorten main.cpp.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Ren Boting 0:a9aeed8cd62e 1 /* Rohm SensorShield-EVK-xxx 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 0:a9aeed8cd62e 17 #include "BM1383AGLV.h"
Ren Boting 0:a9aeed8cd62e 18 #include "BM1422AGMV.h"
Ren Boting 0:a9aeed8cd62e 19 #include "KX224.h"
Ren Boting 0:a9aeed8cd62e 20 #include "rohm-bh1790glc-driver/bh1790glc.h"
Ren Boting 0:a9aeed8cd62e 21 #include "rohm-rpr0521/rohm-rpr0521/rpr0521.h"
Ren Boting 0:a9aeed8cd62e 22 #include "rohm-rpr0521/rohm-rpr0521/rpr0521_driver.h"
Ren Boting 0:a9aeed8cd62e 23 #include "rohm-sensor-hal/rohm-sensor-hal/I2CCommon.h"
Ren Boting 0:a9aeed8cd62e 24
Ren Boting 2:d022d883a31f 25 BM1383AGLV bm1383aglv(I2C_SDA, I2C_SCL);
Ren Boting 2:d022d883a31f 26 BM1422AGMV bm1422agmv(I2C_SDA, I2C_SCL);
Ren Boting 2:d022d883a31f 27 KX224 kx224_1053(I2C_SDA, I2C_SCL);
Ren Boting 0:a9aeed8cd62e 28 RegisterWriter i2c_rw_bh(I2C_SDA, I2C_SCL);
Ren Boting 2:d022d883a31f 29 BH1790GLC bh1790glc(i2c_rw_bh);
Ren Boting 2:d022d883a31f 30 AnalogIn bd1020hfv(A2);
Ren Boting 0:a9aeed8cd62e 31
Ren Boting 0:a9aeed8cd62e 32 Serial pc(USBTX, USBRX);
Ren Boting 0:a9aeed8cd62e 33
Ren Boting 0:a9aeed8cd62e 34 int main() {
Ren Boting 2:d022d883a31f 35 float axis_ac[3], temp1_bd1020hfv, temp2_bd1020hfv ;
Ren Boting 2:d022d883a31f 36 bool err_rpr0521;
Ren Boting 2:d022d883a31f 37 int err_bh1790, err_KX224;
Ren Boting 2:d022d883a31f 38 uint16_t bh1790_data[2], rpr0521_data[3];
Ren Boting 0:a9aeed8cd62e 39
Ren Boting 0:a9aeed8cd62e 40 pc.printf("\r\nExample program for using following Rohm sensor libraries\r\n");
Ren Boting 0:a9aeed8cd62e 41 pc.printf("\n - BM1383AGLV: Pressure/Temperature sensor\n");
Ren Boting 0:a9aeed8cd62e 42 pc.printf("\r - BM1422AGMV: 3 axis magnetic sensor\n");
Ren Boting 0:a9aeed8cd62e 43 pc.printf("\r - KX224-1053: 3 axis accelerometer\n");
Ren Boting 0:a9aeed8cd62e 44 pc.printf("\r - BH1790GLC: optical sensor for heart rate monitor\n");
Ren Boting 0:a9aeed8cd62e 45 pc.printf("\r - RPR-0521RS: Light & Proximity Sensor\n");
Ren Boting 0:a9aeed8cd62e 46 pc.printf("\r - BD1020HFV: Temperature Sensor, Formula values should be calibrated before use.\n");
Ren Boting 0:a9aeed8cd62e 47 //init KX224-1053
Ren Boting 2:d022d883a31f 48 err_KX224=kx224_1053.initialize();
Ren Boting 0:a9aeed8cd62e 49 if (err_KX224!=0){
Ren Boting 2:d022d883a31f 50 pc.printf("\r\nkx224_1053 : Failed initialization \r\n");
Ren Boting 0:a9aeed8cd62e 51 }
Ren Boting 0:a9aeed8cd62e 52
Ren Boting 0:a9aeed8cd62e 53 do{ //init BH1790GLC
Ren Boting 2:d022d883a31f 54 err_bh1790 = bh1790glc.set_default_on();
Ren Boting 0:a9aeed8cd62e 55 wait_ms(300);
Ren Boting 0:a9aeed8cd62e 56 } while (err_bh1790);
Ren Boting 0:a9aeed8cd62e 57
Ren Boting 0:a9aeed8cd62e 58 //init RPR-0521RS
Ren Boting 0:a9aeed8cd62e 59 I2CCommonBegin();
Ren Boting 0:a9aeed8cd62e 60 rpr0521_wait_until_found();
Ren Boting 0:a9aeed8cd62e 61 pc.printf("\nRPR-0521RS Sensor found.\r\n");
Ren Boting 0:a9aeed8cd62e 62 rpr0521_initial_setup();
Ren Boting 0:a9aeed8cd62e 63
Ren Boting 0:a9aeed8cd62e 64 while(1) {
Ren Boting 2:d022d883a31f 65 pc.printf("\r++++++++++++++++++\r");
Ren Boting 2:d022d883a31f 66 pc.printf("\r\nbm1383aglv : pressure=%7.2f, temperature=%5.3f\r\n", bm1383aglv.getPressure(), bm1383aglv.getTemperature());
Ren Boting 2:d022d883a31f 67 memset(&axis_ac[0], 0, sizeof(axis_ac));
Ren Boting 2:d022d883a31f 68 bm1422agmv.get_val(&axis_ac[0]);
Ren Boting 2:d022d883a31f 69 pc.printf("\r\nbm1422agmv : X=%7.2f, Y=%7.2f, Z=%7.2f\n\r", axis_ac[0], axis_ac[1], axis_ac[2]);
Ren Boting 2:d022d883a31f 70 memset(&axis_ac[0], 0, sizeof(axis_ac));
Ren Boting 2:d022d883a31f 71 kx224_1053.get_val(&axis_ac[0]);
Ren Boting 2:d022d883a31f 72 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]);
Ren Boting 2:d022d883a31f 73 memset(&bh1790_data[0], 0, sizeof(bh1790_data));
Ren Boting 2:d022d883a31f 74 err_bh1790 = bh1790glc.getresults(&bh1790_data[0]);
Ren Boting 2:d022d883a31f 75 if(err_bh1790) {
Ren Boting 2:d022d883a31f 76 pc.printf("\r\nBH1790GLC : Failed reading value from BH1790GLC\r\n");
Ren Boting 2:d022d883a31f 77 } else {
Ren Boting 2:d022d883a31f 78 pc.printf("\r\nBH1790GLC : value= %d, \t%d\n\r", bh1790_data[1], bh1790_data[0]);
Ren Boting 2:d022d883a31f 79 }
Ren Boting 2:d022d883a31f 80 memset(&rpr0521_data[0], 0, sizeof(rpr0521_data));
Ren Boting 2:d022d883a31f 81 err_rpr0521 = rpr0521_read_data(&rpr0521_data[0]);
Ren Boting 2:d022d883a31f 82 if(err_rpr0521) {
Ren Boting 2:d022d883a31f 83 pc.printf("\r\nRPR-0521RS : Failed reading value from RPR-0521RS\r\n");
Ren Boting 2:d022d883a31f 84 } else {
Ren Boting 2:d022d883a31f 85 pc.printf("\r\nRPR-0521RS : PS= %4u, Als0= %4u, Als1= %4u\r\n", rpr0521_data[0], rpr0521_data[1], rpr0521_data[2]);
Ren Boting 2:d022d883a31f 86 }
Ren Boting 2:d022d883a31f 87 //Input voltage 0-3.3V == 0.0-1.0f
Ren Boting 2:d022d883a31f 88 //-40'C == 1.87V
Ren Boting 2:d022d883a31f 89 // 0'C == 1.546V
Ren Boting 2:d022d883a31f 90 //192'C == 0V (out of scale)
Ren Boting 2:d022d883a31f 91 //1.87V / 232'C = 0.008060V/'C
Ren Boting 2:d022d883a31f 92 temp1_bd1020hfv = -(1000 * (bd1020hfv * 3.3f) - 1546) / 8.2;
Ren Boting 2:d022d883a31f 93 temp2_bd1020hfv = 192 - ( bd1020hfv * 3.3f / 0.008060 );
Ren Boting 2:d022d883a31f 94 pc.printf("\r\nBD1020HFV : formula1= %5.3f, formula2= %5.3f\r\n", temp1_bd1020hfv, temp2_bd1020hfv);
Ren Boting 2:d022d883a31f 95 wait(3);
Ren Boting 0:a9aeed8cd62e 96 }
Ren Boting 0:a9aeed8cd62e 97 }