Arduino MEGA 2560 cant run code

hello every one
im using Pulse Express Pulse-Ox & Heart Rate Sensor with MAX32664
with my arduino MEGA 2560

every time i connect the sensor and open serial monitor it says "Could not communicate with the sensor! please make proper connections"

but same connections on arduino uno works and post data on my serial monitor just fine

what i can do to make it work with my arduino MEGA 2560

the code :arrow_down:

#include <Wire.h>
#include "max32664.h"

#define RESET_PIN 04
#define MFIO_PIN 02
#define RAWDATA_BUFFLEN 250

max32664 MAX32664(RESET_PIN, MFIO_PIN, RAWDATA_BUFFLEN);


void mfioInterruptHndlr(){
  //Serial.println("i");
}

void enableInterruptPin(){

  //pinMode(mfioPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(MAX32664.mfioPin), mfioInterruptHndlr, FALLING);

}

void loadAlgomodeParameters(){

  algomodeInitialiser algoParameters;
  /*  Replace the predefined values with the calibration values taken with a reference spo2 device in a controlled environt.
      Please have a look here for more information, https://pdfserv.maximintegrated.com/en/an/an6921-measuring-blood-pressure-MAX32664D.pdf
      https://github.com/Protocentral/protocentral-pulse-express/blob/master/docs/SpO2-Measurement-Maxim-MAX32664-Sensor-Hub.pdf
  */

  algoParameters.calibValSys[0] = 120;
  algoParameters.calibValSys[1] = 122;
  algoParameters.calibValSys[2] = 125;

  algoParameters.calibValDia[0] = 80;
  algoParameters.calibValDia[1] = 81;
  algoParameters.calibValDia[2] = 82;

  algoParameters.spo2CalibCoefA = 1.5958422;
  algoParameters.spo2CalibCoefB = -34.659664;
  algoParameters.spo2CalibCoefC = 112.68987;

  MAX32664.loadAlgorithmParameters(&algoParameters);
}



void setup(){

  Serial.begin(57600);

  Wire.begin();

  loadAlgomodeParameters();

  int result = MAX32664.hubBegin();
  if (result == CMD_SUCCESS){
    Serial.println("Sensorhub begin!");
  }else{
    //stay here.
    while(1){
      Serial.println("Could not communicate with the sensor! please make proper connections");
      delay(5000);
    }
  }

  bool ret = MAX32664.startBPTcalibration();
  while(!ret){

    delay(10000);
    Serial.println("failed calib, please retsart");
    //ret = MAX32664.startBPTcalibration();
  }

  delay(1000);

  //Serial.println("start in estimation mode");
  ret = MAX32664.configAlgoInEstimationMode();
  while(!ret){

    //Serial.println("failed est mode");
    ret = MAX32664.configAlgoInEstimationMode();
    delay(10000);
  }

  //MAX32664.enableInterruptPin();
  Serial.println("Getting the device ready..");
  delay(1000);
}

void loop(){

  uint8_t num_samples = MAX32664.readSamples();

  if(num_samples){

    Serial.print("sys = ");
    Serial.print(MAX32664.max32664Output.sys);
    Serial.print(", dia = ");
    Serial.print(MAX32664.max32664Output.dia);
    Serial.print(", hr = ");
    Serial.print(MAX32664.max32664Output.hr);
    Serial.print(" spo2 = ");
    Serial.println(MAX32664.max32664Output.spo2);
  }

  delay(100);
}

How are you connecting the sensor to the Mega?
On an UNO, the I2C pins are on A4 & A5, and the pins labeled SDA & SCL.
On the Mega, the I2C pins are on pins 20 & 21, and the pins labeled SDA & SCL.

1 Like

Where are the I2C pins on the Mega? Yeah, beat me to it. I had this problem once, my not perfect but working solution was to jumper A4,5 to pin 20-21 and ensure that A4,A5 were configured for input.

1 Like

thanks

can the same connection be on arduino due ?
i tried but the same error message came thats why i switched to mega

When using any shield with any Arduino, you have to check every pin connection. Oh, wait... you don't have a shield, it's a module.

1 Like

due is 3.3v can it be use with 5v sensors like this one or MLX90614 IR Temperature Sensor

Ask the manufacturer. No supply voltage spec is listed with the link you provided. But from the schematic, I can see that it expects to run on 5V. So, not good for the Due.

Why can't you just connect to the correct I2C pins on the Mega?

Module schematic:
https://github.com/Protocentral/protocentral-pulse-express/blob/master/hardware/pc_pulse%20express_schematic.pdf

1 Like

Due uses pin 20 (SDA) and 21 (SCL), or the SDA1/SCL1 pins.
See the Wire library reference page Wire library

You generally do not want to directly connect 5V and 3.3V devices, there are I2C level shifters if needed.

1 Like

The device already has level shifters on board. So if you use external ones, you're shifting it twice.

i started the project with due but when i fined out that it can't run 5v sensors i got mega from a friend to see if it can run the sensor i mentioned and other sensors before buying mega

trying to avoid level shifters because i will use two sensors with this one and the other two operate on 5v
too many level shifters not helpful with the final design of the device

That would rule out the Due unless you can find a 3.3V version of the module.. What about the on board device voltages of the other sensors? If they also are 3.3V devices adapted for 5V, and your final project includes them on a PCB or something like that, you could just skip all the level shifting and use a Due or other 3.3V processor.

1 Like

or don't use due
i will buy mega because Nextion display and MLX90614 IR Temperature Sensor
the final design must be small

Well, a Mega is not exactly small, but you're the boss.

1 Like

Nextion display is not small too but the design should be small as possible

thank you very much for your help aarg and david_2018

Unfortunately the library for that device needs a substantial amount of ram, not much left to work with on an UNO/Nano.

1 Like

@moh2625, your topic has been moved to a more suitable location on the forum.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.