Hello friends of the community. I spend a lot of time trying to solve this issue and I hope you can help me. I'm ussing the library from this link https://github.com/oxullo/Arduino-MAX30100 in order to implement my project. The arduino code executes quite well, but when I try to receive data from the serial port, who's connected to an HC-05, I can't concatenate the data when pox.update() is present in the loop, the data received is like:
R
o
b
e
r
t
o
A
n
d
r
e
s
So I need to cancatenate it to shows it in a 128x64 oled display. Moreover, the if (incomingByte == 'T')
condition seems not to be executed, as it the oled display doesn't show the getStringfromProgMem(3)
char. The loop code is:
void loop() {
if (Serial.available() > 0) {
incomingByte = Serial.read();
if (incomingByte == 'T') {
palabra = getStringfromProgMem(3);
c = 0;
} else {
palabra.concat(incomingByte);
}
}
pox.update();
display.clearDisplay();
estado = digitalRead(STATE);
estado ? (enlace()) : (noenlace());
unsigned long tiempoActual = millis();
if (tiempoActual - tiempoAnterior >= intervaloEvento) {
rate = pox.getHeartRate();
spo = pox.getSpO2();
if (rate && palabra != getStringfromProgMem(3)) {
c++;
}
if (c == 60) {
c = 0;
}
/*Serial.print(rate);
Serial.print(',');
Serial.print(spo);
Serial.print(',');
Serial.println(c);*/
tiempoAnterior = tiempoActual;
}
mostrar(rate, 15, 35);
mostrar(spo, 105, 35);
mostrar(getStringfromProgMem(0), 10, 52);
mostrar(getStringfromProgMem(1), 100, 52);
/*outputValue = (VERF * analogRead(ANALOG)) / 1024;
smoothedVal = smoothedVal + ((outputValue - smoothedVal) / SAMPLES);
comparacion(smoothedVal);*/
//
display.display();
}
The code shows just the first letter in the oled display and ignores the others. I'm using this libraries also:
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "MAX30100_PulseOximeter.h"
#include <avr/pgmspace.h>
And I declarate the variables "incomingByte" and "palabra" as globals:
char incomingByte;
String palabra="";
The code palabra.concat(incomingByte)
executes well without the "pox.update()" method. What I'm doing wrong?
I think that I solved it. The issue was generated due a memory leak of my Arduino. When I tried to concatenate the String "palabra", the Arduino simply didn't do it because of a memory leak. If any of you have troubles handling the Strings and the Arduino simply doesn't concatenate your strings, I suggest visit this site:
https://www.best-microcontroller-projects.com/arduino-string.html
Now I can't realice how to handle the c-strings but is question of time.
Any of you have an idea how to clean the
static char palabra[15], *pSdata = palabra;
?When I use strings is simply to write
palabra="";
. But now, I have no idea how to do it. I hope you can help me.Greetings.