Rohm optical pulse wave sensor bh1790glc hello world. Printing values of wave to serial.

Dependencies:   RegisterWriter rohm-bh1790glc-driver

Fork of kionix-kx123-hello by Rohm

Committer:
MikkoZ
Date:
Wed Nov 29 11:45:27 2017 +0000
Revision:
4:50eff3af63c7
Parent:
3:76f82d0d3c8a
Changed data output print to tabbed + pulse graph; ; You can read the pulse from pulse graph if you train your eye a little bit and have good contact with the sensor.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MikkoZ 3:76f82d0d3c8a 1 /*
MikkoZ 3:76f82d0d3c8a 2 The MIT License (MIT)
MikkoZ 3:76f82d0d3c8a 3 Copyright (c) 2017 Rohm Semiconductor
MikkoZ 0:bb054fb43c57 4
MikkoZ 3:76f82d0d3c8a 5 Permission is hereby granted, free of charge, to any person obtaining a
MikkoZ 3:76f82d0d3c8a 6 copy of this software and associated documentation files (the
MikkoZ 3:76f82d0d3c8a 7 "Software"), to deal in the Software without restriction, including
MikkoZ 3:76f82d0d3c8a 8 without limitation the rights to use, copy, modify, merge, publish,
MikkoZ 3:76f82d0d3c8a 9 distribute, sublicense, and/or sell copies of the Software, and to
MikkoZ 3:76f82d0d3c8a 10 permit persons to whom the Software is furnished to do so, subject to
MikkoZ 3:76f82d0d3c8a 11 the following conditions:
MikkoZ 0:bb054fb43c57 12
MikkoZ 3:76f82d0d3c8a 13 The above copyright notice and this permission notice shall be included
MikkoZ 3:76f82d0d3c8a 14 in all copies or substantial portions of the Software.
MikkoZ 3:76f82d0d3c8a 15
MikkoZ 3:76f82d0d3c8a 16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
MikkoZ 3:76f82d0d3c8a 17 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MikkoZ 3:76f82d0d3c8a 18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
MikkoZ 3:76f82d0d3c8a 19 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
MikkoZ 3:76f82d0d3c8a 20 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
MikkoZ 3:76f82d0d3c8a 21 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
MikkoZ 3:76f82d0d3c8a 22 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
MikkoZ 0:bb054fb43c57 23 */
MikkoZ 0:bb054fb43c57 24
MikkoZ 0:bb054fb43c57 25 #include "RegisterWriter/RegisterWriter/rohm_hal2.h"
MikkoZ 0:bb054fb43c57 26
MikkoZ 3:76f82d0d3c8a 27 #include "rohm-bh1790glc-driver/bh1790glc_registers.h"
MikkoZ 3:76f82d0d3c8a 28 #include "rohm-bh1790glc-driver/bh1790glc.h"
MikkoZ 0:bb054fb43c57 29
MikkoZ 0:bb054fb43c57 30 DigitalOut led1(LED1);
MikkoZ 0:bb054fb43c57 31 Serial pc(USBTX, USBRX);
MikkoZ 0:bb054fb43c57 32
MikkoZ 0:bb054fb43c57 33 I2C i2c(I2C_SDA, I2C_SCL);
MikkoZ 0:bb054fb43c57 34 RegisterWriter i2c_rw(i2c);
MikkoZ 3:76f82d0d3c8a 35 BH1790GLC bh1790glc(i2c_rw);
MikkoZ 0:bb054fb43c57 36
MikkoZ 3:76f82d0d3c8a 37 /* Global variables for timer */
MikkoZ 3:76f82d0d3c8a 38 bool interval_elapsed;
MikkoZ 3:76f82d0d3c8a 39 Ticker ticker;
MikkoZ 3:76f82d0d3c8a 40
MikkoZ 3:76f82d0d3c8a 41 void timer_isr()
MikkoZ 3:76f82d0d3c8a 42 {
MikkoZ 3:76f82d0d3c8a 43 interval_elapsed = true;
MikkoZ 3:76f82d0d3c8a 44 }
MikkoZ 0:bb054fb43c57 45
MikkoZ 3:76f82d0d3c8a 46 int main()
MikkoZ 3:76f82d0d3c8a 47 {
MikkoZ 3:76f82d0d3c8a 48 uint16_t data[2];
MikkoZ 3:76f82d0d3c8a 49 int error;
MikkoZ 0:bb054fb43c57 50
MikkoZ 3:76f82d0d3c8a 51 pc.baud(115200);
MikkoZ 3:76f82d0d3c8a 52 i2c.frequency(400000);
MikkoZ 3:76f82d0d3c8a 53
MikkoZ 3:76f82d0d3c8a 54 wait(0.1);
MikkoZ 3:76f82d0d3c8a 55
MikkoZ 3:76f82d0d3c8a 56 do{ //until init OK.
MikkoZ 3:76f82d0d3c8a 57 error = bh1790glc.set_default_on();
MikkoZ 0:bb054fb43c57 58 Thread::wait(50);
MikkoZ 0:bb054fb43c57 59 led1 = !led1; //Red led toggle
MikkoZ 0:bb054fb43c57 60 Thread::wait(200);
MikkoZ 0:bb054fb43c57 61 }
MikkoZ 0:bb054fb43c57 62 while (error);
MikkoZ 0:bb054fb43c57 63 led1 = 0; //Red off
MikkoZ 0:bb054fb43c57 64
MikkoZ 3:76f82d0d3c8a 65 interval_elapsed = false;
MikkoZ 3:76f82d0d3c8a 66 ticker.attach(&timer_isr, 0.03125); //32Hz
MikkoZ 0:bb054fb43c57 67
MikkoZ 3:76f82d0d3c8a 68 while(true) {
MikkoZ 3:76f82d0d3c8a 69 if (interval_elapsed) { //Wait until ISR
MikkoZ 3:76f82d0d3c8a 70 error = bh1790glc.getresults(data);
MikkoZ 3:76f82d0d3c8a 71 if (!error) {
MikkoZ 4:50eff3af63c7 72 int i;
MikkoZ 4:50eff3af63c7 73 pc.printf("%d, \t%d", data[1], data[0]);
MikkoZ 4:50eff3af63c7 74 for (i=0; i < (data[1]/200); i++) {
MikkoZ 4:50eff3af63c7 75 pc.printf(" ");
MikkoZ 4:50eff3af63c7 76 }
MikkoZ 4:50eff3af63c7 77 pc.printf("I\r\n");
MikkoZ 0:bb054fb43c57 78 }
MikkoZ 3:76f82d0d3c8a 79 interval_elapsed = false;
MikkoZ 3:76f82d0d3c8a 80 }
MikkoZ 3:76f82d0d3c8a 81 }
MikkoZ 3:76f82d0d3c8a 82 } /* main() */
MikkoZ 0:bb054fb43c57 83