Skip to content

Commit bfc0f46

Browse files
committed
Merge branch 'pr/6'
2 parents a300896 + 83bf298 commit bfc0f46

File tree

2 files changed

+167
-14
lines changed

2 files changed

+167
-14
lines changed

examples/Example1-ECG-BioZ-stream-Openview/Example1-ECG-BioZ-stream-Openview.ino

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@
66
// GUI URL: https://github.com/Protocentral/protocentral_openview.git
77
//
88
// Arduino connections:
9-
//
10-
// |MAX30001 pin label| Pin Function |Arduino Connection|
11-
// |----------------- |:--------------------:|-----------------:|
12-
// | MISO | Slave Out | D12 |
13-
// | MOSI | Slave In | D11 |
14-
// | SCLK | Serial Clock | D13 |
15-
// | CS | Chip Select | D7 |
16-
// | VCC | Digital VDD | +5V |
17-
// | GND | Digital Gnd | Gnd |
18-
// | FCLK | 32K CLOCK | - |
19-
// | INT1 | Interrupt1 | 02 |
20-
// | INT2 | Interrupt2 | - |
9+
// |MAX30001 pin label| Pin Function |Arduino Connection|ESP32 Connection|
10+
// |----------------- |:--------------------:|-----------------:|---------------:|
11+
// | MISO | Slave Out | D12 | 19 |
12+
// | MOSI | Slave In | D11 | 23 |
13+
// | SCLK | Serial Clock | D13 | 18 |
14+
// | CS | Chip Select | D7 | 5 |
15+
// | VCC | Digital VDD | +5V | +5V |
16+
// | GND | Digital Gnd | Gnd | Gnd |
17+
// | FCLK | 32K CLOCK | - | - |
18+
// | INT1 | Interrupt1 | 02 | 02 |
19+
// | INT2 | Interrupt2 | - | - |
2120
//
2221
// This software is licensed under the MIT License(http://opensource.org/licenses/MIT).
2322
//
@@ -29,12 +28,13 @@
2928
//
3029
// For information on how to use, visit https://github.com/Protocentral/protocentral_max30001
3130
//
31+
3232
/////////////////////////////////////////////////////////////////////////////////////////
3333

3434
#include <SPI.h>
3535
#include "protocentral_max30001.h"
3636

37-
#define MAX30001_CS_PIN 7
37+
#define MAX30001_CS_PIN 17
3838
#define MAX30001_DELAY_SAMPLES 8 // Time between consecutive samples
3939

4040
#define CES_CMDIF_PKT_START_1 0x0A
@@ -142,4 +142,4 @@ void loop()
142142
BioZSkipSample = false;
143143
}
144144
delay(MAX30001_DELAY_SAMPLES);
145-
}
145+
}
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
//////////////////////////////////////////////////////////////////////////////////////////
2+
//
3+
// Demo code for the MAX30001 breakout board
4+
//
5+
// This example plots the ECG through serial UART on openview processing GUI.
6+
// GUI URL: https://github.com/Protocentral/protocentral_openview.git
7+
//
8+
// Arduino connections:
9+
//
10+
// |MAX30001 pin label| Pin Function |Arduino Connection|ESP32 Connection|
11+
// |----------------- |:--------------------:|-----------------:|---------------:|
12+
// | MISO | Slave Out | D12 | 19 |
13+
// | MOSI | Slave In | D11 | 23 |
14+
// | SCLK | Serial Clock | D13 | 18 |
15+
// | CS | Chip Select | D7 | 5 |
16+
// | VCC | Digital VDD | +5V | +5V |
17+
// | GND | Digital Gnd | Gnd | Gnd |
18+
// | FCLK | 32K CLOCK | - | - |
19+
// | INT1 | Interrupt1 | 02 | 02 |
20+
// | INT2 | Interrupt2 | - | - |
21+
//
22+
// This software is licensed under the MIT License(http://opensource.org/licenses/MIT).
23+
//
24+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
25+
// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26+
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28+
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29+
//
30+
// For information on how to use, visit https://github.com/Protocentral/protocentral_max30001
31+
//
32+
/////////////////////////////////////////////////////////////////////////////////////////
33+
34+
#include <SPI.h>
35+
#include "protocentral_max30001.h"
36+
37+
#define MAX30001_CS_PIN 20
38+
#define MAX30001_DELAY_SAMPLES 8 // Time between consecutive samples
39+
40+
#define CES_CMDIF_PKT_START_1 0x0A
41+
#define CES_CMDIF_PKT_START_2 0xFA
42+
#define CES_CMDIF_TYPE_DATA 0x02
43+
#define CES_CMDIF_PKT_STOP 0x0B
44+
#define DATA_LEN 0x0C
45+
#define ZERO 0
46+
47+
volatile char DataPacket[DATA_LEN];
48+
const char DataPacketFooter[2] = {ZERO, CES_CMDIF_PKT_STOP};
49+
const char DataPacketHeader[5] = {CES_CMDIF_PKT_START_1, CES_CMDIF_PKT_START_2, DATA_LEN, ZERO, CES_CMDIF_TYPE_DATA};
50+
51+
uint8_t data_len = 0x0C;
52+
53+
MAX30001 max30001(MAX30001_CS_PIN);
54+
55+
signed long ecg_data;
56+
signed long bioz_data;
57+
58+
void sendData(signed long ecg_sample, signed long bioz_sample, bool _bioZSkipSample)
59+
{
60+
61+
DataPacket[0] = ecg_sample;
62+
DataPacket[1] = ecg_sample >> 8;
63+
DataPacket[2] = ecg_sample >> 16;
64+
DataPacket[3] = ecg_sample >> 24;
65+
66+
DataPacket[4] = bioz_sample;
67+
DataPacket[5] = bioz_sample >> 8;
68+
DataPacket[6] = bioz_sample >> 16;
69+
DataPacket[7] = bioz_sample >> 24;
70+
71+
if (_bioZSkipSample == false)
72+
{
73+
DataPacket[8] = 0x00;
74+
}
75+
else
76+
{
77+
DataPacket[8] = 0xFF;
78+
}
79+
80+
DataPacket[9] = 0x00; // max30001.heartRate >> 8;
81+
DataPacket[10] = 0x00;
82+
DataPacket[11] = 0x00;
83+
84+
// Send packet header (in ProtoCentral OpenView format)
85+
for (int i = 0; i < 5; i++)
86+
{
87+
Serial.write(DataPacketHeader[i]);
88+
}
89+
90+
// Send the data payload
91+
for (int i = 0; i < DATA_LEN; i++) // transmit the data
92+
{
93+
Serial.write(DataPacket[i]);
94+
}
95+
96+
// Send packet footer (in ProtoCentral OpenView format)
97+
for (int i = 0; i < 2; i++)
98+
{
99+
Serial.write(DataPacketFooter[i]);
100+
}
101+
}
102+
103+
bool BioZSkipSample = false;
104+
105+
void setup()
106+
{
107+
Serial.begin(57600); // Serial begin
108+
//SPI.begin();
109+
110+
111+
SPI.begin(10,8,7,20);
112+
113+
//SPI.
114+
115+
bool ret = max30001.max30001ReadInfo();
116+
if (ret)
117+
{
118+
Serial.println("MAX 30001 read ID Success");
119+
}
120+
else
121+
{
122+
while (!ret)
123+
{
124+
// stay here untill the issue is fixed.
125+
ret = max30001.max30001ReadInfo();
126+
Serial.println("Failed to read ID, please make sure all the pins are connected");
127+
delay(5000);
128+
}
129+
}
130+
131+
Serial.println("Initialising the chip ...");
132+
max30001.BeginECGBioZ(); // initialize MAX30001
133+
// max30001.Begin();
134+
}
135+
136+
void loop()
137+
{
138+
ecg_data = max30001.getECGSamples();
139+
// max30001.getHRandRR();
140+
if (BioZSkipSample == false)
141+
{
142+
bioz_data = max30001.getBioZSamples();
143+
sendData(ecg_data, bioz_data, BioZSkipSample);
144+
BioZSkipSample = true;
145+
}
146+
else
147+
{
148+
bioz_data = 0x00;
149+
sendData(ecg_data, bioz_data, BioZSkipSample);
150+
BioZSkipSample = false;
151+
}
152+
delay(8);
153+
}

0 commit comments

Comments
 (0)