Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: CI

on:
push:
branches: [main, 'release/**', v2-dev]
pull_request:
branches: [main, 'release/**', v2-dev]

jobs:
host-tests:
name: Host unit tests (FrameCodec)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install PlatformIO
run: python -m pip install --upgrade platformio
- name: Run native tests
run: pio test -e native

arduino-lint:
name: arduino-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: arduino/arduino-lint-action@v2
with:
compliance: specification
library-manager: submit
project-type: library

compile-examples:
name: Compile examples on XIAO ESP32-C6
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: arduino/compile-sketches@v1
with:
fqbn: esp32:esp32:XIAO_ESP32C6
platforms: |
- name: esp32:esp32
source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
libraries: |
- source-path: ./
- name: Adafruit NeoPixel
- name: hp_BH1750
- name: U8g2
sketch-paths: |
- examples/mmwaveBreath
- examples/PeopleCounting_demo
- examples/ReadByte
- examples/passthrough_mode
- examples/ReadLuxValue
- examples/LightRGB
- examples/Grove_U8x8
- examples/breath_demo
- examples/fall_demo
cli-compile-flags: |
- --warnings=default
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.vscode
archieve
debug*
debug*
.pio/
.pio*
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Seeed Arduino mmWave Library For XIAO

> **Status (2026-04-19):** `main` is still the shipped **v1.0.0**. Two newer
> versions are staged as GitHub prereleases and **have not yet been validated
> on real hardware** — do not rely on them in production yet.
> **Status (2026-10-15):** `main` ships **v1.0.1** (UART assembler, presence
> getter, and host CI). Two newer versions are staged as GitHub prereleases
> and **have not yet been validated on real hardware**.
>
> - [**v1.1.0-rc1**](https://github.com/Love4yzp/Seeed-mmWave-library/releases/tag/v1.1.0-rc1)
> (branch `release/1.1.0-rc`) — housekeeping only: example reorg,
Expand All @@ -22,6 +22,12 @@
> [`ROADMAP.md`](https://github.com/Love4yzp/Seeed-mmWave-library/blob/v2-dev/ROADMAP.md)
> on the `v2-dev` branch.

The 1.0.1 UART receiver checks `HEAD_CKSUM` as soon as eight bytes arrive,
re-locks onto the next `0x01` after a bad header, and applies completed
vital-sign frames when people-counting reports fill the queue.
`isHumanDetected()` returns the last reported presence. Call
`SeeedmmWave::resync()` after a noisy power-on to restart frame lock.

## Introduction

This Library is designed to interface with the Seeed Studio XIAO ESP32-C6 Board integrated on the [MR60BHA2-XIAO 60GHz mmWave Human Breathing and Heartbeat Sensor](https://www.seeedstudio.com/MR60BHA2-60GHz-mmWave-Sensor-Breathing-and-Heartbeat-Module-p-5945.html) and [MR60FDA2-XIAO 60GHz mmWave Human Fall Detection Sensor](https://www.seeedstudio.com/MR60FDA2-60GHz-mmWave-Sensor-Fall-Detection-Module-p-5946.html) sensors. This library enables easy data reading and additional operations for functionalities such as breathing and heartbeat monitoring, and fall detection.
Expand Down Expand Up @@ -65,6 +71,12 @@ To begin using the library, include it in your Arduino sketch and refer to the e

Please refer to the comments in the source code for detailed information on the available methods and parameters.

Host-side protocol tests (no hardware) live under `test/test_framecodec/` and run with:

```
pio test -e native
```

## License

This library is released under the [MIT License](https://github.com/love4yzp/Seeed-mmWave-library/blob/main/LICENSE).
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Seeed Arduino mmWave",
"keywords": "arduino, seeedstudio, mmwave, sensor, breathing, heartbeat, fall detection",
"version": "1.0.0",
"version": "1.0.1",
"description": "Arduino library for XIAO to interact with Seeed mmWave modules for breathing, heartbeat, and fall detection.",
"author": "Seeed Studio",
"maintainers": [
Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name=Seeed Arduino mmWave
version=1.0.0
version=1.0.1
author=Seeed Studio
maintainer=Seeed Studio <maker@seeed.cc>
sentence=Arduino library for XIAO to interact with Seeed mmWave modules for breathing, heartbeat, and fall detection.
paragraph=This library provides easy-to-use interfaces for Seeed XIAO to interact with Seeeds 60GHz mmWave sensors, including MR60BHA2 (breathing and heartbeat) and MR60FDA2 (fall detection). It simplifies the process of data acquisition and sensor integration.
category=Sensors
url=https://github.com/Love4yzp/seeed-mmWave-library
architectures=*
depends=Adafruit NeoPixel, hp_BH1750,
depends=Adafruit NeoPixel, hp_BH1750
includes=Seeed_Arduino_mmWave.h
15 changes: 15 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; PlatformIO project configuration for developing Seeed Arduino mmWave.
;
; [env:native] host-side unit tests for FrameCodec / FrameAssembler.

[platformio]
default_envs = native

[env:native]
platform = native
test_framework = unity
test_build_src = yes
build_src_filter = -<*> +<FrameCodec.cpp> +<FrameAssembler.cpp>
build_flags =
-std=gnu++17
-Isrc
129 changes: 129 additions & 0 deletions src/FrameAssembler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/**
* @file FrameAssembler.cpp
* @copyright © 2024, Seeed Studio
*/

#include "FrameAssembler.h"

#include <cstddef>

namespace seeed {
namespace mmwave {

namespace {
constexpr size_t kIdxLenHi = 3;
constexpr size_t kIdxLenLo = 4;
constexpr size_t kIdxHeadCksum = 7;
} // namespace

FrameAssembler::FeedResult FrameAssembler::feed(uint8_t byte) {
if (ready_) {
buf_.clear();
ready_ = false;
in_frame_ = false;
}

if (!in_frame_) {
if (byte != FrameCodec::kSofByte) {
return FeedResult::NeedMore;
}
buf_.clear();
buf_.push_back(byte);
in_frame_ = true;
return FeedResult::NeedMore;
}

buf_.push_back(byte);
return evaluate();
}

size_t FrameAssembler::feedBuffer(const uint8_t* data, size_t len,
std::vector<std::vector<uint8_t>>& out) {
size_t count = 0;
for (size_t i = 0; i < len; ++i) {
if (feed(data[i]) == FeedResult::FrameReady) {
out.push_back(takeFrame());
++count;
}
}
return count;
}

std::vector<uint8_t> FrameAssembler::takeFrame() {
std::vector<uint8_t> out;
out.swap(buf_);
ready_ = false;
in_frame_ = false;
return out;
}

void FrameAssembler::reset() {
buf_.clear();
in_frame_ = false;
ready_ = false;
}

FrameAssembler::FeedResult FrameAssembler::evaluate() {
bool resynced = false;

while (true) {
if (buf_.empty()) {
in_frame_ = false;
ready_ = false;
return resynced ? FeedResult::Resynced : FeedResult::NeedMore;
}

if (buf_[0] != FrameCodec::kSofByte) {
size_t sof = 1;
while (sof < buf_.size() && buf_[sof] != FrameCodec::kSofByte) {
++sof;
}
if (sof >= buf_.size()) {
buf_.clear();
in_frame_ = false;
ready_ = false;
return FeedResult::Resynced;
}
buf_.erase(buf_.begin(), buf_.begin() + static_cast<std::ptrdiff_t>(sof));
resynced = true;
in_frame_ = true;
continue;
}

if (buf_.size() < FrameCodec::kHeaderSize) {
in_frame_ = true;
return resynced ? FeedResult::Resynced : FeedResult::NeedMore;
}

const uint16_t data_len = static_cast<uint16_t>(
(static_cast<uint16_t>(buf_[kIdxLenHi]) << 8) | buf_[kIdxLenLo]);
const bool header_ok =
(data_len <= FrameCodec::kMaxDataLen) &&
(FrameCodec::checksum(buf_.data(), FrameCodec::kHeaderSize - 1) ==
buf_[kIdxHeadCksum]);

if (!header_ok) {
buf_.erase(buf_.begin());
resynced = true;
continue;
}

const size_t expected =
FrameCodec::kHeaderSize + data_len + FrameCodec::kDataChecksum;
if (buf_.size() < expected) {
in_frame_ = true;
return resynced ? FeedResult::Resynced : FeedResult::NeedMore;
}

if (buf_.size() > expected) {
buf_.resize(expected);
}

ready_ = true;
in_frame_ = false;
return FeedResult::FrameReady;
}
}

} // namespace mmwave
} // namespace seeed
79 changes: 79 additions & 0 deletions src/FrameAssembler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* @file FrameAssembler.h
* @brief Streaming UART assembler with header-checksum resync.
*
* Locks onto SOF=0x01, checks HEAD_CKSUM as soon as 8 bytes are present, and
* searches the leftover bytes for the next SOF when the header is invalid.
* This recovers from boot-time UART noise without waiting on a forged LEN.
*
* 流式组帧:满 8 字节就校验帧头,失败则在剩余字节里重新找 SOF。
*
* @copyright © 2024, Seeed Studio
*/

#ifndef SEEED_ARDUINO_MMWAVE_FRAME_ASSEMBLER_H
#define SEEED_ARDUINO_MMWAVE_FRAME_ASSEMBLER_H

#include <cstddef>
#include <cstdint>
#include <vector>

#include "FrameCodec.h"

namespace seeed {
namespace mmwave {

class FrameAssembler {
public:
enum class FeedResult {
NeedMore, // Still collecting a candidate frame.
FrameReady, // takeFrame() returns one complete candidate.
Resynced, // Dropped a false lock and continued scanning.
};

/**
* @brief Consume one UART byte.
* @param byte Next byte from the serial stream.
* @return NeedMore, FrameReady, or Resynced.
*
* 喂入一字节串口数据。
*/
FeedResult feed(uint8_t byte);

/**
* @brief Feed a buffer and collect every completed candidate frame.
* @param data Bytes to feed.
* @param len Number of bytes.
* @param out Completed frames in arrival order.
* @return Number of frames appended to `out`.
*
* 连续喂入一段字节并收集完整候选帧。
*/
size_t feedBuffer(const uint8_t* data, size_t len,
std::vector<std::vector<uint8_t>>& out);

/**
* @brief Move the completed candidate out of the assembler.
* @return The candidate frame bytes (header + payload + data checksum).
*
* 取出刚组好的一帧。
*/
std::vector<uint8_t> takeFrame();

void reset();

bool hasFrame() const { return ready_; }
size_t buffered() const { return buf_.size(); }

private:
FeedResult evaluate();

std::vector<uint8_t> buf_;
bool in_frame_ = false;
bool ready_ = false;
};

} // namespace mmwave
} // namespace seeed

#endif // SEEED_ARDUINO_MMWAVE_FRAME_ASSEMBLER_H
Loading
Loading