├── .gitignore ├── .DS_Store ├── assets ├── body.png ├── max30003_brk.jpg └── gif-max30003-openview.gif ├── hardware ├── .DS_Store ├── pc_max30003_brk.pdf └── pc_max30003_brk.zip ├── library.properties ├── src ├── protocentral_Max30003.h └── protocentral_Max30003.cpp ├── LICENSE.md ├── examples ├── Example2-ECG-stream-Arduino-Plotter │ └── Example2-ECG-stream-Arduino-Plotter.ino ├── Example3-Computation-only │ └── Example3-Computation-only.ino └── Example1-ECG-stream-Openview │ └── Example1-ECG-stream-Openview.ino ├── README.md └── license_mark.svg /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shivasiddharth/protocentral_max30003/master/.DS_Store -------------------------------------------------------------------------------- /assets/body.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shivasiddharth/protocentral_max30003/master/assets/body.png -------------------------------------------------------------------------------- /hardware/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shivasiddharth/protocentral_max30003/master/hardware/.DS_Store -------------------------------------------------------------------------------- /assets/max30003_brk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shivasiddharth/protocentral_max30003/master/assets/max30003_brk.jpg -------------------------------------------------------------------------------- /hardware/pc_max30003_brk.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shivasiddharth/protocentral_max30003/master/hardware/pc_max30003_brk.pdf -------------------------------------------------------------------------------- /hardware/pc_max30003_brk.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shivasiddharth/protocentral_max30003/master/hardware/pc_max30003_brk.zip -------------------------------------------------------------------------------- /assets/gif-max30003-openview.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shivasiddharth/protocentral_max30003/master/assets/gif-max30003-openview.gif -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=ProtoCentral MAX30003 ECG AFE Sensor Library 2 | version=1.0.2 3 | author=ProtoCentral Electronics 4 | maintainer=ProtoCentral Electronics 5 | sentence=Library for the ProtoCentral MAX30003 Single lead ECG breakout board. 6 | paragraph=The MAX30003 chip from Maxim is a single-lead ECG analog front-end, which also includes R-R (heartbeat) detection. 7 | category=Sensors 8 | url=https://github.com/Protocentral/protocentral_max30003 9 | architectures=* -------------------------------------------------------------------------------- /src/protocentral_Max30003.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Demo code for the MAX30003 breakout board 4 | // 5 | // Copyright (c) 2020 ProtoCentral 6 | // 7 | // This software is licensed under the MIT License(http://opensource.org/licenses/MIT). 8 | // 9 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 10 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 11 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 12 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 13 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 14 | // 15 | // For information on how to use, visit https://github.com/Protocentral/protocentral-max30003-arduino 16 | // 17 | ///////////////////////////////////////////////////////////////////////////////////////// 18 | 19 | 20 | #ifndef protocentral_Max30003.h 21 | #define protocentral_Max30003.h 22 | 23 | #include 24 | 25 | #define WREG 0x00 26 | #define RREG 0x01 27 | 28 | #define NO_OP 0x00 29 | #define STATUS 0x01 30 | #define EN_INT 0x02 31 | #define EN_INT2 0x03 32 | #define MNGR_INT 0x04 33 | #define MNGR_DYN 0x05 34 | #define SW_RST 0x08 35 | #define SYNCH 0x09 36 | #define FIFO_RST 0x0A 37 | #define INFO 0x0F 38 | #define CNFG_GEN 0x10 39 | #define CNFG_CAL 0x12 40 | #define CNFG_EMUX 0x14 41 | #define CNFG_ECG 0x15 42 | #define CNFG_RTOR1 0x1D 43 | #define CNFG_RTOR2 0x1E 44 | #define ECG_FIFO_BURST 0x20 45 | #define ECG_FIFO 0x21 46 | #define RTOR 0x25 47 | #define NO_OP 0x7F 48 | 49 | #define MAX30003_CS_PIN 7 50 | #define CLK_PIN 6 51 | #define RTOR_INTR_MASK 0x04 52 | 53 | typedef enum 54 | { 55 | SAMPLINGRATE_128 = 128, SAMPLINGRATE_256 = 256, SAMPLINGRATE_512 = 512 56 | }sampRate; 57 | 58 | class MAX30003 59 | { 60 | public: 61 | unsigned int heartRate; 62 | unsigned int RRinterval; 63 | signed long ecgdata; 64 | 65 | void max30003Begin(); 66 | void max30003BeginRtorMode(); 67 | void max30003SwReset(void); 68 | void getHRandRR(void); 69 | void getEcgSamples(void); 70 | bool max30003ReadInfo(void); 71 | void max30003SetsamplingRate(uint16_t samplingRate); 72 | void max30003RegRead(uint8_t Reg_address, uint8_t * buff); 73 | 74 | private: 75 | 76 | void max30003ReadData(int num_samples, uint8_t * readBuffer); 77 | 78 | void max30003Synch(void); 79 | void max30003RegWrite (unsigned char WRITE_ADDRESS, unsigned long data); 80 | }; 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | License Information 2 | =================== 3 | 4 | Hardware 5 | --------- 6 | 7 | **All hardware is released under the [CERN-OHL-P v2](https://ohwr.org/cern_ohl_p_v2.txt).** license. 8 | 9 | Copyright CERN 2020. 10 | 11 | This source describes Open Hardware and is licensed under the CERN-OHL-P v2. 12 | 13 | You may redistribute and modify this documentation and make products 14 | using it under the terms of the CERN-OHL-P v2 (https:/cern.ch/cern-ohl). 15 | This documentation is distributed WITHOUT ANY EXPRESS OR IMPLIED 16 | WARRANTY, INCLUDING OF MERCHANTABILITY, SATISFACTORY QUALITY 17 | AND FITNESS FOR A PARTICULAR PURPOSE. Please see the CERN-OHL-P v2 18 | for applicable conditions 19 | 20 | Software 21 | -------- 22 | 23 | **All software is released under the MIT License(http://opensource.org/licenses/MIT).** 24 | 25 | The MIT License (MIT) 26 | 27 | Copyright (c) 2019 ProtoCentral 28 | 29 | Permission is hereby granted, free of charge, to any person obtaining a copy 30 | of this software and associated documentation files (the "Software"), to deal 31 | in the Software without restriction, including without limitation the rights 32 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 33 | copies of the Software, and to permit persons to whom the Software is 34 | furnished to do so, subject to the following conditions: 35 | 36 | The above copyright notice and this permission notice shall be included in all 37 | copies or substantial portions of the Software. 38 | 39 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 40 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 41 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 42 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 43 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 44 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 45 | SOFTWARE. 46 | 47 | Documentation 48 | ------------- 49 | **All documentation is released under [Creative Commons Share-alike 4.0 International](http://creativecommons.org/licenses/by-sa/4.0/).** 50 | ![CC-BY-SA-4.0](https://i.creativecommons.org/l/by-sa/4.0/88x31.png) 51 | 52 | You are free to: 53 | 54 | * Share — copy and redistribute the material in any medium or format 55 | * Adapt — remix, transform, and build upon the material for any purpose, even commercially. 56 | The licensor cannot revoke these freedoms as long as you follow the license terms. 57 | 58 | Under the following terms: 59 | 60 | * Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. 61 | * ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original. 62 | 63 | Please check [*LICENSE.md*](LICENSE.md) for detailed license descriptions. -------------------------------------------------------------------------------- /examples/Example2-ECG-stream-Arduino-Plotter/Example2-ECG-stream-Arduino-Plotter.ino: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Demo code for the MAX30003 breakout board 4 | // 5 | // This example plots the ECG through Arduino Plotter. 6 | // GUI URL: https://github.com/Protocentral/protocentral_openview.git 7 | // 8 | // Arduino connections: 9 | // 10 | // |MAX30003 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 | - | 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_max30003 31 | // 32 | ///////////////////////////////////////////////////////////////////////////////////////// 33 | 34 | #include 35 | #include "protocentral_Max30003.h" 36 | 37 | MAX30003 max30003; 38 | 39 | 40 | void setup() 41 | { 42 | Serial.begin(57600); //Serial begin 43 | 44 | pinMode(MAX30003_CS_PIN,OUTPUT); 45 | digitalWrite(MAX30003_CS_PIN,HIGH); //disable device 46 | 47 | SPI.begin(); 48 | SPI.setBitOrder(MSBFIRST); 49 | SPI.setDataMode(SPI_MODE0); 50 | 51 | bool ret = max30003.max30003ReadInfo(); 52 | if(ret){ 53 | Serial.println("Max30003 read ID Success"); 54 | }else{ 55 | 56 | while(!ret){ 57 | //stay here untill the issue is fixed. 58 | ret = max30003.max30003ReadInfo(); 59 | Serial.println("Failed to read ID, please make sure all the pins are connected"); 60 | delay(10000); 61 | } 62 | } 63 | 64 | Serial.println("Initialising the chip ..."); 65 | max30003.max30003Begin(); // initialize MAX30003 66 | } 67 | 68 | void loop() 69 | { 70 | max30003.getEcgSamples(); //It reads the ecg sample and stores it to max30003.ecgdata . 71 | 72 | Serial.println(max30003.ecgdata); 73 | delay(8); 74 | } 75 | -------------------------------------------------------------------------------- /examples/Example3-Computation-only/Example3-Computation-only.ino: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Demo code for the MAX30003 breakout board 4 | // 5 | // This example displays heart rate and rr interval through arduino serial port. 6 | // 7 | // GUI URL: https://github.com/Protocentral/protocentral_openview.git 8 | // 9 | // Arduino connections: 10 | // 11 | // |MAX30003 pin label| Pin Function |Arduino Connection| 12 | // |----------------- |:--------------------:|-----------------:| 13 | // | MISO | Slave Out | D12 | 14 | // | MOSI | Slave In | D11 | 15 | // | SCLK | Serial Clock | D13 | 16 | // | CS | Chip Select | D7 | 17 | // | VCC | Digital VDD | +5V | 18 | // | GND | Digital Gnd | Gnd | 19 | // | FCLK | 32K CLOCK | - | 20 | // | INT1 | Interrupt1 | 02 | 21 | // | INT2 | Interrupt2 | - | 22 | // 23 | // This software is licensed under the MIT License(http://opensource.org/licenses/MIT). 24 | // 25 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 26 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 27 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 28 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 29 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 30 | // 31 | // For information on how to use, visit https://github.com/Protocentral/protocentral_max30003 32 | // 33 | ///////////////////////////////////////////////////////////////////////////////////////// 34 | 35 | #include 36 | #include "protocentral_Max30003.h" 37 | 38 | #define INT_PIN 02 39 | 40 | MAX30003 max30003; 41 | bool rtorIntrFlag = false; 42 | uint8_t statusReg[3]; 43 | 44 | 45 | void rtorInterruptHndlr(){ 46 | rtorIntrFlag = true; 47 | } 48 | 49 | 50 | void enableInterruptPin(){ 51 | 52 | pinMode(INT_PIN, INPUT_PULLUP); 53 | attachInterrupt(digitalPinToInterrupt(INT_PIN), rtorInterruptHndlr, CHANGE); 54 | } 55 | 56 | void setup() 57 | { 58 | Serial.begin(115200); //Serial begin 59 | 60 | pinMode(MAX30003_CS_PIN,OUTPUT); 61 | digitalWrite(MAX30003_CS_PIN,HIGH); //disable device 62 | 63 | SPI.begin(); 64 | SPI.setBitOrder(MSBFIRST); 65 | SPI.setDataMode(SPI_MODE0); 66 | 67 | bool ret = max30003.max30003ReadInfo(); 68 | if(ret){ 69 | Serial.println("Max30003 ID Success"); 70 | }else{ 71 | 72 | while(!ret){ 73 | //stay here untill the issue is fixed. 74 | ret = max30003.max30003ReadInfo(); 75 | Serial.println("Failed to read ID, please make sure all the pins are connected"); 76 | delay(5000); 77 | } 78 | } 79 | 80 | Serial.println("Initialising the chip ..."); 81 | max30003.max30003BeginRtorMode(); // initialize MAX30003 82 | enableInterruptPin(); 83 | max30003.max30003RegRead(STATUS, statusReg); 84 | } 85 | 86 | void loop() 87 | { 88 | if(rtorIntrFlag){ 89 | rtorIntrFlag = false; 90 | max30003.max30003RegRead(STATUS, statusReg); 91 | 92 | if(statusReg[1] & RTOR_INTR_MASK){ 93 | 94 | max30003.getHRandRR(); //It will store HR to max30003.heartRate and rr to max30003.RRinterval. 95 | Serial.print("Heart Rate = "); 96 | Serial.println(max30003.heartRate); 97 | 98 | Serial.print("RR interval = "); 99 | Serial.println(max30003.RRinterval); 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /examples/Example1-ECG-stream-Openview/Example1-ECG-stream-Openview.ino: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Demo code for the MAX30003 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 | // |MAX30003 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 | - | 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_max30003 31 | // 32 | ///////////////////////////////////////////////////////////////////////////////////////// 33 | 34 | #include 35 | #include "protocentral_Max30003.h" 36 | 37 | #define CES_CMDIF_PKT_START_1 0x0A 38 | #define CES_CMDIF_PKT_START_2 0xFA 39 | #define CES_CMDIF_TYPE_DATA 0x02 40 | #define CES_CMDIF_PKT_STOP 0x0B 41 | #define DATA_LEN 0x0C 42 | #define ZERO 0 43 | 44 | volatile char DataPacket[DATA_LEN]; 45 | const char DataPacketFooter[2] = {ZERO, CES_CMDIF_PKT_STOP}; 46 | const char DataPacketHeader[5] = {CES_CMDIF_PKT_START_1, CES_CMDIF_PKT_START_2, DATA_LEN, ZERO, CES_CMDIF_TYPE_DATA}; 47 | 48 | uint8_t data_len = 0x0C; 49 | 50 | MAX30003 max30003; 51 | 52 | void sendDataThroughUART(void){ 53 | 54 | DataPacket[5] = max30003.ecgdata; 55 | DataPacket[6] = max30003.ecgdata>>8; 56 | DataPacket[7] = max30003.ecgdata>>16; 57 | DataPacket[8] = max30003.ecgdata>>24; 58 | 59 | DataPacket[9] = max30003.RRinterval ; 60 | DataPacket[10] = max30003.RRinterval >>8; 61 | DataPacket[11] = 0x00; 62 | DataPacket[12] = 0x00; 63 | 64 | DataPacket[13] = max30003.heartRate ; 65 | DataPacket[14] = max30003.heartRate >>8; 66 | DataPacket[15] = 0x00; 67 | DataPacket[16] = 0x00; 68 | 69 | //send packet header 70 | for(int i=0; i<5; i++){ 71 | 72 | Serial.write(DataPacketHeader[i]); 73 | } 74 | 75 | //send 30003 data 76 | for(int i=0; i 32 | #include "protocentral_Max30003.h" 33 | 34 | void MAX30003::max30003RegWrite (unsigned char WRITE_ADDRESS, unsigned long data) 35 | { 36 | // now combine the register address and the command into one byte: 37 | byte dataToSend = (WRITE_ADDRESS<<1) | WREG; 38 | 39 | // take the chip select low to select the device: 40 | digitalWrite(MAX30003_CS_PIN, LOW); 41 | 42 | delay(2); 43 | SPI.transfer(dataToSend); 44 | SPI.transfer(data>>16); 45 | SPI.transfer(data>>8); 46 | SPI.transfer(data); 47 | delay(2); 48 | 49 | // take the chip select high to de-select: 50 | digitalWrite(MAX30003_CS_PIN, HIGH); 51 | } 52 | 53 | 54 | void MAX30003::max30003SwReset(void) 55 | { 56 | max30003RegWrite(SW_RST,0x000000); 57 | delay(100); 58 | } 59 | 60 | void MAX30003::max30003Synch(void) 61 | { 62 | max30003RegWrite(SYNCH,0x000000); 63 | } 64 | 65 | void MAX30003::max30003RegRead(uint8_t Reg_address, uint8_t * buff) 66 | { 67 | uint8_t spiTxBuff; 68 | 69 | digitalWrite(MAX30003_CS_PIN, LOW); 70 | 71 | spiTxBuff = (Reg_address<<1 ) | RREG; 72 | SPI.transfer(spiTxBuff); //Send register location 73 | 74 | for ( int i = 0; i < 3; i++) 75 | { 76 | buff[i] = SPI.transfer(0xff); 77 | } 78 | 79 | digitalWrite(MAX30003_CS_PIN, HIGH); 80 | } 81 | 82 | bool MAX30003::max30003ReadInfo(void) 83 | { 84 | uint8_t spiTxBuff; 85 | uint8_t readBuff[4] ; 86 | 87 | digitalWrite(MAX30003_CS_PIN, LOW); 88 | 89 | spiTxBuff = (INFO << 1 ) | RREG; 90 | SPI.transfer(spiTxBuff); //Send register location 91 | 92 | for ( int i = 0; i < 3; i++) 93 | { 94 | readBuff[i] = SPI.transfer(0xff); 95 | } 96 | 97 | digitalWrite(MAX30003_CS_PIN, HIGH); 98 | 99 | if((readBuff[0]&0xf0) == 0x50 ){ 100 | 101 | Serial.println("max30003 is ready"); 102 | Serial.print("Rev ID: "); 103 | Serial.println((readBuff[0]&0xf0)); 104 | 105 | return true; 106 | }else{ 107 | 108 | Serial.println("max30003 read info error\n"); 109 | return false; 110 | } 111 | 112 | return false; 113 | } 114 | 115 | void MAX30003::max30003ReadData(int num_samples, uint8_t * readBuffer) 116 | { 117 | uint8_t spiTxBuff; 118 | digitalWrite(MAX30003_CS_PIN, LOW); 119 | 120 | spiTxBuff = (ECG_FIFO_BURST<<1 ) | RREG; 121 | SPI.transfer(spiTxBuff); //Send register location 122 | 123 | for ( int i = 0; i < num_samples*3; ++i) 124 | { 125 | readBuffer[i] = SPI.transfer(0x00); 126 | } 127 | 128 | digitalWrite(MAX30003_CS_PIN, HIGH); 129 | } 130 | 131 | void MAX30003::max30003Begin() 132 | { 133 | max30003SwReset(); 134 | delay(100); 135 | max30003RegWrite(CNFG_GEN, 0x081007); 136 | delay(100); 137 | max30003RegWrite(CNFG_CAL, 0x720000); // 0x700000 138 | delay(100); 139 | max30003RegWrite(CNFG_EMUX,0x0B0000); 140 | delay(100); 141 | max30003RegWrite(CNFG_ECG, 0x805000); // d23 - d22 : 10 for 250sps , 00:500 sps 142 | delay(100); 143 | 144 | max30003RegWrite(CNFG_RTOR1,0x3fc600); 145 | max30003Synch(); 146 | delay(100); 147 | } 148 | 149 | void MAX30003::max30003BeginRtorMode() 150 | { 151 | max30003SwReset(); 152 | delay(100); 153 | max30003RegWrite(CNFG_GEN, 0x080004); 154 | delay(100); 155 | max30003RegWrite(CNFG_CAL, 0x720000); // 0x700000 156 | delay(100); 157 | max30003RegWrite(CNFG_EMUX,0x0B0000); 158 | delay(100); 159 | max30003RegWrite(CNFG_ECG, 0x805000); // d23 - d22 : 10 for 250sps , 00:500 sps 160 | delay(100); 161 | max30003RegWrite(CNFG_RTOR1,0x3fc600); 162 | delay(100); 163 | max30003RegWrite(EN_INT, 0x000401); 164 | delay(100); 165 | max30003Synch(); 166 | delay(100); 167 | } 168 | 169 | //not tested 170 | void MAX30003::max30003SetsamplingRate(uint16_t samplingRate) 171 | { 172 | uint8_t regBuff[4] = {0}; 173 | max30003RegRead(CNFG_ECG, regBuff); 174 | 175 | switch(samplingRate){ 176 | case SAMPLINGRATE_128: 177 | regBuff[0] = (regBuff[0] | 0x80 ); 178 | break; 179 | 180 | case SAMPLINGRATE_256: 181 | regBuff[0] = (regBuff[0] | 0x40 ); 182 | break; 183 | 184 | case SAMPLINGRATE_512: 185 | regBuff[0] = (regBuff[0] | 0x00 ); 186 | break; 187 | 188 | default : 189 | Serial.println("Wrong samplingRate, please choose between 128, 256 or 512"); 190 | break; 191 | } 192 | 193 | unsigned long cnfgEcg; 194 | memcpy(&cnfgEcg, regBuff, 4); 195 | 196 | Serial.print(" cnfg ECG "); 197 | Serial.println((cnfgEcg)); 198 | max30003RegWrite(CNFG_ECG, (cnfgEcg >> 8)); 199 | } 200 | 201 | void MAX30003::getEcgSamples(void) 202 | { 203 | uint8_t regReadBuff[4]; 204 | max30003RegRead(ECG_FIFO, regReadBuff); 205 | 206 | unsigned long data0 = (unsigned long) (regReadBuff[0]); 207 | data0 = data0 <<24; 208 | unsigned long data1 = (unsigned long) (regReadBuff[1]); 209 | data1 = data1 <<16; 210 | unsigned long data2 = (unsigned long) (regReadBuff[2]); 211 | data2 = data2 >>6; 212 | data2 = data2 & 0x03; 213 | 214 | unsigned long data = (unsigned long) (data0 | data1 | data2); 215 | ecgdata = (signed long) (data); 216 | } 217 | 218 | 219 | void MAX30003::getHRandRR(void) 220 | { 221 | uint8_t regReadBuff[4]; 222 | max30003RegRead(RTOR, regReadBuff); 223 | 224 | unsigned long RTOR_msb = (unsigned long) (regReadBuff[0]); 225 | unsigned char RTOR_lsb = (unsigned char) (regReadBuff[1]); 226 | unsigned long rtor = (RTOR_msb<<8 | RTOR_lsb); 227 | rtor = ((rtor >>2) & 0x3fff) ; 228 | 229 | float hr = 60 /((float)rtor*0.0078125); 230 | heartRate = (unsigned int)hr; 231 | 232 | unsigned int RR = (unsigned int)rtor* (7.8125) ; //8ms 233 | RRinterval = RR; 234 | } 235 | -------------------------------------------------------------------------------- /license_mark.svg: -------------------------------------------------------------------------------- 1 | 2 | image/svg+xmlOpen Source Licenses HardwareSoftwareDocumentationCERN-OHL-P-2.0MITCC-BY-SA-4.0 3 | --------------------------------------------------------------------------------