Skip to content

Commit 9dfc5e5

Browse files
committed
Formatted an renamed all examples
1 parent 325ee9c commit 9dfc5e5

File tree

12 files changed

+688
-744
lines changed

12 files changed

+688
-744
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
//////////////////////////////////////////////////////////////////////////////////////////
2+
//
3+
// Protocentral ADS1293 Arduino example — 3-lead ECG (Arduino Plotter)
4+
//
5+
// Author: Ashwin Whitchurch, Protocentral Electronics
6+
// SPDX-FileCopyrightText: 2020 Protocentral Electronics
7+
// SPDX-License-Identifier: MIT
8+
//
9+
// This example streams ECG samples to the Arduino IDE Plotter.
10+
//
11+
// Hardware connections (Arduino UNO / ESP32 VSPI):
12+
//
13+
// | Signal | Arduino UNO | ESP32 (VSPI default) |
14+
// |-------:|:------------:|:--------------------:|
15+
// | MISO | 12 | 19 |
16+
// | MOSI | 11 | 23 |
17+
// | SCLK | 13 | 18 |
18+
// | CS | 4 | 4 |
19+
// | VCC | +5V | +5V |
20+
// | GND | GND | GND |
21+
// | DRDY | 2 | 2 |
22+
//
23+
// For full documentation and examples, see:
24+
// https://github.com/Protocentral/protocentral-ads1293-arduino
25+
//
26+
/////////////////////////////////////////////////////////////////////////////////////////
27+
28+
#include "protocentral_ads1293.h"
29+
#include <SPI.h>
30+
31+
#define DRDY_PIN 2
32+
#define CS_PIN 4
33+
34+
// Optional: override these before build to change SPI pins. Defaults follow
35+
// common Uno pins, and typical VSPI pins for ESP32.
36+
#if !defined(SCK_PIN)
37+
#if defined(ARDUINO_ARCH_ESP32)
38+
#define SCK_PIN 18
39+
#define MISO_PIN 19
40+
#define MOSI_PIN 23
41+
#else
42+
#define SCK_PIN 13
43+
#define MISO_PIN 12
44+
#define MOSI_PIN 11
45+
#endif
46+
#endif
47+
48+
ads1293 ADS1293(DRDY_PIN, CS_PIN);
49+
50+
void setup()
51+
{
52+
Serial.begin(115200);
53+
54+
#if defined(ARDUINO_ARCH_ESP32)
55+
ADS1293.begin(SCK_PIN, MISO_PIN, MOSI_PIN);
56+
#else
57+
ADS1293.begin();
58+
#endif
59+
60+
// Configure device for 3-lead ECG
61+
ADS1293.configureChannel1(FlexCh1Mode::Default);
62+
ADS1293.configureChannel2(FlexCh2Mode::Default);
63+
ADS1293.enableCommonModeDetection(CMDetMode::Enabled);
64+
ADS1293.configureRLD(RLDMode::Default);
65+
ADS1293.configureOscillator(OscMode::Default);
66+
67+
ADS1293.configureAFEShutdown(AFEShutdownMode::AFE_On);
68+
ADS1293.setSamplingRate(ADS1293::SamplingRate::SPS_100);
69+
70+
ADS1293.setChannelGain(1, ADS1293::PgaGain::G8);
71+
ADS1293.setChannelGain(2, ADS1293::PgaGain::G8);
72+
ADS1293.setChannelGain(3, ADS1293::PgaGain::G8);
73+
74+
ADS1293.configureDRDYSource(DRDYSource::Default);
75+
ADS1293.configureChannelConfig(ChannelConfig::Default3Lead);
76+
ADS1293.applyGlobalConfig(GlobalConfig::Start);
77+
78+
delay(10);
79+
}
80+
81+
void loop()
82+
{
83+
if (digitalRead(DRDY_PIN) == LOW)
84+
{
85+
auto samples = ADS1293.getECGData();
86+
if (samples.ok)
87+
{
88+
Serial.print(samples.ch1);
89+
Serial.print(',');
90+
Serial.print(samples.ch2);
91+
Serial.print(',');
92+
Serial.println(samples.ch3);
93+
}
94+
}
95+
delay(10);
96+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
//////////////////////////////////////////////////////////////////////////////////////////
2+
//
3+
// Protocentral ADS1293 Arduino example — 5-lead ECG (Arduino Plotter)
4+
//
5+
// Author: Ashwin Whitchurch, Protocentral Electronics
6+
// SPDX-FileCopyrightText: 2020 Protocentral Electronics
7+
// SPDX-License-Identifier: MIT
8+
//
9+
// This example streams ECG samples to the Arduino IDE Plotter.
10+
//
11+
// Hardware connections (Arduino UNO / ESP32 VSPI):
12+
//
13+
// | Signal | Arduino UNO | ESP32 (VSPI default) |
14+
// |-------:|:------------:|:--------------------:|
15+
// | MISO | 12 | 19 |
16+
// | MOSI | 11 | 23 |
17+
// | SCLK | 13 | 18 |
18+
// | CS | 4 | 4 |
19+
// | VCC | +5V | +5V |
20+
// | GND | GND | GND |
21+
// | DRDY | 2 | 2 |
22+
//
23+
// For full documentation and examples, see:
24+
// https://github.com/Protocentral/protocentral-ads1293-arduino
25+
//
26+
/////////////////////////////////////////////////////////////////////////////////////////
27+
28+
#include "protocentral_ads1293.h"
29+
#include <SPI.h>
30+
31+
#define DRDY_PIN 2
32+
#define CS_PIN 4
33+
34+
// Optional SPI pin overrides
35+
#if !defined(SCK_PIN)
36+
#if defined(ARDUINO_ARCH_ESP32)
37+
#define SCK_PIN 18
38+
#define MISO_PIN 19
39+
#define MOSI_PIN 23
40+
#else
41+
#define SCK_PIN 13
42+
#define MISO_PIN 12
43+
#define MOSI_PIN 11
44+
#endif
45+
#endif
46+
47+
ads1293 ADS1293(DRDY_PIN, CS_PIN);
48+
49+
void setup()
50+
{
51+
Serial.begin(115200);
52+
#if defined(ARDUINO_ARCH_ESP32)
53+
ADS1293.begin(SCK_PIN, MISO_PIN, MOSI_PIN);
54+
#else
55+
ADS1293.begin();
56+
#endif
57+
58+
// Configure device for 5-lead ECG
59+
ADS1293.configureChannel1(FlexCh1Mode::Default);
60+
ADS1293.configureChannel2(FlexCh2Mode::Default);
61+
ADS1293.configureChannel3(FlexCh3Mode::Default);
62+
ADS1293.enableCommonModeDetection(CMDetMode::Enabled);
63+
ADS1293.configureRLD(RLDMode::Default);
64+
ADS1293.configureRef(RefMode::Default);
65+
ADS1293.configureAFEShutdown(AFEShutdownMode::AFE_On);
66+
67+
ADS1293.setChannelGain(1, ADS1293::PgaGain::G8);
68+
ADS1293.setChannelGain(2, ADS1293::PgaGain::G8);
69+
ADS1293.setChannelGain(3, ADS1293::PgaGain::G8);
70+
71+
ADS1293.setSamplingRate(ADS1293::SamplingRate::SPS_100);
72+
ADS1293.configureDRDYSource(DRDYSource::Default);
73+
ADS1293.configureChannelConfig(ChannelConfig::Default5Lead);
74+
ADS1293.applyGlobalConfig(GlobalConfig::Start);
75+
delay(10);
76+
}
77+
78+
void loop()
79+
{
80+
if (digitalRead(DRDY_PIN) == LOW)
81+
{
82+
83+
auto samples = ADS1293.getECGData();
84+
if (samples.ok)
85+
{
86+
87+
Serial.print(samples.ch1);
88+
Serial.print(',');
89+
Serial.print(samples.ch2);
90+
Serial.print(',');
91+
Serial.println(samples.ch3);
92+
}
93+
}
94+
}
95+
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
//////////////////////////////////////////////////////////////////////////////////////////
2+
//
3+
// Protocentral ADS1293 Arduino example — 5-lead ECG (OpenView packet format)
4+
//
5+
// Author: Ashwin Whitchurch, Protocentral Electronics
6+
// SPDX-FileCopyrightText: 2020 Protocentral Electronics
7+
// SPDX-License-Identifier: MIT
8+
//
9+
// Streams ECG samples in the OpenView packet format. See the OpenView
10+
// project for the host-side processing tools:
11+
// https://github.com/Protocentral/protocentral_openview
12+
//
13+
// Hardware connections (Arduino UNO / ESP32 VSPI):
14+
//
15+
// | Signal | Arduino UNO | ESP32 (VSPI default) |
16+
// |-------:|:------------:|:--------------------:|
17+
// | MISO | 12 | 19 |
18+
// | MOSI | 11 | 23 |
19+
// | SCLK | 13 | 18 |
20+
// | CS | 4 | 4 |
21+
// | VCC | +5V | +5V |
22+
// | GND | GND | GND |
23+
// | DRDY | 2 | 2 |
24+
//
25+
// For full documentation and examples, see:
26+
// https://github.com/Protocentral/protocentral-ads1293-arduino
27+
//
28+
/////////////////////////////////////////////////////////////////////////////////////////
29+
30+
31+
#include "protocentral_ads1293.h"
32+
#include <SPI.h>
33+
34+
#define CES_CMDIF_PKT_START_1 0x0A
35+
#define CES_CMDIF_PKT_START_2 0xFA
36+
#define CES_CMDIF_TYPE_DATA 0x02
37+
#define CES_CMDIF_PKT_STOP 0x0B
38+
#define DATA_LEN 12
39+
#define ZERO 0
40+
41+
#define DRDY_PIN 2
42+
#define CS_PIN 4
43+
44+
// Uncomment to send voltages instead of raw ADC codes
45+
// #define PRINT_VOLTAGE
46+
47+
// Optional SPI pin overrides
48+
#if !defined(SCK_PIN)
49+
#if defined(ARDUINO_ARCH_ESP32)
50+
#define SCK_PIN 18
51+
#define MISO_PIN 19
52+
#define MOSI_PIN 23
53+
#else
54+
#define SCK_PIN 13
55+
#define MISO_PIN 12
56+
#define MOSI_PIN 11
57+
#endif
58+
#endif
59+
60+
ads1293 ADS1293(DRDY_PIN, CS_PIN);
61+
62+
volatile uint8_t DataPacket[DATA_LEN];
63+
const uint8_t DataPacketFooter[2] = {ZERO, CES_CMDIF_PKT_STOP};
64+
const uint8_t DataPacketHeader[5] = {CES_CMDIF_PKT_START_1, CES_CMDIF_PKT_START_2, DATA_LEN, ZERO, CES_CMDIF_TYPE_DATA};
65+
66+
void sendDataThroughUart(int32_t ecgCh1, int32_t ecgCh2, int32_t ecgCh3) {
67+
// pack little-endian 32-bit values
68+
DataPacket[0] = static_cast<uint8_t>(ecgCh1 & 0xFF);
69+
DataPacket[1] = static_cast<uint8_t>((ecgCh1 >> 8) & 0xFF);
70+
DataPacket[2] = static_cast<uint8_t>((ecgCh1 >> 16) & 0xFF);
71+
DataPacket[3] = static_cast<uint8_t>((ecgCh1 >> 24) & 0xFF);
72+
73+
DataPacket[4] = static_cast<uint8_t>(ecgCh2 & 0xFF);
74+
DataPacket[5] = static_cast<uint8_t>((ecgCh2 >> 8) & 0xFF);
75+
DataPacket[6] = static_cast<uint8_t>((ecgCh2 >> 16) & 0xFF);
76+
DataPacket[7] = static_cast<uint8_t>((ecgCh2 >> 24) & 0xFF);
77+
78+
DataPacket[8] = static_cast<uint8_t>(ecgCh3 & 0xFF);
79+
DataPacket[9] = static_cast<uint8_t>((ecgCh3 >> 8) & 0xFF);
80+
DataPacket[10] = static_cast<uint8_t>((ecgCh3 >> 16) & 0xFF);
81+
DataPacket[11] = static_cast<uint8_t>((ecgCh3 >> 24) & 0xFF);
82+
83+
// send packet header
84+
for (int i = 0; i < 5; ++i) {
85+
Serial.write(DataPacketHeader[i]);
86+
}
87+
88+
// send actual data
89+
for (int i = 0; i < DATA_LEN; ++i) {
90+
Serial.write(DataPacket[i]);
91+
}
92+
93+
// send packet footer
94+
for (int i = 0; i < 2; ++i) {
95+
Serial.write(DataPacketFooter[i]);
96+
}
97+
}
98+
99+
// Helper: convert 24-bit unsigned raw value to signed 32-bit using two's-complement
100+
static int32_t raw24_to_int24(uint32_t raw24) {
101+
raw24 &= 0xFFFFFFu;
102+
if (raw24 & 0x800000u) {
103+
return static_cast<int32_t>(raw24 | 0xFF000000u);
104+
}
105+
return static_cast<int32_t>(raw24);
106+
}
107+
108+
// Helper: build a 24-bit raw value from three bytes (MSB, mid, LSB)
109+
static uint32_t raw24_from_bytes(uint8_t msb, uint8_t mid, uint8_t lsb) {
110+
return (static_cast<uint32_t>(msb) << 16) | (static_cast<uint32_t>(mid) << 8) | static_cast<uint32_t>(lsb);
111+
}
112+
113+
// Uncomment to enable debug register/sample dumps on startup
114+
// #define ENABLE_DEBUG
115+
116+
void setup() {
117+
Serial.begin(57600);
118+
#if defined(ARDUINO_ARCH_ESP32)
119+
ADS1293.begin(SCK_PIN, MISO_PIN, MOSI_PIN);
120+
#else
121+
ADS1293.begin();
122+
#endif
123+
// Configure device for 5-lead ECG using explicit helpers
124+
ADS1293.configureChannel1(FlexCh1Mode::Default);
125+
ADS1293.configureChannel2(FlexCh2Mode::Default);
126+
ADS1293.configureChannel3(FlexCh3Mode::Default);
127+
ADS1293.enableCommonModeDetection(CMDetMode::Enabled);
128+
ADS1293.configureRLD(RLDMode::Default);
129+
ADS1293.configureRef(RefMode::Default);
130+
ADS1293.configureAFEShutdown(AFEShutdownMode::AFE_On);
131+
// Set PGA gain=8 for all channels
132+
ADS1293.setChannelGain(1, ADS1293::PgaGain::G8);
133+
ADS1293.setChannelGain(2, ADS1293::PgaGain::G8);
134+
ADS1293.setChannelGain(3, ADS1293::PgaGain::G8);
135+
// Ensure example runs at 100 SPS using the DRATE-based API
136+
ADS1293.setSamplingRate(ADS1293::SamplingRate::SPS_100);
137+
ADS1293.configureDRDYSource(DRDYSource::Default);
138+
ADS1293.configureChannelConfig(ChannelConfig::Default5Lead);
139+
ADS1293.applyGlobalConfig(GlobalConfig::Start);
140+
delay(10);
141+
142+
#if defined(ENABLE_DEBUG)
143+
ADS1293.dumpDebug(Serial);
144+
#endif
145+
}
146+
147+
void loop() {
148+
if (digitalRead(DRDY_PIN) == LOW) {
149+
// Use convenience overload to get all three channels in one call
150+
auto samples = ADS1293.getECGData();
151+
if (samples.ok) {
152+
// Read raw 24-bit values from the device, sign-extend to int32_t,
153+
// and send as 32-bit little-endian (LSB first) in the packet payload.
154+
uint32_t raw1 = 0, raw2 = 0, raw3 = 0;
155+
if (ADS1293.getRaw24(1, raw1) && ADS1293.getRaw24(2, raw2) && ADS1293.getRaw24(3, raw3)) {
156+
int32_t s1 = raw24_to_int24(raw1);
157+
int32_t s2 = raw24_to_int24(raw2);
158+
int32_t s3 = raw24_to_int24(raw3);
159+
sendDataThroughUart(s1, s2, s3);
160+
}
161+
}
162+
}
163+
delay(10);
164+
}
165+

0 commit comments

Comments
 (0)