To understand where the problem could come from, I have tried the following code, that prints both the values of the MAX30100 sensor and the analog read from the linechart basic example.
#include <Wire.h>
#include "MAX30100.h"
#include"seeed_line_chart.h" //include the library
TFT_eSPI tft;
#define max_size 30 //maximum size of data
doubles data; //Initilising a doubles type to store data
int brightness;
TFT_eSprite spr = TFT_eSprite(&tft); // Sprite
// Sampling is tightly related to the dynamic range of the ADC.
// refer to the datasheet for further info
#define SAMPLING_RATE MAX30100_SAMPRATE_100HZ
// The LEDs currents must be set to a level that avoids clipping and maximises the
// dynamic range
#define IR_LED_CURRENT MAX30100_LED_CURR_50MA
#define RED_LED_CURRENT MAX30100_LED_CURR_27_1MA
// The pulse width of the LEDs driving determines the resolution of
// the ADC (which is a Sigma-Delta).
// set HIGHRES_MODE to true only when setting PULSE_WIDTH to MAX30100_SPC_PW_1600US_16BITS
#define PULSE_WIDTH MAX30100_SPC_PW_1600US_16BITS
#define HIGHRES_MODE true
// Instantiate a MAX30100 sensor class
MAX30100 sensor;
uint16_t vIR, vR;
void setup() {
Serial.begin(115200);
Serial.print("Initializing MAX30100..");
// Initialize the sensor
// Failures are generally due to an improper I2C wiring, missing power supply
// or wrong target chip
if (!sensor.begin()) {
Serial.println("FAILED");
for(;;);
} else {
Serial.println("SUCCESS");
}
// Set up the wanted parameters
sensor.setMode(MAX30100_MODE_SPO2_HR);
sensor.setLedsCurrent(IR_LED_CURRENT, RED_LED_CURRENT);
sensor.setLedsPulseWidth(PULSE_WIDTH);
sensor.setSamplingRate(SAMPLING_RATE);
sensor.setHighresModeEnabled(HIGHRES_MODE);
pinMode(A0, INPUT);
// tft.begin();
// spr.createSprite(TFT_HEIGHT,TFT_WIDTH);
// spr.setRotation(3);
// tft.setRotation(3);
}
void loop() {
sensor.update();
if (sensor.getRawValues(&vIR, &vR)) {
}
Serial.print("IR \t");
Serial.print(vIR);
Serial.print("\t R \t");
Serial.println(vR);
// spr.fillSprite(TFT_WHITE);
brightness = analogRead(A0);
//
// if (data.size() == max_size) {
// data.pop();//this is used to remove the first read variable
// }
// data.push(brightness); //read variables and store in data
//
Serial.print("brightness \t");
Serial.println(brightness);
//
// //Settings for the line graph title
// auto header = text(0, 0)
// .value("Light Sensor Readings")
// .align(center)
// .valign(vcenter)
// .width(tft.width())
// .thickness(2);
//
// header.height(header.font_height() * 2);
// header.draw(); //Header height is the twice the height of the font
//
// //Settings for the line graph
// auto content = line_chart(20, header.height()); //(x,y) where the line graph begins
// content
// .height(tft.height() - header.height() * 1.5) //actual height of the line chart
// .width(tft.width() - content.x() * 2) //actual width of the line chart
// .based_on(0.0) //Starting point of y-axis, must be a float
// .show_circle(false) //drawing a cirle at each point, default is on.
// .value(data) //passing through the data to line graph
// .color(TFT_RED) //Setting the color for the line
// .draw();
// spr.pushSprite(0, 0);
delay(100);
}
One first thing that I don't understand is why the vIR and vR are not printed if the following lines are left inside the if (sensor.getRawValues(&vIR, &vR)) loop.
Serial.print("IR \t");
Serial.print(vIR);
Serial.print("\t R \t");
Serial.println(vR);
My second point is that if I uncomment the line tft.begin(); in the void setup, the vIR and vR values become equal to zero. Is there an incompatibility between the getRawValue function of MAX30100lib and the TFT_eSPI library?
I would be grateful for any help.