Go Down

Topic: Help on how to use a spo2 sensor using software serial  (Read 425 times) previous topic - next topic

shreya_marwaha

Hi

I am working on Maxim MAXREFDES117# sensor for the determination of the PPG signal.The arduino code can be found on the link below:
https://github.com/MaximIntegratedRefDesTeam/RD117_ARDUINO/blob/master/RD117_ARDUINO.ino
The problem  is i want to use the sensor using 'Software Serial' or 'Altsoftserial' as I have to interface a graphic LCD with a different baud rate (9600)then sensor's baud rate(115200).

Even I too tried working and luckily the code gets compiled and uploaded successfully,Also the sensor gets power but no output is shown on the serial monitor

Could you please help me with how can I  use Software Serial and altsoftserial with the sensor.

P.S. The sensor works well without the use of software serial.

pylon

That reference design includes a MAX30102 which is controlled using I2C. Why do you want to use that horrible SoftwareSerial? The code you referred to uses the hardware serial to control the display at 115200. Which component uses 9600 baud?

Just in case: SoftwareSerial will not work at 115200, no chance to get the timing right. At least I'm not aware of any device that is that tolerant in timing to accept such output and if it exists, it will never be reliable.

shreya_marwaha

#2
Nov 10, 2017, 07:23 am Last Edit: Nov 10, 2017, 07:43 am by shreya_marwaha
Hi Pylon

Thanks for replying

Actually I tried working on the altsoftserial library and was successfully able to compile the code but now I wish to connect a 4D systems uLCD 43PT for display which work on 9600 baud rate . Also when I try compiling the code using the display libraries the display the output is shown as in picture attached.

also when the plot starts on the display the sensor starts to give absurd values in serial monitor can you please let me know the reason for it

Early reply will be highly appreciated

Thanks in advance
Shreya

shreya_marwaha


pylon

Quote
Actually I tried working on the altsoftserial library and was successfully able to compile the code but now I wish to connect a 4D systems uLCD 43PT for display which work on 9600 baud rate . Also when I try compiling the code using the display libraries the display the output is shown as in picture attached.
I still don't see the need for a software emulation. Do you want to add two displays? If it's just one display, just re-use the hardware serial interface.

Quote
also when the plot starts on the display the sensor starts to give absurd values in serial monitor can you please let me know the reason for it
You might have to tell us what kind of absurd values you get. Post the values you get and post the code you used for that. Eliminate everything that's not needed.

shreya_marwaha

I still don't see the need for a software emulation. Do you want to add two displays? If it's just one display, just re-use the hardware serial interface.
I need the software serial as I have one sensor working at 115200 baud rate and one LCD working at 9600 baud rate .Also I want both of these to work in real time


You might have to tell us what kind of absurd values you get. Post the values you get and post the code you used for that. Eliminate everything that's not needed.
When the sensor is used using altsoftserial without any display libraries the values of heart rate and spo2 are perfect.
But as soon as the libraries of display are added it gives absurd values as below.


red=443, ir=1400
red=453, ir=1360
red=474, ir=1330
red=501, ir=1311
red=522, ir=1303
red=557, ir=1295
red=573, ir=1302
red=607, ir=1302
red=637, ir=1304
red=666, ir=1309
red=699, ir=1296
red=751, ir=1304
red=806, ir=1308
red=871, ir=1309
red=936, ir=1298
red=983, ir=1308
red=1042, ir=1295
red=1074, ir=1301

red=1095, ir=1298
red=1085, ir=1302
red=1066, ir=1303
red=1038, ir=1297, HR=45, HRvalid=1, SPO2=56, SPO2Valid=1
⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮

pylon

Quote
I need the software serial as I have one sensor working at 115200 baud rate and one LCD working at 9600 baud rate
Which sensor is accessed at 115200 baud? The only sensor you mentioned already is accessed by I2C and not a UART style serial interface.

Please post the code that produces correct values and also the code that produces the above values. Please use code tags, that's the </> button in the editor.

shreya_marwaha

Which sensor is accessed at 115200 baud? The only sensor you mentioned already is accessed by I2C and not a UART style serial interface.

Yes,I agree The mentioned sensor uses  I2C communication. But I wanted know,hope you don't mind sharing,if what difference the does it makes on communication with arduino.

Also the code for sensor to run using altsoftserial is:
Basically this portion of code covers the part of code edited to use altsoftserial.
<

#include <Arduino.h>
#include "algorithm.h"
#include "max30102.h"
#include <AltSoftSerial.h>



AltSoftSerial altSerial;

void setup() {

Serial.begin(9600);


#if defined(ARDUINO_AVR_LILYPAD_USB)   
  pinMode(13, OUTPUT);  //LED output pin on Lilypad
#endif

#if defined(ARDUINO_AVR_FLORA8)
  //Initialize the LED
  LED.begin();
  LED.show();
#endif

  maxim_max30102_reset(); //resets the MAX30102
  // initialize serial communication at 115200 bits per second:

 altSerial.begin(115200);
  pinMode(8, INPUT);  //pin D10 connects to the interrupt output pin of the MAX30102
  delay(1000);
  maxim_max30102_read_reg(REG_INTR_STATUS_1,&uch_dummy);  //Reads/clears the interrupt status register
  while(Serial.available()==0)  //wait until user presses a key
  {
    Serial.write(27);       // ESC command
    Serial.print(F("[2J"));    // clear screen command
#if defined(ARDUINO_AVR_LILYPAD_USB)   
    Serial.println(F("Lilypad"));
#endif
#if defined(ARDUINO_AVR_FLORA8)
    Serial.println(F("Adafruit Flora"));
#endif
    Serial.println(F("Press any key to start conversion"));
    delay(1000);
  }
  uch_dummy=altSerial.read();
  maxim_max30102_init();  //initialize the MAX30102
}

/>


and when the display libraries are added the code starts to produce absurd values
<

#include <Arduino.h>
#include "algorithm.h"
#include "max30102.h"
#include <AltSoftSerial.h>
#include <Picaso_Const4D.h>
#include <Picaso_Serial_4Dlib.h>
#define DisplaySerial Serial
Picaso_Serial_4DLib Display(&DisplaySerial);


float x,y,z;
AltSoftSerial altSerial;
void setup() {

   Serial.begin(9600);
DisplaySerial.begin(9600);
Display.TimeLimit4D = 5000;

Display.gfx_Cls();

pinMode(2,OUTPUT);
DisplaySerial.begin(9600);
Display.TimeLimit4D = 5000;

digitalWrite(2, HIGH);
delay(1000);
digitalWrite(2, LOW);

#if defined(ARDUINO_AVR_LILYPAD_USB)   
  pinMode(13, OUTPUT);  //LED output pin on Lilypad
#endif

#if defined(ARDUINO_AVR_FLORA8)
  //Initialize the LED
  LED.begin();
  LED.show();
#endif

  maxim_max30102_reset(); //resets the MAX30102
  // initialize serial communication at 115200 bits per second:
 // Serial.begin(115200);
 altSerial.begin(115200);
  pinMode(8, INPUT);  //pin D10 connects to the interrupt output pin of the MAX30102
  delay(1000);
  maxim_max30102_read_reg(REG_INTR_STATUS_1,&uch_dummy);  //Reads/clears the interrupt status register
  while(Serial.available()==0)  //wait until user presses a key
  {
    Serial.write(27);       // ESC command
    Serial.print(F("[2J"));    // clear screen command
#if defined(ARDUINO_AVR_LILYPAD_USB)   
    Serial.println(F("Lilypad"));
#endif
#if defined(ARDUINO_AVR_FLORA8)
    Serial.println(F("Adafruit Flora"));
#endif
    Serial.println(F("Press any key to start conversion"));
    delay(1000);
  }
  uch_dummy=altSerial.read();
  maxim_max30102_init();  //initialize the MAX30102
}

Serial.print(F(", SPO2Valid="));
     Serial.println(ch_spo2_valid, DEC);
     ch_spo2_valid=ch_spo2_valid*100;
       for(z=1;z<1000;z++)
     {
       Display.gfx_PutPixel(z,aun_red_buffer,RED);
       Display.gfx_PutPixel(z,aun_ir_buffer,BLUE);
       Display.gfx_PutPixel(z,ch_spo2_valid,GREEN);
     }

/>

pylon

Quote
Yes,I agree The mentioned sensor uses  I2C communication. But I wanted know,hope you don't mind sharing,if what difference the does it makes on communication with arduino.
The difference is that you simply don't need any serial interface emulation in software. As you can attach the display to the hardware serial interface you don't need an additional interface for the sensor.
As you seem to use a Flora board you have Serial1 available to use for the display, Serial is the virtual USB interface.

Did you read my last post:
Quote
Please post the code that produces correct values and also the code that produces the above values. Please use code tags, that's the </> button in the editor.
You didn't use that button so your code is not marked as code and the forum system mangles it.


Does that stuff compile for you? In my IDE it just spits out hundreds of errors. Even if I fix the most obvious syntax errors the strange version of SoftI2CMaster (why the hell are you using that one if there is Wire included) that you're using will break at the linker stage.

Is it possible that you don't use the Arduino IDE?

Go Up