Skip to content

Commit 95edb07

Browse files
committed
Working with high data rate
1 parent f71f14e commit 95edb07

File tree

9 files changed

+1092
-451
lines changed

9 files changed

+1092
-451
lines changed

examples/Example1-3leadECGstream-arduino-plotter/Example1-3leadECGstream-arduino-plotter.ino

Lines changed: 75 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -30,48 +30,89 @@
3030
//
3131
/////////////////////////////////////////////////////////////////////////////////////////
3232

33-
3433
#include "protocentral_ads1293.h"
3534
#include <SPI.h>
3635

37-
#define DRDY_PIN 02
38-
#define CS_PIN 10
39-
40-
ads1293 ADS1293(DRDY_PIN, CS_PIN);
41-
42-
bool drdyIntFlag = false;
43-
44-
void drdyInterruptHndlr(){
45-
//Serial.println("i");
46-
drdyIntFlag = true;
47-
}
48-
49-
void enableInterruptPin(){
50-
//ToDo
36+
#define DRDY_PIN 2
37+
#define CS_PIN 10
5138

52-
// pinMode(ADS1293.drdyPin, INPUT_PULLUP);
53-
attachInterrupt(digitalPinToInterrupt(ADS1293.drdyPin), drdyInterruptHndlr, FALLING);
54-
}
39+
// Uncomment to route the built-in positive test signal to all channels
40+
// #define ENABLE_TEST_SIGNAL 0
5541

42+
// Optional: override these before build to change SPI pins. Defaults follow
43+
// common Uno pins, and typical VSPI pins for ESP32.
44+
#if !defined(SCK_PIN)
45+
#if defined(ARDUINO_ARCH_ESP32)
46+
#define SCK_PIN 18
47+
#define MISO_PIN 19
48+
#define MOSI_PIN 23
49+
#else
50+
#define SCK_PIN 13
51+
#define MISO_PIN 12
52+
#define MOSI_PIN 11
53+
#endif
54+
#endif
5655

57-
void setup() {
56+
using namespace protocentral;
5857

59-
Serial.begin(9600);
60-
SPI.begin();
58+
ads1293 ADS1293(DRDY_PIN, CS_PIN);
6159

62-
ADS1293.ads1293Begin3LeadECG();
63-
//enableInterruptPin();
64-
delay(10);
60+
// Uncomment to enable debug register/sample dumps on startup and before streaming
61+
// #define ENABLE_DEBUG
62+
63+
void setup()
64+
{
65+
Serial.begin(115200);
66+
// Start SPI appropriately for the platform. On ESP32 use the SCK/MISO/MOSI overload
67+
#if defined(ARDUINO_ARCH_ESP32)
68+
ADS1293.begin(SCK_PIN, MISO_PIN, MOSI_PIN);
69+
#else
70+
ADS1293.begin();
71+
#endif
72+
// Configure device for 3-lead ECG
73+
74+
ADS1293.configureChannel1(FlexCh1Mode::Default);
75+
ADS1293.configureChannel2(FlexCh2Mode::Default);
76+
ADS1293.enableCommonModeDetection(CMDetMode::Enabled);
77+
ADS1293.configureRLD(RLDMode::Default);
78+
ADS1293.configureOscillator(OscMode::Default);
79+
// Ensure the analog front-end is powered on so conversions produce valid data
80+
ADS1293.configureAFEShutdown(AFEShutdownMode::AFE_On);
81+
// Use the new high-level sampling-rate API and set default ODR to 100 SPS
82+
ADS1293.setSamplingRate(Ads1293::SamplingRate::SPS_100);
83+
ADS1293.configureDRDYSource(DRDYSource::Default);
84+
ADS1293.configureChannelConfig(ChannelConfig::Default3Lead);
85+
ADS1293.applyGlobalConfig(GlobalConfig::Start);
86+
87+
#if defined(ENABLE_DEBUG)
88+
// Dump ID, error status and a sample read for debugging wiring/SPI
89+
ADS1293.dumpDebug(Serial);
90+
#endif
91+
92+
#if defined(ENABLE_TEST_SIGNAL)
93+
// enable positive test signal on all channels for validation
94+
ADS1293.enableTestSignalAll(TestSignal::Positive);
95+
#endif
96+
97+
delay(10);
6598
}
6699

67-
void loop() {
68-
69-
//if (drdyIntFlag) {
70-
if (digitalRead(ADS1293.drdyPin) == false){
71-
72-
drdyIntFlag = false;
73-
int32_t ecg = ADS1293.getECGdata(1);
74-
75-
Serial.println(ecg);
76-
}
100+
void loop()
101+
{
102+
// check DRDY pin and read channel 1
103+
if (digitalRead(DRDY_PIN) == LOW)
104+
{
105+
// Use the convenience overload that returns a Samples POD
106+
auto samples = ADS1293.getECGData();
107+
if (samples.ok)
108+
{
109+
// Print all three channels as CSV so the Arduino plotter or a host
110+
// application can parse them easily: ch1,ch2,ch3
111+
Serial.print(samples.ch1);
112+
Serial.print(',');
113+
Serial.print(samples.ch2);
114+
Serial.print(',');
115+
Serial.println(samples.ch3);
116+
}
117+
}
77118
}

examples/Example2-5leadECGstream-arduino-plotter/Example2-5leadECGstream-arduino-plotter.ino

Lines changed: 65 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -34,53 +34,78 @@
3434
#include "protocentral_ads1293.h"
3535
#include <SPI.h>
3636

37-
#define DRDY_PIN 02
38-
#define CS_PIN 10
37+
#define DRDY_PIN 2
38+
#define CS_PIN 10
39+
40+
// Uncomment to print voltages instead of raw ADC codes
41+
// #define PRINT_VOLTAGE
42+
43+
// Optional SPI pin overrides
44+
#if !defined(SCK_PIN)
45+
#if defined(ARDUINO_ARCH_ESP32)
46+
#define SCK_PIN 18
47+
#define MISO_PIN 19
48+
#define MOSI_PIN 23
49+
#else
50+
#define SCK_PIN 13
51+
#define MISO_PIN 12
52+
#define MOSI_PIN 11
53+
#endif
54+
#endif
55+
56+
using namespace protocentral;
3957

4058
ads1293 ADS1293(DRDY_PIN, CS_PIN);
4159

42-
bool drdyIntFlag = false;
43-
44-
void drdyInterruptHndlr(){
45-
//Serial.println("i");
46-
drdyIntFlag = true;
47-
}
48-
49-
void enableInterruptPin(){
50-
51-
// pinMode(ADS1293.drdyPin, INPUT_PULLUP);
52-
attachInterrupt(digitalPinToInterrupt(ADS1293.drdyPin), drdyInterruptHndlr, FALLING);
53-
}
54-
55-
5660
void setup() {
57-
58-
Serial.begin(9600);
59-
SPI.begin();
60-
61-
ADS1293.setAds1293Pins();
62-
ADS1293.ads1293Begin5LeadECG();
63-
//enableInterruptPin();
61+
Serial.begin(115200);
62+
#if defined(ARDUINO_ARCH_ESP32)
63+
ADS1293.begin(SCK_PIN, MISO_PIN, MOSI_PIN);
64+
#else
65+
ADS1293.begin();
66+
#endif
67+
// Configure device for 5-lead ECG using fine-grained helpers
68+
ADS1293.configureChannel1(FlexCh1Mode::Default);
69+
ADS1293.configureChannel2(FlexCh2Mode::Default);
70+
ADS1293.configureChannel3(FlexCh3Mode::Default);
71+
ADS1293.enableCommonModeDetection(CMDetMode::Enabled);
72+
ADS1293.configureRLD(RLDMode::Default);
73+
ADS1293.configureRef(RefMode::Default);
74+
ADS1293.configureAFEShutdown(AFEShutdownMode::AFE_On);
75+
// Ensure example runs at 100 SPS using the DRATE-based API
76+
ADS1293.setSamplingRate(Ads1293::SamplingRate::SPS_100);
77+
ADS1293.configureDRDYSource(DRDYSource::Default);
78+
ADS1293.configureChannelConfig(ChannelConfig::Default5Lead);
79+
ADS1293.applyGlobalConfig(GlobalConfig::Start);
6480
delay(10);
6581
}
6682

6783
void loop() {
68-
69-
//if (drdyIntFlag) {
70-
if (digitalRead(ADS1293.drdyPin) == false){
71-
72-
drdyIntFlag = false;
73-
int32_t ecgCh1 = ADS1293.getECGdata(1);
74-
int32_t ecgCh2 = ADS1293.getECGdata(2);
75-
int32_t ecgCh3 = ADS1293.getECGdata(3);
76-
77-
Serial.print(ecgCh1);
78-
//Serial.print(",");
79-
80-
//Serial.print(ecgCh2);
81-
//Serial.print(",");
82-
83-
//Serial.print(ecgCh3);
84-
Serial.println(",");
84+
if (digitalRead(DRDY_PIN) == LOW) {
85+
// Use the convenience overload that returns Samples
86+
auto samples = ADS1293.getECGData();
87+
if (samples.ok) {
88+
#ifdef PRINT_VOLTAGE
89+
uint32_t raw1=0, raw2=0, raw3=0;
90+
if (ADS1293.getRaw24(1, raw1) && ADS1293.getRaw24(2, raw2) && ADS1293.getRaw24(3, raw3)) {
91+
int32_t s1 = Ads1293::interpretRaw24(raw1, /*offsetBinary=*/false);
92+
int32_t s2 = Ads1293::interpretRaw24(raw2, /*offsetBinary=*/false);
93+
int32_t s3 = Ads1293::interpretRaw24(raw3, /*offsetBinary=*/false);
94+
float v1 = Ads1293::rawToVoltage(s1);
95+
float v2 = Ads1293::rawToVoltage(s2);
96+
float v3 = Ads1293::rawToVoltage(s3);
97+
Serial.print(v1, 6); Serial.print(',');
98+
Serial.print(v2, 6); Serial.print(',');
99+
Serial.println(v3, 6);
100+
}
101+
#else
102+
// print CSV ch1,ch2,ch3 (raw signed codes)
103+
Serial.print(samples.ch1);
104+
Serial.print(',');
105+
Serial.print(samples.ch2);
106+
Serial.print(',');
107+
Serial.println(samples.ch3);
108+
#endif
109+
}
85110
}
86111
}

0 commit comments

Comments
 (0)