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
Diff: Source/main.cpp
- Revision:
- 0:a9aeed8cd62e
- Child:
- 2:d022d883a31f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Source/main.cpp Mon Feb 18 15:08:30 2019 +0900 @@ -0,0 +1,126 @@ +/* Rohm SensorShield-EVK-xxx Example + * Copyright (c) 2019 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "BM1383AGLV.h" +#include "BM1422AGMV.h" +#include "KX224.h" +#include "rohm-bh1790glc-driver/bh1790glc.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" + + + +void clearFlo(float * data, int length); +void clearUint(uint16_t * data, int length); +BM1383AGLV _bm1383aglv(I2C_SDA, I2C_SCL); +BM1422AGMV _bm1422agmv(I2C_SDA, I2C_SCL); +KX224 _kx224_1053(I2C_SDA, I2C_SCL); +RegisterWriter i2c_rw_bh(I2C_SDA, I2C_SCL); +BH1790GLC _bh1790glc(i2c_rw_bh); +AnalogIn _bd1020hfv(A2); + +Serial pc(USBTX, USBRX); + +int main() { + float axis_ac[3], temp1_bd1020hfv, temp2_bd1020hfv ; + bool err_rpr0521; + int err_bh1790, err_KX224; + uint16_t _bh1790[2], _rpr0521[3]; + + pc.printf("\r\nExample program for using following Rohm sensor libraries\r\n"); + pc.printf("\n - BM1383AGLV: Pressure/Temperature sensor\n"); + pc.printf("\r - BM1422AGMV: 3 axis magnetic sensor\n"); + pc.printf("\r - KX224-1053: 3 axis accelerometer\n"); + pc.printf("\r - BH1790GLC: optical sensor for heart rate monitor\n"); + pc.printf("\r - RPR-0521RS: Light & Proximity Sensor\n"); + pc.printf("\r - BD1020HFV: Temperature Sensor, Formula values should be calibrated before use.\n"); + //init KX224-1053 + err_KX224=_kx224_1053.initialize(); + if (err_KX224!=0){ + pc.printf("\r\n_kx224_1053 : Failed initialization \r\n"); + } + + do{ //init BH1790GLC + err_bh1790 = _bh1790glc.set_default_on(); + wait_ms(300); + } while (err_bh1790); + + //init RPR-0521RS + I2CCommonBegin(); + rpr0521_wait_until_found(); + pc.printf("\nRPR-0521RS Sensor found.\r\n"); + rpr0521_initial_setup(); + + while(1) { + pc.printf("\r++++++++++++++++++\r"); + pc.printf("\r\n_bm1383aglv : pressure=%7.2f, temperature=%5.3f\r\n", _bm1383aglv.getPressure(), _bm1383aglv.getTemperature()); + clearFlo(&axis_ac[0],3); + _bm1422agmv.get_val(&axis_ac[0]); + pc.printf("\r\n_bm1422agmv : X=%7.2f, Y=%7.2f, Z=%7.2f\n\r", axis_ac[0], axis_ac[1], axis_ac[2]); + clearFlo(&axis_ac[0],3); + _kx224_1053.get_val(&axis_ac[0]); + pc.printf("\r\n_kx224_1053 : X=%7.2f, Y=%7.2f, Z=%7.2f\n\r", axis_ac[0], axis_ac[1], axis_ac[2]); + clearUint(&_bh1790[0], 2); + err_bh1790 = _bh1790glc.getresults(&_bh1790[0]); + if(err_bh1790) { + pc.printf("\r\nBH1790GLC : Failed reading value from BH1790GLC\r\n"); + } else + { + pc.printf("\r\nBH1790GLC : value= %d, \t%d\n\r", _bh1790[1], _bh1790[0]); + } + clearUint(&_rpr0521[0], 3); + err_rpr0521 = rpr0521_read_data(&_rpr0521[0]); + if(err_rpr0521) { + pc.printf("\r\nRPR-0521RS : Failed reading value from RPR-0521RS\r\n"); + } else + { + pc.printf("\r\nRPR-0521RS : PS= %4u, Als0= %4u, Als1= %4u\r\n", _rpr0521[0], _rpr0521[1], _rpr0521[2]); + } + //Input voltage 0-3.3V == 0.0-1.0f + //-40'C == 1.87V + // 0'C == 1.546V + //192'C == 0V (out of scale) + //1.87V / 232'C = 0.008060V/'C + temp1_bd1020hfv = -(1000 * (_bd1020hfv * 3.3f) - 1546) / 8.2; + temp2_bd1020hfv = 192 - ( _bd1020hfv * 3.3f / 0.008060 ); + pc.printf("\r\nBD1020HFV : formula1= %5.3f, formula2= %5.3f\r\n", temp1_bd1020hfv, temp2_bd1020hfv); + wait(3); + } +} + +void clearFlo(float * data, int length) +{ + if(data==NULL) { + pc.printf("\r\nFailed in clearFlo, data ptr is NULL!!\r\n"); + }else + { + for(int i=0; i<length; i++) + *(data+i) = 0.0f; + } +} + +void clearUint(uint16_t * data, int length) +{ + if(data==NULL) { + pc.printf("\r\nFailed in clearUint, data ptr is NULL!!\r\n"); + }else + { + for(int i=0; i<length; i++) + *(data+i) = 0; + } +} +