mhamat
January 5, 2023, 5:13pm
1
Hi all
Im trying to connect two sensors (max30100 and mlx90614) to an arduino and view the output on an oled display.
The sketch:
#include <Wire.h>
#include <MAX30100_PulseOximeter.h>
#include <Adafruit_MLX90614.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define REPORTING_PERIOD_MS 1000
uint32_t tsLastReport = 0;
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
PulseOximeter pox;
Adafruit_SSD1306 oled;
void setup()
{
Serial.begin(9600);
mlx.begin();
pox.begin();
oled.begin();
oled.clearDisplay();
}
void loop()
{
// oled.clearDisplay();
pox.update();
if (millis() - tsLastReport > REPORTING_PERIOD_MS)
{
Serial.print("Heart rate = ");Serial.print(pox.getHeartRate());Serial.print(" BPM");
Serial.print(" SpO2 = ");Serial.print(pox.getSpO2());Serial.println(" %");
Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC());Serial.print("c");
Serial.print(" Object = "); Serial.print(mlx.readObjectTempC()); Serial.println("c");
Serial.println();
oled.setTextColor(WHITE);
oled.setCursor(0,0);
oled.print("Object = "); oled.print(mlx.readObjectTempC()); oled.println("c");
oled.print("SpO2 = ");oled.print(pox.getSpO2());oled.print(" %");
oled.display();
oled.clearDisplay();
tsLastReport = millis();
}
}
The problem:
this code will stop the max30100 from working and it won't read anything in the serial monitor:
Heart rate = 0.00 BPM SpO2 = 0 %
Ambient = 29.25c Object = 27.85c
but the mlx90614 works fine
when removing
oled.display();
oled.clearDisplay();
the sketch works fine and the values appear correct in the serial monitor, but of course, nothing displays on the oled
something to do with the oled.begin(); effecting the max30100
or could it be that the Arduino doesn't have enough F memory to handle two sensors and an oled display at the same time?
the sketch is using a bit more than half the memory:
Sketch uses 19660 bytes (60%) of program storage space. Maximum is 32256 bytes.
Global variables use 849 bytes (41%) of dynamic memory, leaving 1199 bytes for local variables. Maximum is 2048 bytes.
NOTE : already changed the max30100 bus speed to 100000UL
1 Like
horace
January 5, 2023, 5:17pm
2
what Arduino are you using?
upload a schematic showing the wiring
pylon
January 5, 2023, 5:19pm
3
... for the global variables! The display buffer will use half of the available memory on top, so you're running out of memory.
I2C scanner
What did the I2C scanner report?
Thanks for posting the code in code tags.
mhamat
January 5, 2023, 5:23pm
6
So you think the problem is with the Arduino and not the code?
Will getting an Arduino Mega solve it?
Look at the u8g2 library for the OLED, using a page buffer instead of a full buffer will use considerably less ram.
mhamat
January 5, 2023, 5:24pm
8
Scanning...
I2C device found at address 0x3C !
I2C device found at address 0x57 !
I2C device found at address 0x5A !
done
Cool, Now we know the 3 devices are being 'seen'.
Now to play the pull up resistor game. Do you have 2.2K to 4.7K ohm resistors? Put one on the SCL line to Vcc and one on the SDL line to Vcc.
mhamat
January 5, 2023, 5:29pm
11
Now to play the pull up resistor game. Do you have 2.2K to 4.7K ohm resistors? Put one on the SCL line to Vcc and one on the SDL line to Vcc.
do you mean short circuit the SCL and SDA lines to the VCC using a resistor?
I do not mean for you to short circuit Vcc to anything.
Pull up resistors.
mhamat
January 5, 2023, 5:37pm
14
unfortunately no luck
the same thing
Heart rate = 0.00 BPM SpO2 = 0 %
Ambient = 29.21c Object = 27.81c
leave the circuit wired as is but comment out the code for the mlx, does the pox porduce results?
void setup()
{
Serial.begin(9600);
if (!mlx.begin()) {
Serial.println("Error connecting to MLX sensor. Check wiring.");
while (1);
};
pox.begin();
oled.begin();
oled.clearDisplay();
}
add in tests to see which device is not starting up.
this is code to test the max thingy
/*
Arduino-MAX30100 oximetry / heart rate integrated sensor library
Copyright (C) 2017 OXullo Intersecans <x@brainrapers.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// This example can be used to test connectivity and operation of the sensor
// check the README file on the repo's root for a troubleshooting guide in case
This file has been truncated. show original
code to test the oled
/**************************************************************************
This is an example for our Monochrome OLEDs based on SSD1306 drivers
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/category/63_98
This example is for a 128x32 pixel display using I2C to communicate
3 pins are required to interface (two I2C and one reset).
Adafruit invests time and resources providing this open
source code, please support Adafruit and open-source
hardware by purchasing products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries,
with contributions from the open source community.
BSD license, check license.txt for more information
All text above, and the splash screen below must be
included in any redistribution.
**************************************************************************/
This file has been truncated. show original
also the max thingy requires more setup parameters then your code shows,
/*
Arduino-MAX30100 oximetry / heart rate integrated sensor library
Copyright (C) 2017 OXullo Intersecans <x@brainrapers.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// This example can be used to test connectivity and operation of the sensor
// check the README file on the repo's root for a troubleshooting guide in case
This file has been truncated. show original
post an image of the project.
If you are using a 9V battery like this.
Don't.
mhamat
January 5, 2023, 6:20pm
20
test of the max 30100 :
IR=3 RED=22
IR=0 RED=16
IR=2 RED=17
IR=0 RED=24
IR=0 RED=9
IR=2 RED=15
IR=0 RED=16
IR=0 RED=10
IR=0 RED=22
IR=0 RED=8
IR=5 RED=14
IR=0 RED=18
IR=0 RED=8
IR=0 RED=26
IR=0 RED=8
IR=5 RED=16
IR=0 RED=18
IR=0 RED=11
IR=0 RED=17
IR=0 RED=16
IR=0 RED=12
IR=1 RED=16
IR=0 RED=19
IR=0 RED=18
test of the oled: ok
could you post your most recent code in a post below this one?