MICRADAR R60ABD1をM5StackCore2 AWS Editionで動かす。

# 注意
本製品は技適がありません。自己責任でお願いします。

# はじめに
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/97061/928cc4da-ae6f-f420-c285-4fa409ad4e27.png)

M5 Japan Tour 2024 Autumn 東京 で　持ってこられていた60GHz 心拍、呼吸センサーに興味があったので購入して動作確認しました。

https://www.micradar.net/manufacturer/60g-sleep-monitoring-radar-module-r60abd1/

これどう見ても、Seeedの製品と瓜二つです。そこでSeeedのライブラリを使ったところ動きました。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/97061/9f822b54-1502-242d-5a1b-7b0540a46eba.png)

https://www.seeedstudio.com/60GHz-mmWave-Radar-Sensor-Breathing-and-Heartbeat-Module-p-5305.html

# 使い方
これはVccが５Vで、データが3.3VなのでM5StackのGroveで対応可能です。ただし通信がUARTなのでM5Stackでいう所の青Grove端子が良さそうです。そこで青端子を備えているM5Stack Core2 AWS Editionで操作確認をしました。

## 接続方法
接続方法は、マニュアル通りでした。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/97061/84ce378b-c075-6eb8-f13a-2454bfcc9881.png)
端子は2mmピッチのコネクタです。(多分これです。間違っていたらごめんなさい。実際はお店で現物見て買ったので。。。）
https://www.sengoku.co.jp/mod/sgk_cart/detail.php?code=2AMN-DPGB
https://www.sengoku.co.jp/mod/sgk_cart/detail.php?code=6AMN-EPGC
はじめてつかうコネクタだったので圧着を試行錯誤しました。（結局は接続部分、引っ掛かり部分（ここを間違て配線の圧着部分と思って潰してしまって、試行錯誤しました）、線圧着部分、被覆圧着部分でした）

|Pin|M5Stack Core2 AWS(Port C)|M5StackGroveの線の色|MicRadar|
|:-:|:-:|:-:|:-:|
| 1 |RXD2|白|TX|
| 2 |TXD2|黄|RX|
| 3 |VCC|赤|5V|
| 4 |GND|黒|GND|

Seeed社のGroveケーブルは白と黄が逆です。

# スケッチ
https://wiki.seeedstudio.com/Radar_MR60BHA1/ のデモをM5StackCore2AWS用にしたものです。
ライブラリが必要です。
https://github.com/limengdu/Seeed-Studio-MR60BHA1-Sensor
(M5StackCore2のライブラリは省略）

※書き込みだけでは動きださないこともありました。電源（TypeCコネクタ）を抜き差ししてみてください。

## Demo1 Raw data export
```
#include <M5Core2.h>
#include <60ghzbreathheart.h>

BreathHeart_60GHz radar = BreathHeart_60GHz(&Serial2);
void setup() {
  M5.begin();
  Serial2.begin(115200, SERIAL_8N1, 13, 14);
}

void loop() {
  radar.recvRadarBytes();
  radar.showData();
  delay(200);
}
```
## Demo2: Use of human presence detection function
```
#include <M5Core2.h>
#include <60ghzbreathheart.h>

BreathHeart_60GHz radar = BreathHeart_60GHz(&Serial2);
void setup() {
  M5.begin();
  Serial2.begin(115200, SERIAL_8N1, 13, 14);
}

void loop() {
  radar.HumanExis_Func();
  if (radar.sensor_report != 0x00) {
    switch (radar.sensor_report) {
      case NOONE:
        Serial.println("Nobody here.");
        Serial.println("----------------------------");
        break;
      case SOMEONE:
        Serial.println("Someone is here.");
        Serial.println("----------------------------");
        break;
      case NONEPSE:
        Serial.println("No human activity messages.");
        Serial.println("----------------------------");
        break;
      case STATION:
        Serial.println("Someone stop");
        Serial.println("----------------------------");
        break;
      case MOVE:
        Serial.println("Someone moving");
        Serial.println("----------------------------");
        break;
      case BODYVAL:
        Serial.print("The parameters of human body signs are: ");
        Serial.println(radar.bodysign_val, DEC);
        Serial.println("----------------------------");
        break;
      case DISVAL:
        Serial.print("The sensor judges the distance to the human body to be: ");
        Serial.print(radar.distance, DEC);
        Serial.println(" m");
        Serial.println("----------------------------");
        break;
      case DIREVAL:
        Serial.print("The sensor judges the orientation data with the human body as -- x: ");
        Serial.print(radar.Dir_x);
        Serial.print(" m, y: ");
        Serial.print(radar.Dir_y);
        Serial.print(" m, z: ");
        Serial.print(radar.Dir_z);
        Serial.println(" m");
        Serial.println("----------------------------");
        break;
    }
  }
  delay(200);
}
```
## Demo3: The use of respiratory and heartbeat functions in the resting people
検出できないと何も表示されません。50cm程度離してみてください。
```
#include <M5Core2.h>
#include <60ghzbreathheart.h>

BreathHeart_60GHz radar = BreathHeart_60GHz(&Serial2);
void setup() {
  M5.begin();
  Serial2.begin(115200, SERIAL_8N1, 13, 14);
}

void loop() {
  radar.Breath_Heart();
  if (radar.sensor_report != 0x00) {
    switch (radar.sensor_report) {
      case HEARTRATEVAL:
        Serial.print("Sensor monitored the current heart rate value is: ");
        Serial.println(radar.heart_rate, DEC);
        Serial.println("----------------------------");
        break;
      case HEARTRATEWAVE:  //Valid only when real-time data transfer mode is on
        Serial.print("The heart rate waveform(Sine wave) -- point 1: ");
        Serial.print(radar.heart_point_1);
        Serial.print(", point 2 : ");
        Serial.print(radar.heart_point_2);
        Serial.print(", point 3 : ");
        Serial.print(radar.heart_point_3);
        Serial.print(", point 4 : ");
        Serial.print(radar.heart_point_4);
        Serial.print(", point 5 : ");
        Serial.println(radar.heart_point_5);
        Serial.println("----------------------------");
        break;
      case BREATHNOR:
        Serial.println("Sensor detects current breath rate is normal.");
        Serial.println("----------------------------");
        break;
      case BREATHRAPID:
        Serial.println("Sensor detects current breath rate is too fast.");
        Serial.println("----------------------------");
        break;
      case BREATHSLOW:
        Serial.println("Sensor detects current breath rate is too slow.");
        Serial.println("----------------------------");
        break;
      case BREATHNONE:
        Serial.println("There is no breathing information yet, please wait...");
        Serial.println("----------------------------");
        break;
      case BREATHVAL:
        Serial.print("Sensor monitored the current breath rate value is: ");
        Serial.println(radar.breath_rate, DEC);
        Serial.println("----------------------------");
        break;
      case BREATHWAVE:  //Valid only when real-time data transfer mode is on
        Serial.print("The breath rate waveform(Sine wave) -- point 1: ");
        Serial.print(radar.breath_point_1);
        Serial.print(", point 2 : ");
        Serial.print(radar.breath_point_2);
        Serial.print(", point 3 : ");
        Serial.print(radar.breath_point_3);
        Serial.print(", point 4 : ");
        Serial.print(radar.breath_point_4);
        Serial.print(", point 5 : ");
        Serial.println(radar.breath_point_5);
        Serial.println("----------------------------");
        break;
    }
  }
  delay(200);
}
```
## Demo4: Use of the sleep function
動作確認できていません。(環境が作れなかった）

```
#include <M5Core2.h>
#include <60ghzbreathheart.h>

BreathHeart_60GHz radar = BreathHeart_60GHz(&Serial2);
void setup() {
  M5.begin();
  Serial2.begin(115200, SERIAL_8N1, 13, 14);
}

void loop() {
  radar.SleepInf_Decode();
  if (radar.sensor_report != 0x00) {
    switch (radar.sensor_report) {
      case OUTBED:
        Serial.println("Sensor detects someone currently leaving the bed.");
        Serial.println("----------------------------");
        break;
      case INBED:
        Serial.println("Sensor detects that someone is currently in bed.");
        Serial.println("----------------------------");
        break;
      case NOINOUT:
        Serial.println("No subject is detected leaving or going to bed.");
        Serial.println("----------------------------");
        break;
      case SLEEPAWAKE:
        Serial.println("Sensor detects that the monitoring people is awake.");
        Serial.println("----------------------------");
        break;
      case SLEEPLIGHT:
        Serial.println("Sensor detects that the monitoring people is in light sleeping.");
        Serial.println("----------------------------");
        break;
      case SLEEPDEEP:
        Serial.println("Sensor detects that the monitoring people is in deep sleeping.");
        Serial.println("----------------------------");
        break;
      case SLEEPNONE:
        Serial.println("Sleep state of the object is not detected.");
        Serial.println("----------------------------");
        break;
      case AWAKETIME:
        Serial.print("Sensor monitored the awake sleep time is: ");
        Serial.print(radar.awake_time);
        Serial.println(" min");
        Serial.println("----------------------------");
        break;
      case LIGHTTIME:
        Serial.print("Sensor monitored the light sleep time is: ");
        Serial.print(radar.light_time);
        Serial.println(" min");
        Serial.println("----------------------------");
        break;
      case DEEPTIME:
        Serial.print("Sensor monitored the deep sleep time is: ");
        Serial.print(radar.deep_time);
        Serial.println(" min");
        Serial.println("----------------------------");
        break;
      case SLEEPSCORE:
        Serial.print("Sensor judgment sleep score is: ");
        Serial.println(radar.sleep_score);
        Serial.println("----------------------------");
        break;
      case SLEEPSTATUE:
        Serial.println("Sleep integrated state information -- ");
        Serial.print("Human existence: ");
        if (radar.existence) Serial.println("human exis");
        else Serial.println("human non-existent");
        Serial.print("Sleep state: ");
        if (radar.sleep_status == SLEEPDEEP) Serial.println("sleeping soundly");
        else if (radar.sleep_status == SLEEPLIGHT) Serial.println("light sleep");
        else if (radar.sleep_status == SLEEPAWAKE) Serial.println("awake");
        else if (radar.sleep_status == SLEEPNONE) Serial.println("off the bed");
        Serial.print("Average breathing: ");
        Serial.println(radar.breath_rate);
        Serial.print("Average heart rate: ");
        Serial.println(radar.heart_rate);
        Serial.print("Number of turning over during sleep: ");
        Serial.println(radar.turn_num);
        Serial.print("Percentage of substantial exercise during sleep: ");
        Serial.println(radar.substantial_move_ratio);
        Serial.print("Percentage of small-amplitude movements during sleep: ");
        Serial.println(radar.samll_move_ratio);
        Serial.print("Number of apnea: ");
        Serial.println(radar.apnea_num);
        Serial.println("----------------------------");
        break;
      case SLEEPQUALITY:
        Serial.println("Quality of sleep information -- ");
        Serial.print("Sleep score: ");
        Serial.println(radar.sleep_score);
        Serial.print("Total time of sleep: ");
        Serial.print(radar.sleep_time);
        Serial.println(" min");
        Serial.print("Percentage of waking time: ");
        Serial.println(radar.awake_time_radio);
        Serial.print("Percentage of light sleep time: ");
        Serial.println(radar.light_time_radio);
        Serial.print("Percentage of deep sleep time: ");
        Serial.println(radar.deep_time_radio);
        Serial.print("Total time away from bed: ");
        Serial.print(radar.outbed_time);
        Serial.println(" min");
        Serial.print("Total number of times out of bed: ");
        Serial.println(radar.outbed_num);
        Serial.print("The number of turning over during sleep: ");
        Serial.println(radar.turn_num);
        Serial.print("Average breathing: ");
        Serial.println(radar.breath_rate);
        Serial.print("Average heart rate: ");
        Serial.println(radar.heart_rate);
        Serial.print("Number of apnea: ");
        Serial.println(radar.apnea_num);
        Serial.println("----------------------------");
        break;
      case SLEEPLESS4H:
        Serial.print("The monitored subjects slept for less than 4 hours.");
        Serial.println("----------------------------");
        break;
      case SLEEPOVER12H:
        Serial.print("The length of sleep of the monitored subjects exceeded 12 hours.");
        Serial.println("----------------------------");
        break;
      case LONGTIMENOONE:
        Serial.print("Abnormally unoccupied for long periods of time.");
        Serial.println("----------------------------");
        break;
      case ERRORNONE:
        Serial.print("No abnormal information.");
        Serial.println("----------------------------");
        break;
    }
  }
  delay(200);
}
```

# おわりに
Seeedの他のセンサーはどうかな。　気になっています。

https://www.seeedstudio.com/MR60BHA2-60GHz-mmWave-Sensor-Breathing-and-Heartbeat-Module-p-5945.html