ESP32 connecting to MAX30003 ECG

Pangeranhuang
Posts: 2
Joined: Wed Mar 10, 2021 12:36 pm

ESP32 connecting to MAX30003 ECG

Postby Pangeranhuang » Wed Mar 10, 2021 12:46 pm

Hi guys, I'm currently working on a project detecting heart rate using MAX30003 Protocentral ECG Breakout sensor. When I tested the sensor using Arduino UNO it was working well. However, for connectivity reason I'm changing the MCU to ESP32 NodeMCU Devkit-1.

I use the code from Protocentral library. At first, the functions are working well until I push the EN button. It seems something has changed with MOSI, MISO, SCK, and CSB pinouts, and error message appears on the COM serial monitor.

Please any advice on how to making it work :)



  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<SPI.h>
  36. #include "protocentral_Max30003.h"
  37.  
  38. #define INT_PIN 04
  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. }

ESP_Sprite
Posts: 9746
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32 connecting to MAX30003 ECG

Postby ESP_Sprite » Thu Mar 11, 2021 3:20 am

No idea. What's the error message you get?

Pangeranhuang
Posts: 2
Joined: Wed Mar 10, 2021 12:36 pm

Re: ESP32 connecting to MAX30003 ECG

Postby Pangeranhuang » Thu Mar 11, 2021 5:24 am

The pins I use are GPIO 19 (MISO), 23 (MOSI), 18 (SCK), 5 (CS). There are no error messages but the pins are not sending signal to the microcontroller. I've tried changing the pins and the code as well, but nothing happens. When I move the project back to Arduino Uno, everything is working well.

ESP_Sprite
Posts: 9746
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32 connecting to MAX30003 ECG

Postby ESP_Sprite » Thu Mar 11, 2021 8:46 am

Without an error message, it's hard to say. Might be that that library isn't built to work well on platforms other than the AVR in the Uno.

somesh007
Posts: 1
Joined: Fri Apr 23, 2021 5:10 am

Re: ESP32 connecting to MAX30003 ECG

Postby somesh007 » Fri Apr 23, 2021 5:39 am

ESP_Sprite wrote:
Thu Mar 11, 2021 3:20 am
No idea. What's the error message you get?
collect2.exe: error: ld returned 1 exit status
Using library SPI at version 1.0 in folder: C:\Users\cokas\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.6\libraries\SPI
Using library ProtoCentral_MAX30003_ECG_AFE_Sensor_Library at version 1.0.1 in folder: C:\Users\cokas\OneDrive\Documents\Arduino\libraries\ProtoCentral_MAX30003_ECG_AFE_Sensor_Library
exit status 1
Error compiling for board ESP32 Wrover Module.

it was something like this can u please guide us on how to move forward with it
Attachments
Screenshot 2021-04-23 110127.jpg
this is error snapshot
Screenshot 2021-04-23 110127.jpg (267.87 KiB) Viewed 3844 times

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot], Majestic-12 [Bot] and 94 guests