![](/media/cache/group/200px-Rohm_logo_2009.png.50x50_q85.png)
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
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
Measured Data Output
Source/main.cpp@3:d119901a65bd, 2019-02-21 (annotated)
- Committer:
- Ren Boting
- Date:
- Thu Feb 21 16:55:15 2019 +0900
- Revision:
- 3:d119901a65bd
- Parent:
- 2:d022d883a31f
- Child:
- 4:e1f9ba2da8af
add enable definition for each sensor at main.cpp.
Who changed what in which revision?
User | Revision | Line number | New 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 | 3:d119901a65bd | 17 | |
Ren Boting | 3:d119901a65bd | 18 | #define BM1383AGLV_CONNECTED 1 |
Ren Boting | 3:d119901a65bd | 19 | #define BM1422AGMV_CONNECTED 1 |
Ren Boting | 3:d119901a65bd | 20 | #define KX224_1053_CONNECTED 1 |
Ren Boting | 3:d119901a65bd | 21 | #define BH1790GLC_CONNECTED 0 |
Ren Boting | 3:d119901a65bd | 22 | #define RPR_0521RS_CONNECTED 1 |
Ren Boting | 3:d119901a65bd | 23 | #define BD1020HFV_CONNECTED 1 |
Ren Boting | 3:d119901a65bd | 24 | |
Ren Boting | 3:d119901a65bd | 25 | #if BM1383AGLV_CONNECTED == 1 |
Ren Boting | 0:a9aeed8cd62e | 26 | #include "BM1383AGLV.h" |
Ren Boting | 3:d119901a65bd | 27 | #endif |
Ren Boting | 3:d119901a65bd | 28 | #if BM1422AGMV_CONNECTED == 1 |
Ren Boting | 0:a9aeed8cd62e | 29 | #include "BM1422AGMV.h" |
Ren Boting | 3:d119901a65bd | 30 | #endif |
Ren Boting | 3:d119901a65bd | 31 | #if KX224_1053_CONNECTED == 1 |
Ren Boting | 0:a9aeed8cd62e | 32 | #include "KX224.h" |
Ren Boting | 3:d119901a65bd | 33 | #endif |
Ren Boting | 3:d119901a65bd | 34 | #if BH1790GLC_CONNECTED == 1 |
Ren Boting | 0:a9aeed8cd62e | 35 | #include "rohm-bh1790glc-driver/bh1790glc.h" |
Ren Boting | 3:d119901a65bd | 36 | #endif |
Ren Boting | 3:d119901a65bd | 37 | #if RPR_0521RS_CONNECTED == 1 |
Ren Boting | 0:a9aeed8cd62e | 38 | #include "rohm-rpr0521/rohm-rpr0521/rpr0521.h" |
Ren Boting | 0:a9aeed8cd62e | 39 | #include "rohm-rpr0521/rohm-rpr0521/rpr0521_driver.h" |
Ren Boting | 0:a9aeed8cd62e | 40 | #include "rohm-sensor-hal/rohm-sensor-hal/I2CCommon.h" |
Ren Boting | 3:d119901a65bd | 41 | #endif |
Ren Boting | 0:a9aeed8cd62e | 42 | |
Ren Boting | 3:d119901a65bd | 43 | #if BM1383AGLV_CONNECTED == 1 |
Ren Boting | 2:d022d883a31f | 44 | BM1383AGLV bm1383aglv(I2C_SDA, I2C_SCL); |
Ren Boting | 3:d119901a65bd | 45 | #endif |
Ren Boting | 3:d119901a65bd | 46 | #if BM1422AGMV_CONNECTED == 1 |
Ren Boting | 2:d022d883a31f | 47 | BM1422AGMV bm1422agmv(I2C_SDA, I2C_SCL); |
Ren Boting | 3:d119901a65bd | 48 | #endif |
Ren Boting | 3:d119901a65bd | 49 | #if KX224_1053_CONNECTED == 1 |
Ren Boting | 2:d022d883a31f | 50 | KX224 kx224_1053(I2C_SDA, I2C_SCL); |
Ren Boting | 3:d119901a65bd | 51 | #endif |
Ren Boting | 3:d119901a65bd | 52 | #if BH1790GLC_CONNECTED == 1 |
Ren Boting | 0:a9aeed8cd62e | 53 | RegisterWriter i2c_rw_bh(I2C_SDA, I2C_SCL); |
Ren Boting | 2:d022d883a31f | 54 | BH1790GLC bh1790glc(i2c_rw_bh); |
Ren Boting | 3:d119901a65bd | 55 | #endif |
Ren Boting | 3:d119901a65bd | 56 | #if BD1020HFV_CONNECTED == 1 |
Ren Boting | 3:d119901a65bd | 57 | #ifdef TARGET_K66F |
Ren Boting | 3:d119901a65bd | 58 | #warning A2 pin is disabled on THIS BOARD, please use A0 pin!! |
Ren Boting | 3:d119901a65bd | 59 | #endif |
Ren Boting | 3:d119901a65bd | 60 | AnalogIn bd1020hfv(A0); |
Ren Boting | 3:d119901a65bd | 61 | #endif |
Ren Boting | 0:a9aeed8cd62e | 62 | |
Ren Boting | 0:a9aeed8cd62e | 63 | Serial pc(USBTX, USBRX); |
Ren Boting | 0:a9aeed8cd62e | 64 | |
Ren Boting | 0:a9aeed8cd62e | 65 | int main() { |
Ren Boting | 2:d022d883a31f | 66 | float axis_ac[3], temp1_bd1020hfv, temp2_bd1020hfv ; |
Ren Boting | 2:d022d883a31f | 67 | bool err_rpr0521; |
Ren Boting | 2:d022d883a31f | 68 | int err_bh1790, err_KX224; |
Ren Boting | 2:d022d883a31f | 69 | uint16_t bh1790_data[2], rpr0521_data[3]; |
Ren Boting | 0:a9aeed8cd62e | 70 | |
Ren Boting | 0:a9aeed8cd62e | 71 | pc.printf("\r\nExample program for using following Rohm sensor libraries\r\n"); |
Ren Boting | 3:d119901a65bd | 72 | #if BM1383AGLV_CONNECTED == 1 |
Ren Boting | 3:d119901a65bd | 73 | pc.printf("\n - BM1383AGLV: Pressure/Temperature sensor\r\n"); |
Ren Boting | 3:d119901a65bd | 74 | #endif |
Ren Boting | 3:d119901a65bd | 75 | #if BM1422AGMV_CONNECTED == 1 |
Ren Boting | 3:d119901a65bd | 76 | pc.printf("\r - BM1422AGMV: 3 axis magnetic sensor\r\n"); |
Ren Boting | 3:d119901a65bd | 77 | #endif |
Ren Boting | 3:d119901a65bd | 78 | #if KX224_1053_CONNECTED == 1 |
Ren Boting | 3:d119901a65bd | 79 | pc.printf("\r - KX224-1053: 3 axis accelerometer\r\n"); |
Ren Boting | 3:d119901a65bd | 80 | #endif |
Ren Boting | 3:d119901a65bd | 81 | #if BH1790GLC_CONNECTED == 1 |
Ren Boting | 3:d119901a65bd | 82 | pc.printf("\r - BH1790GLC: optical sensor for heart rate monitor\r\n"); |
Ren Boting | 3:d119901a65bd | 83 | #endif |
Ren Boting | 3:d119901a65bd | 84 | #if RPR_0521RS_CONNECTED == 1 |
Ren Boting | 3:d119901a65bd | 85 | pc.printf("\r - RPR-0521RS: Light & Proximity Sensor\r\n"); |
Ren Boting | 3:d119901a65bd | 86 | #endif |
Ren Boting | 3:d119901a65bd | 87 | #if BD1020HFV_CONNECTED == 1 |
Ren Boting | 3:d119901a65bd | 88 | pc.printf("\r - BD1020HFV: Temperature Sensor, Formula values should be calibrated before use.\r\n"); |
Ren Boting | 3:d119901a65bd | 89 | #endif |
Ren Boting | 3:d119901a65bd | 90 | |
Ren Boting | 3:d119901a65bd | 91 | #if KX224_1053_CONNECTED == 1 |
Ren Boting | 0:a9aeed8cd62e | 92 | //init KX224-1053 |
Ren Boting | 2:d022d883a31f | 93 | err_KX224=kx224_1053.initialize(); |
Ren Boting | 0:a9aeed8cd62e | 94 | if (err_KX224!=0){ |
Ren Boting | 3:d119901a65bd | 95 | pc.printf("\r\nkx224_1053 : Failed initialization \n"); |
Ren Boting | 0:a9aeed8cd62e | 96 | } |
Ren Boting | 3:d119901a65bd | 97 | #endif |
Ren Boting | 3:d119901a65bd | 98 | #if BH1790GLC_CONNECTED == 1 |
Ren Boting | 0:a9aeed8cd62e | 99 | do{ //init BH1790GLC |
Ren Boting | 2:d022d883a31f | 100 | err_bh1790 = bh1790glc.set_default_on(); |
Ren Boting | 0:a9aeed8cd62e | 101 | wait_ms(300); |
Ren Boting | 0:a9aeed8cd62e | 102 | } while (err_bh1790); |
Ren Boting | 3:d119901a65bd | 103 | #endif |
Ren Boting | 3:d119901a65bd | 104 | #if RPR_0521RS_CONNECTED == 1 |
Ren Boting | 0:a9aeed8cd62e | 105 | //init RPR-0521RS |
Ren Boting | 0:a9aeed8cd62e | 106 | I2CCommonBegin(); |
Ren Boting | 0:a9aeed8cd62e | 107 | rpr0521_wait_until_found(); |
Ren Boting | 0:a9aeed8cd62e | 108 | pc.printf("\nRPR-0521RS Sensor found.\r\n"); |
Ren Boting | 0:a9aeed8cd62e | 109 | rpr0521_initial_setup(); |
Ren Boting | 3:d119901a65bd | 110 | #endif |
Ren Boting | 0:a9aeed8cd62e | 111 | |
Ren Boting | 0:a9aeed8cd62e | 112 | while(1) { |
Ren Boting | 2:d022d883a31f | 113 | pc.printf("\r++++++++++++++++++\r"); |
Ren Boting | 3:d119901a65bd | 114 | #if BM1383AGLV_CONNECTED == 1 |
Ren Boting | 2:d022d883a31f | 115 | pc.printf("\r\nbm1383aglv : pressure=%7.2f, temperature=%5.3f\r\n", bm1383aglv.getPressure(), bm1383aglv.getTemperature()); |
Ren Boting | 3:d119901a65bd | 116 | #endif |
Ren Boting | 3:d119901a65bd | 117 | #if BM1422AGMV_CONNECTED == 1 |
Ren Boting | 2:d022d883a31f | 118 | memset(&axis_ac[0], 0, sizeof(axis_ac)); |
Ren Boting | 2:d022d883a31f | 119 | bm1422agmv.get_val(&axis_ac[0]); |
Ren Boting | 3:d119901a65bd | 120 | pc.printf("\r\nbm1422agmv : X=%7.2f, Y=%7.2f, Z=%7.2f\r\n", axis_ac[0], axis_ac[1], axis_ac[2]); |
Ren Boting | 3:d119901a65bd | 121 | #endif |
Ren Boting | 3:d119901a65bd | 122 | #if KX224_1053_CONNECTED == 1 |
Ren Boting | 2:d022d883a31f | 123 | memset(&axis_ac[0], 0, sizeof(axis_ac)); |
Ren Boting | 2:d022d883a31f | 124 | kx224_1053.get_val(&axis_ac[0]); |
Ren Boting | 3:d119901a65bd | 125 | 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]); |
Ren Boting | 3:d119901a65bd | 126 | #endif |
Ren Boting | 3:d119901a65bd | 127 | #if BH1790GLC_CONNECTED == 1 |
Ren Boting | 2:d022d883a31f | 128 | memset(&bh1790_data[0], 0, sizeof(bh1790_data)); |
Ren Boting | 2:d022d883a31f | 129 | err_bh1790 = bh1790glc.getresults(&bh1790_data[0]); |
Ren Boting | 2:d022d883a31f | 130 | if(err_bh1790) { |
Ren Boting | 2:d022d883a31f | 131 | pc.printf("\r\nBH1790GLC : Failed reading value from BH1790GLC\r\n"); |
Ren Boting | 2:d022d883a31f | 132 | } else { |
Ren Boting | 2:d022d883a31f | 133 | pc.printf("\r\nBH1790GLC : value= %d, \t%d\n\r", bh1790_data[1], bh1790_data[0]); |
Ren Boting | 2:d022d883a31f | 134 | } |
Ren Boting | 3:d119901a65bd | 135 | #endif |
Ren Boting | 3:d119901a65bd | 136 | #if RPR_0521RS_CONNECTED == 1 |
Ren Boting | 2:d022d883a31f | 137 | memset(&rpr0521_data[0], 0, sizeof(rpr0521_data)); |
Ren Boting | 2:d022d883a31f | 138 | err_rpr0521 = rpr0521_read_data(&rpr0521_data[0]); |
Ren Boting | 2:d022d883a31f | 139 | if(err_rpr0521) { |
Ren Boting | 2:d022d883a31f | 140 | pc.printf("\r\nRPR-0521RS : Failed reading value from RPR-0521RS\r\n"); |
Ren Boting | 2:d022d883a31f | 141 | } else { |
Ren Boting | 2:d022d883a31f | 142 | 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 | 143 | } |
Ren Boting | 3:d119901a65bd | 144 | #endif |
Ren Boting | 3:d119901a65bd | 145 | #if BD1020HFV_CONNECTED == 1 |
Ren Boting | 2:d022d883a31f | 146 | //Input voltage 0-3.3V == 0.0-1.0f |
Ren Boting | 2:d022d883a31f | 147 | //-40'C == 1.87V |
Ren Boting | 2:d022d883a31f | 148 | // 0'C == 1.546V |
Ren Boting | 2:d022d883a31f | 149 | //192'C == 0V (out of scale) |
Ren Boting | 2:d022d883a31f | 150 | //1.87V / 232'C = 0.008060V/'C |
Ren Boting | 2:d022d883a31f | 151 | temp1_bd1020hfv = -(1000 * (bd1020hfv * 3.3f) - 1546) / 8.2; |
Ren Boting | 2:d022d883a31f | 152 | temp2_bd1020hfv = 192 - ( bd1020hfv * 3.3f / 0.008060 ); |
Ren Boting | 2:d022d883a31f | 153 | pc.printf("\r\nBD1020HFV : formula1= %5.3f, formula2= %5.3f\r\n", temp1_bd1020hfv, temp2_bd1020hfv); |
Ren Boting | 3:d119901a65bd | 154 | #endif |
Ren Boting | 2:d022d883a31f | 155 | wait(3); |
Ren Boting | 0:a9aeed8cd62e | 156 | } |
Ren Boting | 0:a9aeed8cd62e | 157 | } |