0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

STM32F767で脈拍センサー,AE-NJL5501Rので脈拍を液晶で表示

Last updated at Posted at 2021-03-12

1.センサーの接続
2.下記のソースコードを書き込む
3.コンパイル実行で表示されたら終了
4.スタートボタンを押す
5.Arduinoプロッターで開く
6.おわり

センサーとアンプがなんだかなぁ
少しでもズレるとサチル
調子のいいときは、約100前後を正しく表示する
120でトリガーを掛けている
表示も高速にしている
今後は、トリガーポイントのオート化

アルゴリズムの説明
トリガーは、立ち上がりで120
ポイント(点)が120を超え1個前のバックアップポイントが120より小さい時に発動する
人間の脈拍は、約1分あたり約100である
1分は、60,000msで100回の幅は、600msである
脈拍 100=60,000ms/600ms
16ビットでも処理出来るように両辺を2で割る
脈拍 100 = 30,000ms / (600ms / 2 )
脈を検出した毎に液晶に脈拍数を表示
0割り算エラー対策になんか適当な値を間隔に入れる

秋月の脈拍センサー,AE-NJL5501Rで脈拍を見る NJL5501R
https://qiita.com/caa45040/items/f3a5674e825c9ac542fb


# include "mbed.h"

# define ADDR_LCD    (0x7C)      //  address

I2C i2c(I2C_SDA, I2C_SCL); //767

AnalogIn adc_vbat(A0);

DigitalOut led(LED1);
DigitalOut led3(LED3);

DigitalIn bu(PC_13);

int time_cou; //タイムカウンター ms


char    data_read[8];   //i2cバッファー

char INIT_com[]={0x0,0x38,
0x0,0x39,
0x0,0x4,
0x0,0x14,
0x0,0x70,
0x0,0x56,
0x0,0x6C,
0x0,0x38,
0x0,0xC,
0x0,0x1,
0x40,0x41,0x99,0x99};

char INIT_cls[]={0x0,0x1};
char INIT_home[]={0x0,0x80};

char ch_hex_a_b[5];
char *ch_hex_a(int l_num)
{
    ch_hex_a_b[0] = '@';
    ch_hex_a_b[1] = '0' + (  l_num / 100);
    ch_hex_a_b[2] = '0' + ( (l_num % 100) / 10 ) ;
    ch_hex_a_b[3] = '0' + (  l_num % 10);
    ch_hex_a_b[4] = 0;
    return(ch_hex_a_b);
}

int ii;     //ループカウンタ


int main()
{
    unsigned short aa,bk,pu;

    unsigned short ha,hb,hc,hd;

    
    while( bu.read() == 0 ) { }
    
    //液晶の初期化
    for(ii=0;ii<11;ii++){
        i2c.write(ADDR_LCD, &INIT_com[ii*2], 2);wait_ms(2);
    } //for
    
    
    while(1) {
    
        //液晶のクリア
        //i2c.write(ADDR_LCD,INIT_cls,2);wait_ms(2);
        i2c.write(ADDR_LCD,INIT_home,2);
        
        aa = (adc_vbat.read_u16()/16);
        
        hd = hc;
        hc = hb;
        hb = ha;
        ha = aa;
        
        aa = ( ha + hb + hc + hd) / 4;
        
        if ( aa <= 1700 ) { aa = 0;} else { aa = aa - 1700; }
        
        aa = aa / 2;
        
        if ( aa >= 255  ) { aa = 255; }
        
        printf("%u\r\n", aa );
        //printf("%d\r\n",bu.read());
        //led = !led;
        if ( aa >= 120 ) {led = 1;} else {led = 0; }
        
        //脈拍を表示する
        if( aa >= 120 && bk < 120 ) {
            //液晶で3桁の値を表示
            if( time_cou <= 250 ) { time_cou = 250; }
            pu = 60000 / ( time_cou / 2 );
            //pu = 333;
            i2c.write(ADDR_LCD, ch_hex_a( (int)pu ) ,4);
             
             
            led3 = !led3;
            time_cou = 0; //カウントを(0)にする
        } //if
        bk = aa;
        
        ////バックアップポイントを{0)にリセット
        //if ( aa < 160 ) { bk = 0; }
        
        wait_ms(10);
        time_cou = time_cou + 10;
        //10秒でリセット
        if (time_cou >= 30000) { time_cou = 0; } 
        
    }
}

pm_an_dd_1.jpg

オートトリガー


# include "mbed.h"

# define ADDR_LCD    (0x7C)      //  address

I2C i2c(I2C_SDA, I2C_SCL); //767

AnalogIn adc_vbat(A0);

DigitalOut led(LED1);
DigitalOut led3(LED3);

DigitalIn bu(PC_13);

int time_cou; //タイムカウンター ms


char    data_read[8];   //i2cバッファー

char INIT_com[]={0x0,0x38,
0x0,0x39,
0x0,0x4,
0x0,0x14,
0x0,0x70,
0x0,0x56,
0x0,0x6C,
0x0,0x38,
0x0,0xC,
0x0,0x1,
0x40,0x41,0x99,0x99};

char INIT_cls[]={0x0,0x1};
char INIT_home[]={0x0,0x80};

char ch_hex_a_b[5];
char *ch_hex_a(int l_num)
{
    ch_hex_a_b[0] = '@';
    ch_hex_a_b[1] = '0' + (  l_num / 100);
    ch_hex_a_b[2] = '0' + ( (l_num % 100) / 10 ) ;
    ch_hex_a_b[3] = '0' + (  l_num % 10);
    ch_hex_a_b[4] = 0;
    return(ch_hex_a_b);
}

int ii;     //ループカウンタ


int main()
{
    unsigned short aa,bk,pu;

    unsigned short ha,hb,hc,hd;

    unsigned short au[101];
    unsigned short au_co;
    
    int hhl; //1秒平均
    
    while( bu.read() == 0 ) { }
    
    //液晶の初期化
    for(ii=0;ii<11;ii++){
        i2c.write(ADDR_LCD, &INIT_com[ii*2], 2);wait_ms(2);
    } //for
    
    au_co = 0;
    au[0] = 120;
    hhl = 120;
    
    while(1) {
    
        //液晶のクリア
        //i2c.write(ADDR_LCD,INIT_cls,2);wait_ms(2);
        i2c.write(ADDR_LCD,INIT_home,2);
        
        aa = (adc_vbat.read_u16()/16);
        
        hd = hc;
        hc = hb;
        hb = ha;
        ha = aa;
        
        aa = ( ha + hb + hc + hd) / 4;
        
        if ( aa <= 1700 ) { aa = 0;} else { aa = aa - 1700; }
        
        aa = aa / 2;
        
        if ( aa >= 255  ) { aa = 255; }
        
        printf("%u\r\n", aa );
        //printf("%d\r\n",bu.read());
        //led = !led;
        if ( aa >= (hhl + 10) ) {led = 1;} else {led = 0; }
        
        //脈拍を表示する
        if( aa >= (hhl + 10) && bk < (hhl + 10) ) {
            //液晶で3桁の値を表示
            if( time_cou <= 250 ) { time_cou = 250; }
            pu = 60000 / ( time_cou / 2 );
            //pu = 333;
            i2c.write(ADDR_LCD, ch_hex_a( (int)pu ) ,4);

            //i2c.write(ADDR_LCD, "@-" ,2);
            //i2c.write(ADDR_LCD, ch_hex_a( (int)hhl ) ,4);
             
             
            led3 = !led3;
            time_cou = 0; //カウントを(0)にする
        } //if
        bk = aa;
        
        au[au_co] = aa;
        au_co = au_co + 1;
        if (au_co >= 100) { au_co = 0;}
        

        for(ii=0;ii<100;ii++){ hhl = hhl + au[ii]; }
        hhl = hhl / 100;
        //i2c.write(ADDR_LCD, "@-" ,2);
        //i2c.write(ADDR_LCD, ch_hex_a( (int)hhl ) ,4);
        
        ////バックアップポイントを{0)にリセット
        //if ( aa < 160 ) { bk = 0; }
        
        wait_ms(10-5);
        time_cou = time_cou + 10;
        //10秒でリセット
        if (time_cou >= 30000) { time_cou = 0; } 
        
    }
}


0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?