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@8:a212185be55a, 2019-02-27 (annotated)
- Committer:
- MACRUM
- Date:
- Wed Feb 27 09:13:51 2019 +0000
- Revision:
- 8:a212185be55a
- Parent:
- 6:b38a0cbc1b3f
Fix return code
Who changed what in which revision?
User | Revision | Line number | New 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" |
MACRUM | 6:b38a0cbc1b3f | 17 | #define BH1790GLC_CONNECTED 0 |
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" |
MACRUM | 6:b38a0cbc1b3f | 22 | #include "BH1749NUC.h" |
Ren Boting | 4:e1f9ba2da8af | 23 | #include "rohm-rpr0521/rohm-rpr0521/rpr0521.h" |
Ren Boting | 4:e1f9ba2da8af | 24 | #include "rohm-rpr0521/rohm-rpr0521/rpr0521_driver.h" |
Ren Boting | 4:e1f9ba2da8af | 25 | #include "rohm-sensor-hal/rohm-sensor-hal/I2CCommon.h" |
MACRUM | 5:f0dac0711070 | 26 | #include "rohm-bh1790glc-driver/bh1790glc.h" |
MACRUM | 5:f0dac0711070 | 27 | |
MACRUM | 5:f0dac0711070 | 28 | BM1383AGLV pressure(I2C_SDA, I2C_SCL); |
MACRUM | 5:f0dac0711070 | 29 | BM1422AGMV magnetometer(I2C_SDA, I2C_SCL); |
MACRUM | 5:f0dac0711070 | 30 | KX224 accelerometer(I2C_SDA, I2C_SCL); |
MACRUM | 6:b38a0cbc1b3f | 31 | BH1749NUC color(I2C_SDA, I2C_SCL); |
Ren Boting | 3:d119901a65bd | 32 | #if BH1790GLC_CONNECTED == 1 |
MACRUM | 5:f0dac0711070 | 33 | RegisterWriter i2c_rw_bh(I2C_SDA, I2C_SCL); |
MACRUM | 5:f0dac0711070 | 34 | BH1790GLC heartrate(i2c_rw_bh); |
Ren Boting | 3:d119901a65bd | 35 | #endif |
Ren Boting | 0:a9aeed8cd62e | 36 | |
Ren Boting | 3:d119901a65bd | 37 | #ifdef TARGET_K66F |
Ren Boting | 4:e1f9ba2da8af | 38 | #warning A2 pin is disabled on THIS BOARD, please use A0 pin for BD1020HFV!! |
Ren Boting | 3:d119901a65bd | 39 | #endif |
MACRUM | 5:f0dac0711070 | 40 | AnalogIn temperature(A0); // BD1020HFV |
Ren Boting | 0:a9aeed8cd62e | 41 | |
Ren Boting | 0:a9aeed8cd62e | 42 | int main() { |
Ren Boting | 2:d022d883a31f | 43 | float axis_ac[3], temp1_bd1020hfv, temp2_bd1020hfv ; |
Ren Boting | 2:d022d883a31f | 44 | bool err_rpr0521; |
MACRUM | 5:f0dac0711070 | 45 | int ret; |
MACRUM | 6:b38a0cbc1b3f | 46 | uint16_t buf[5]; |
Ren Boting | 0:a9aeed8cd62e | 47 | |
MACRUM | 5:f0dac0711070 | 48 | printf("\r\nExample program for using following Rohm sensor libraries\r\n"); |
MACRUM | 5:f0dac0711070 | 49 | printf(" - BM1383AGLV: Pressure/Temperature sensor\r\n"); |
MACRUM | 5:f0dac0711070 | 50 | printf(" - BM1422AGMV: 3 axis magnetic sensor\r\n"); |
MACRUM | 5:f0dac0711070 | 51 | printf(" - KX224-1053: 3 axis accelerometer\r\n"); |
Ren Boting | 3:d119901a65bd | 52 | #if BH1790GLC_CONNECTED == 1 |
MACRUM | 5:f0dac0711070 | 53 | printf(" - BH1790GLC: optical sensor for heart rate monitor\r\n"); |
Ren Boting | 3:d119901a65bd | 54 | #endif |
MACRUM | 5:f0dac0711070 | 55 | printf(" - RPR-0521RS: Light & Proximity Sensor\r\n"); |
MACRUM | 5:f0dac0711070 | 56 | printf(" - BD1020HFV: Temperature Sensor, Formula values should be calibrated before use.\r\n"); |
MACRUM | 6:b38a0cbc1b3f | 57 | printf(" - BH1749NUC: Color Sensor\r\n"); |
Ren Boting | 3:d119901a65bd | 58 | |
MACRUM | 6:b38a0cbc1b3f | 59 | // Initialize KX224-1053 |
MACRUM | 5:f0dac0711070 | 60 | ret = accelerometer.initialize(); |
MACRUM | 5:f0dac0711070 | 61 | if (ret != 0) { |
MACRUM | 5:f0dac0711070 | 62 | printf("\r\nKX224-1053 : Failed initialization \n"); |
Ren Boting | 0:a9aeed8cd62e | 63 | } |
Ren Boting | 4:e1f9ba2da8af | 64 | |
Ren Boting | 3:d119901a65bd | 65 | #if BH1790GLC_CONNECTED == 1 |
MACRUM | 6:b38a0cbc1b3f | 66 | // Initialize BH1790GLC |
MACRUM | 6:b38a0cbc1b3f | 67 | do { |
MACRUM | 5:f0dac0711070 | 68 | ret = heartrate.set_default_on(); |
Ren Boting | 0:a9aeed8cd62e | 69 | wait_ms(300); |
MACRUM | 5:f0dac0711070 | 70 | } while (ret); |
Ren Boting | 3:d119901a65bd | 71 | #endif |
Ren Boting | 4:e1f9ba2da8af | 72 | |
MACRUM | 6:b38a0cbc1b3f | 73 | // Initialize RPR-0521RS |
Ren Boting | 0:a9aeed8cd62e | 74 | I2CCommonBegin(); |
Ren Boting | 0:a9aeed8cd62e | 75 | rpr0521_wait_until_found(); |
MACRUM | 5:f0dac0711070 | 76 | printf("\nRPR-0521RS Sensor found.\r\n"); |
Ren Boting | 0:a9aeed8cd62e | 77 | rpr0521_initial_setup(); |
Ren Boting | 0:a9aeed8cd62e | 78 | |
MACRUM | 6:b38a0cbc1b3f | 79 | // Initialize BH1749NUC |
MACRUM | 6:b38a0cbc1b3f | 80 | ret = color.init(); |
MACRUM | 6:b38a0cbc1b3f | 81 | if (ret != 0) { |
MACRUM | 6:b38a0cbc1b3f | 82 | printf("\r\nBH1749NUC : Failed initialization \n"); |
MACRUM | 6:b38a0cbc1b3f | 83 | } |
MACRUM | 6:b38a0cbc1b3f | 84 | |
MACRUM | 5:f0dac0711070 | 85 | while (1) { |
MACRUM | 8:a212185be55a | 86 | printf("\n++++++++++++++++++\n"); |
MACRUM | 5:f0dac0711070 | 87 | printf("BM1383AGLV : pressure=%7.2f, temperature=%5.3f\r\n", pressure.getPressure(), pressure.getTemperature()); |
MACRUM | 5:f0dac0711070 | 88 | magnetometer.get_val(&axis_ac[0]); |
MACRUM | 5:f0dac0711070 | 89 | 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 | 90 | accelerometer.get_val(&axis_ac[0]); |
MACRUM | 5:f0dac0711070 | 91 | 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 | 92 | |
Ren Boting | 3:d119901a65bd | 93 | #if BH1790GLC_CONNECTED == 1 |
MACRUM | 6:b38a0cbc1b3f | 94 | ret = heartrate.getresults(buf); |
MACRUM | 5:f0dac0711070 | 95 | if (ret) { |
MACRUM | 5:f0dac0711070 | 96 | printf("BH1790GLC : Failed reading value from BH1790GLC\r\n"); |
Ren Boting | 2:d022d883a31f | 97 | } else { |
MACRUM | 6:b38a0cbc1b3f | 98 | printf("BH1790GLC : value= %d, \t%d\n\r", buf[1], buf[0]); |
Ren Boting | 2:d022d883a31f | 99 | } |
Ren Boting | 3:d119901a65bd | 100 | #endif |
Ren Boting | 4:e1f9ba2da8af | 101 | |
MACRUM | 6:b38a0cbc1b3f | 102 | err_rpr0521 = rpr0521_read_data(buf); |
MACRUM | 5:f0dac0711070 | 103 | if (err_rpr0521) { |
MACRUM | 5:f0dac0711070 | 104 | printf("RPR-0521RS : Failed reading value from RPR-0521RS\r\n"); |
Ren Boting | 2:d022d883a31f | 105 | } else { |
MACRUM | 6:b38a0cbc1b3f | 106 | printf("RPR-0521RS : PS= %4u, Als0= %4u, Als1= %4u\r\n", buf[0], buf[1], buf[2]); |
Ren Boting | 2:d022d883a31f | 107 | } |
Ren Boting | 4:e1f9ba2da8af | 108 | |
MACRUM | 5:f0dac0711070 | 109 | // Input voltage 0-3.3V == 0.0-1.0f |
MACRUM | 5:f0dac0711070 | 110 | // -40'C == 1.87V |
MACRUM | 5:f0dac0711070 | 111 | // 0'C == 1.546V |
MACRUM | 5:f0dac0711070 | 112 | // 192'C == 0V (out of scale) |
MACRUM | 5:f0dac0711070 | 113 | // 1.87V / 232'C = 0.008060V/'C |
MACRUM | 6:b38a0cbc1b3f | 114 | temp1_bd1020hfv = -(1000 * (temperature * 3.3f) - 1546) / 8.2f; |
MACRUM | 6:b38a0cbc1b3f | 115 | temp2_bd1020hfv = 192 - ( temperature * 3.3f / 0.008060f ); |
MACRUM | 5:f0dac0711070 | 116 | printf("BD1020HFV : formula1= %5.3f, formula2= %5.3f\r\n", temp1_bd1020hfv, temp2_bd1020hfv); |
MACRUM | 6:b38a0cbc1b3f | 117 | |
MACRUM | 6:b38a0cbc1b3f | 118 | color.get_val(buf); |
MACRUM | 6:b38a0cbc1b3f | 119 | printf("BH1749NUC : [R] %04x, [G] %04x, [B] %04x, [IR] %04x, [G2] %04x\n", buf[0], buf[1], buf[2], buf[3], buf[4]); |
MACRUM | 6:b38a0cbc1b3f | 120 | |
Ren Boting | 2:d022d883a31f | 121 | wait(3); |
Ren Boting | 0:a9aeed8cd62e | 122 | } |
Ren Boting | 0:a9aeed8cd62e | 123 | } |