Skip to content

Commit 99faaa3

Browse files
authored
Merge pull request #179 from biomurph/master
Adding support for UNO R5
2 parents 4f14d66 + f94f492 commit 99faaa3

File tree

12 files changed

+216
-11
lines changed

12 files changed

+216
-11
lines changed

examples/PulseSensor_ATtiny85_Serial/PulseSensor_ATtiny85_Serial.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
Here, #define USE_ARDUINO_INTERRUPTS true tells the library to use
2424
interrupts to automatically read and process PulseSensor data.
2525
26-
See ProcessEverySample.ino for an example of not using interrupts.
26+
See PulseSensor_BPM_Alternative.ino for an example of not using interrupts.
2727
*/
2828
#define USE_ARDUINO_INTERRUPTS true
2929
#include <PulseSensorPlayground.h>

examples/PulseSensor_ATtiny85_noSerial/PulseSensor_ATtiny85_noSerial.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
Here, #define USE_ARDUINO_INTERRUPTS true tells the library to use
2424
interrupts to automatically read and process PulseSensor data.
2525
26-
See ProcessEverySample.ino for an example of not using interrupts.
26+
See PulseSensor_BPM_Alternative.ino for an example of not using interrupts.
2727
*/
2828
#define USE_ARDUINO_INTERRUPTS true
2929
#include <PulseSensorPlayground.h>

examples/PulseSensor_BPM/PulseSensor_BPM.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
Here, #define USE_ARDUINO_INTERRUPTS true tells the library to use
2424
interrupts to automatically read and process PulseSensor data.
2525
26-
See ProcessEverySample.ino for an example of not using interrupts.
26+
See PulseSensor_BPM_Alternative.ino for an example of not using interrupts.
2727
*/
2828
#define USE_ARDUINO_INTERRUPTS true
2929
#include <PulseSensorPlayground.h>
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/*
2+
Code to detect pulses from the PulseSensor,
3+
using an interrupt service routine.
4+
5+
>>>> This example targest the Arduino UNO R4.
6+
>>>> It has been tested on the Minima and the WiFi board variants.
7+
8+
Here is a link to the tutorial
9+
https://pulsesensor.com/pages/getting-advanced
10+
11+
Copyright World Famous Electronics LLC - see LICENSE
12+
Contributors:
13+
Joel Murphy, https://pulsesensor.com
14+
Yury Gitman, https://pulsesensor.com
15+
Bradford Needham, @bneedhamia, https://bluepapertech.com
16+
17+
Licensed under the MIT License, a copy of which
18+
should have been included with this software.
19+
20+
This software is not intended for medical use.
21+
*/
22+
23+
/*
24+
We use the FspTimer to setup a timer interrupt for sample acquisition
25+
FspTimer is part of the hardware core files for this chip
26+
*/
27+
#include "FspTimer.h"
28+
FspTimer sampleTimer;
29+
30+
31+
/*
32+
Every Sketch that uses the PulseSensor Playground must
33+
define USE_ARDUINO_INTERRUPTS before including PulseSensorPlayground.h.
34+
Here, #define USE_ARDUINO_INTERRUPTS true tells the library to use
35+
interrupts to automatically read and process PulseSensor data.
36+
37+
See PulseSensorBPM_Alternative.ino for an example of not using interrupts.
38+
*/
39+
#define USE_ARDUINO_INTERRUPTS true
40+
#include <PulseSensorPlayground.h>
41+
42+
/*
43+
This is the timer interrupt service routine where we acquire and process samples
44+
*/
45+
void sampleTimerISR(timer_callback_args_t __attribute((unused)) *p_args){
46+
PulseSensorPlayground::OurThis->onSampleTime();
47+
}
48+
49+
/*
50+
The format of our output.
51+
52+
Set this to PROCESSING_VISUALIZER if you're going to run
53+
the Processing Visualizer Sketch.
54+
See https://github.com/WorldFamousElectronics/PulseSensor_Amped_Processing_Visualizer
55+
56+
Set this to SERIAL_PLOTTER if you're going to run
57+
the Arduino IDE's Serial Plotter.
58+
*/
59+
const int OUTPUT_TYPE = SERIAL_PLOTTER;
60+
61+
/*
62+
Pinout:
63+
PULSE_INPUT = Analog Input. Connected to the pulse sensor
64+
purple (signal) wire.
65+
PULSE_BLINK = digital Output. Connected to an LED (and 1K series resistor)
66+
that will flash on each detected pulse.
67+
PULSE_FADE = digital Output. PWM pin onnected to an LED (and 1K series resistor)
68+
that will smoothly fade with each pulse.
69+
NOTE: PULSE_FADE must be a pin that supports PWM. Do not use
70+
pin 9 or 10, because those pins' PWM interferes with the sample timer.
71+
THRESHOLD should be set higher than the PulseSensor signal idles
72+
at when there is nothing touching it. The expected idle value
73+
should be 512, which is 1/2 of the ADC range. To check the idle value
74+
open a serial monitor and make note of the PulseSensor signal values
75+
with nothing touching the sensor. THRESHOLD should be a value higher
76+
than the range of idle noise by 25 to 50 or so. When the library
77+
is finding heartbeats, the value is adjusted based on the pulse signal
78+
waveform. THRESHOLD sets the default when there is no pulse present.
79+
Adjust as neccesary.
80+
*/
81+
const int PULSE_INPUT = A0;
82+
const int PULSE_BLINK = LED_BUILTIN;
83+
const int PULSE_FADE = 5;
84+
const int THRESHOLD = 550; // Adjust this number to avoid noise when idle
85+
86+
/*
87+
All the PulseSensor Playground functions.
88+
*/
89+
PulseSensorPlayground pulseSensor;
90+
91+
void setup() {
92+
/*
93+
Use 115200 baud because that's what the Processing Sketch expects to read,
94+
and because that speed provides about 11 bytes per millisecond.
95+
96+
If we used a slower baud rate, we'd likely write bytes faster than
97+
they can be transmitted, which would mess up the timing
98+
of readSensor() calls, which would make the pulse measurement
99+
not work properly.
100+
*/
101+
Serial.begin(115200);
102+
103+
// Configure the PulseSensor manager.
104+
105+
pulseSensor.analogInput(PULSE_INPUT);
106+
pulseSensor.blinkOnPulse(PULSE_BLINK);
107+
pulseSensor.fadeOnPulse(PULSE_FADE);
108+
109+
pulseSensor.setSerial(Serial);
110+
pulseSensor.setOutputType(OUTPUT_TYPE);
111+
pulseSensor.setThreshold(THRESHOLD);
112+
113+
// Now that everything is ready, start reading the PulseSensor signal.
114+
if (!pulseSensor.begin()) {
115+
/*
116+
PulseSensor initialization failed,
117+
likely because our particular Arduino platform interrupts
118+
aren't supported yet.
119+
120+
If your Sketch hangs here, try PulseSensor_BPM_Alternative.ino,
121+
which doesn't use interrupts.
122+
*/
123+
for(;;) {
124+
// Flash the led to show things didn't work.
125+
digitalWrite(PULSE_BLINK, LOW);
126+
delay(50); Serial.println('!');
127+
digitalWrite(PULSE_BLINK, HIGH);
128+
delay(50);
129+
}
130+
}
131+
132+
/*
133+
We have to get control of a timer on the R4. First, we try and see if there are any free timers available.
134+
If there are no free timers available, we will just take control of one from some other purpose.
135+
We shouldn't have to force things, but if you use alot of timers, beware of this force use code!
136+
*/
137+
uint8_t timer_type = GPT_TIMER;
138+
int8_t tindex = FspTimer::get_available_timer(timer_type);
139+
if(tindex == 0){
140+
FspTimer::force_use_of_pwm_reserved_timer();
141+
tindex = FspTimer::get_available_timer(timer_type);
142+
}
143+
144+
/*
145+
Begin sets up the timer that we just got control of as a periodic timer with 500Hz frequency.
146+
It also passes the interrupt service routine that we made above.
147+
*/
148+
sampleTimer.begin(TIMER_MODE_PERIODIC, timer_type, tindex, SAMPLE_RATE_500HZ, 0.0f, sampleTimerISR);
149+
sampleTimer.setup_overflow_irq();
150+
sampleTimer.open();
151+
sampleTimer.start();
152+
}
153+
154+
void loop() {
155+
/*
156+
Wait a bit.
157+
We don't output every sample, because our baud rate
158+
won't support that much I/O.
159+
*/
160+
delay(20);
161+
162+
// write the latest sample to Serial.
163+
pulseSensor.outputSample();
164+
165+
/*
166+
If a beat has happened since we last checked,
167+
write the per-beat information to Serial.
168+
*/
169+
if (pulseSensor.sawStartOfBeat()) {
170+
pulseSensor.outputBeat();
171+
}
172+
173+
}
174+

examples/PulseSensor_RP2040/PulseSensor_RP2040.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ RPI_PICO_Timer sampleTimer(0); // the paramater may need to change, depending?
4141
Here, #define USE_ARDUINO_INTERRUPTS true tells the library to use
4242
interrupts to automatically read and process PulseSensor data.
4343
44-
See ProcessEverySample.ino for an example of not using interrupts.
44+
See PulseSensor_BPM_Alternative.ino for an example of not using interrupts.
4545
*/
4646
#define USE_ARDUINO_INTERRUPTS true
4747
#include <PulseSensorPlayground.h>

examples/PulseSensor_Servo/PulseSensor_Servo.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
Here, #define USE_ARDUINO_INTERRUPTS true tells the library to use
3030
interrupts to automatically read and process PulseSensor data.
3131
32-
See ProcessEverySample.ino for an example of not using interrupts.
32+
See PulseSensor_BPM_Alternative.ino for an example of not using interrupts.
3333
*/
3434
#define USE_ARDUINO_INTERRUPTS true
3535
#include <PulseSensorPlayground.h>

examples/PulseSensor_Speaker/PulseSensor_Speaker.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
Here, #define USE_ARDUINO_INTERRUPTS true tells the library to use
2727
interrupts to automatically read and process PulseSensor data.
2828
29-
See ProcessEverySample.ino for an example of not using interrupts.
29+
See PulseSensor_BPM_Alternative.ino for an example of not using interrupts.
3030
*/
3131
#define USE_ARDUINO_INTERRUPTS true
3232
#include <PulseSensorPlayground.h>

examples/PulseSensor_nRF52/PulseSensor_nRF52.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ NRF52Timer sampleTimer(NRF_TIMER_3);
5959
Here, #define USE_ARDUINO_INTERRUPTS true tells the library to use
6060
interrupts to automatically read and process PulseSensor data.
6161
62-
See ProcessEverySample.ino for an example of not using interrupts.
62+
See PulseSensor_BPM_Alternative.ino for an example of not using interrupts.
6363
*/
6464
#define USE_ARDUINO_INTERRUPTS true
6565
#include <PulseSensorPlayground.h>

examples/PulseSensor_nRF52840_Feather_Express/PulseSensor_nRF52840_Feather_Express.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ BLEDis bledis;
7878
Here, #define USE_ARDUINO_INTERRUPTS true tells the library to use
7979
interrupts to automatically read and process PulseSensor data.
8080
81-
See ProcessEverySample.ino for an example of not using interrupts.
81+
See PulseSensor_BPM_Alternative.ino for an example of not using interrupts.
8282
*/
8383
#define USE_ARDUINO_INTERRUPTS true
8484
#include <PulseSensorPlayground.h>

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=PulseSensor Playground
2-
version=1.8.2
2+
version=1.9.0
33
author=Joel Murphy, Yury Gitman, Brad Needham
44
maintainer=Joel Murphy, Yury Gitman
55
sentence=Support at PulseSensor.com

src/PulseSensorPlayground.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,19 @@
133133
#if defined(ARDUINO_ARCH_NRF52)
134134
#include "Adafruit_TinyUSB.h"
135135
#endif
136+
// #if defined(ARDUINO_ARCH_RENESAS)
137+
// #include "FspTimer.h"
138+
// FspTimer sampleTimer
139+
// #endif
136140
#include <Arduino.h>
137141
#include "utility/PulseSensor.h"
138142
#if USE_SERIAL
139143
#include "utility/PulseSensorSerialOutput.h"
140144
#endif
141145
#include "utility/PulseSensorTimingStatistics.h"
142146

147+
#define SAMPLE_RATE_500HZ 500
148+
143149
class PulseSensorPlayground {
144150
public:
145151
/*
@@ -464,6 +470,12 @@ class PulseSensorPlayground {
464470
#if PULSE_SENSOR_TIMING_ANALYSIS // Don't use ram and flash we don't need.
465471
PulseSensorTimingStatistics *pTiming;
466472
#endif // PULSE_SENSOR_TIMING_ANALYSIS
473+
474+
#if defined(ARDUINO_ARCH_RENESAS)
475+
uint8_t timer_type;
476+
int8_t tindex;
477+
#endif
478+
467479
};
468480

469481
/*

src/utility/Interrupts.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
#if defined(__arc__)||(ARDUINO_SAMD_MKR1000)||(ARDUINO_SAMD_MKRZERO)||(ARDUINO_SAMD_ZERO)\
6666
||(ARDUINO_ARCH_SAMD)||(ARDUINO_ARCH_STM32)||(ARDUINO_STM32_STAR_OTTO)||(ARDUINO_ARCH_NRF52)\
6767
||(ARDUINO_NANO33BLE)||(ARDUINO_ARCH_RP2040)||(ARDUINO_ARCH_ESP32)||(ARDUINO_ARCH_MBED_NANO)\
68-
||(ARDUINO_ARCH_NRF52840)||(ARDUINO_ARCH_SAM)
68+
||(ARDUINO_ARCH_NRF52840)||(ARDUINO_ARCH_SAM)||(ARDUINO_ARCH_RENESAS)
6969

7070
#define DISABLE_PULSE_SENSOR_INTERRUPTS
7171
#define ENABLE_PULSE_SENSOR_INTERRUPTS
@@ -254,6 +254,10 @@ boolean PulseSensorPlaygroundSetupInterrupt() {
254254
result = true;
255255
#endif
256256

257+
#if defined(ARDUINO_ARCH_RENESAS)
258+
result = true;
259+
#endif
260+
257261
#endif // USE_ARDUINO_INTERRUPTS
258262

259263
return result;
@@ -320,8 +324,14 @@ boolean PulseSensorPlaygroundDisableInterrupt(){
320324
result = true;
321325
#endif
322326

327+
#if defined(ARDUINO_ARCH_RENESAS)
328+
sampleTimer.stop();
329+
#endif
330+
323331
#endif
324332

333+
334+
325335
return result; // unknown or unsupported platform.
326336
} // PulseSensorPlaygroundDisableInterrupt
327337

@@ -388,6 +398,10 @@ boolean PulseSensorPlaygroundEnableInterrupt(){
388398
result = true;
389399
#endif
390400

401+
#if defined(ARDUINO_ARCH_RENESAS)
402+
sampleTimer.start();
403+
#endif
404+
391405
#endif
392406

393407
return result; // unknown or unsupported platform.
@@ -472,7 +486,12 @@ return result; // unknown or unsupported platform.
472486
// Interrupts not supported yet for Teensy
473487
#endif
474488

475-
489+
// #if defined(ARDUINO_ARCH_RENESAS)
490+
// void sampleTimerISR(timer_callback_args_t __attribute((unused)) *p_args)
491+
// {
492+
// PulseSensorPlayground::OurThis->onSampleTime();
493+
// }
494+
// #endif
476495

477496

478497
#endif // USE_ARDUINO_INTERRUPTS

0 commit comments

Comments
 (0)