https://github.com/jpcodes44/heartclick5_lib
Arduino Library for the HeartClick5 Spo2 sensor
https://github.com/jpcodes44/heartclick5_lib
Last synced: 11 months ago
JSON representation
Arduino Library for the HeartClick5 Spo2 sensor
- Host: GitHub
- URL: https://github.com/jpcodes44/heartclick5_lib
- Owner: JPCodes44
- Created: 2025-04-03T21:49:01.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-03T22:17:43.000Z (over 1 year ago)
- Last Synced: 2025-04-09T21:14:20.755Z (about 1 year ago)
- Language: C++
- Size: 7.81 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# HeartClick5 Arduino Driver
This Arduino library enables communication with the **HeartClick5** sensor module, based on the **AFE4404 analog front-end** by Texas Instruments. It supports I2C communication and allows you to access raw LED and ambient photodiode data for heart rate and SpOβ signal extraction.
---
## π¦ Files
- `HeartClick5.h` β Class interface definitions
- `HeartClick5.cpp` β Implementation of register access and signal readout
- `HeartClick5_hal.cpp` β Optional hardware abstraction helpers (if required)
---
## π Hardware Interface
- **I2C Address**: `0x58`
- **Power**: 3.3V (recommended)
- **Pins**:
- `SCL` β Arduino SCL
- `SDA` β Arduino SDA
- `GND` β Ground
- `VCC` β 3.3V
- Optional `RST` β Digital pin (if using software reset)
---
## π Getting Started
### 1. Clone or Copy the Files
Place `HeartClick5.h`, `HeartClick5.cpp` in your Arduino project folder.
### 2. Include and Initialize the Sensor
```cpp
#include
#include "HeartClick5.h"
HeartClick5 heartSensor(0x58); // Default I2C address
void setup() {
Serial.begin(9600);
Wire.begin();
if (heartSensor.begin()) {
Serial.println("β
HeartClick5 initialized.");
} else {
Serial.println("β Sensor not found.");
while (1); // Halt
}
}
```
---
## π§ Example: Reading SpOβ Signal
The most relevant signal for oximetry is the **difference between LED2 and its ambient phase**, accessible via `getLed2MinusAled2Val()`.
```cpp
void loop() {
int32_t rawSpO2 = heartSensor.getLed2MinusAled2Val();
Serial.println(rawSpO2);
delay(100);
}
```
---
## π API Reference
### Initialization
```cpp
HeartClick5 sensor(0x58);
sensor.begin();
```
### Signal Readouts (24-bit Registers)
```cpp
int32_t getLed2Val();
int32_t getAled2ValLed3Val();
int32_t getLed1Val();
int32_t getAled1Val();
int32_t getLed2MinusAled2Val(); // Preferred for SpOβ
int32_t getLed1MinusAled1Val(); // Preferred for HR
```
---
## π SpOβ Estimation Logic
To compute SpOβ:
1. Sample both `LED2 - ALED2` and `LED1 - ALED1` over time.
2. Calculate the AC and DC components.
3. Use the ratio-of-ratios method:
```math
R = (AC_red / DC_red) / (AC_ir / DC_ir)
SpOβ β 110 - 25 Γ R
```
A moving average or peak-to-peak calculation is typically used for AC, and a long-term average for DC.
---
## π Datasheet & References
- π [AFE4404 Datasheet (TI / MikroE)](https://download.mikroe.com/documents/datasheets/afe4404.pdf)
- π§ͺ [Texas Instruments AFE4404 Product Page](https://www.ti.com/product/AFE4404)
- π MikroElektronika Heart Rate 5 Click board
---
## π§ͺ Advanced Usage
You can also access and configure register-level controls:
- Pulse timing
- LED current settings
- Gain settings
- TIA bandwidth
- Power modes
Use setters like `writeRegister(uint8_t reg, uint32_t val)` or expose additional API calls.
---
## π§βπ» Author
Adapted by your team from MikroEβs C library to Arduino C++ for easy integration with embedded projects.
---
## π License
MIT License or based on MikroElektronika SDK license if using their base source.
```
Let me know if you want this converted to PDF, added to a repo, or expanded with visuals or usage diagrams!