Sunrom Blood Pressure Sensor 1437 Arduino code help

I cant display the right results to the serial monitor
Im using Arduino Uno
the code I used was

char sbuffer[30], ch;
unsigned char pos;
unsigned char read1, read2, read3;

void setup(){
Serial.begin(9600); // Serial is used for output on PCs "Serial Monitor"
Serial.begin(9600); // Serial1 is used for serial input from connected sensor
}

char mygetchar(void)
{ //receive serial character from sensor (blocking while nothing received)
while (!Serial.available());
return Serial.read();
}

void loop()
{
ch = mygetchar(); //loop till character received
if(ch==0x0A) // if received character is , 0x0A, 10 then process buffer
{
pos = 0; // buffer position reset for next reading
Serial.println("Calculating Results");
// extract data from serial buffer to 8 bit integer value
// convert data from ASCII to decimal
read1 = ((sbuffer[1]-'0')*100) + ((sbuffer[2]-'0')*10) +(sbuffer[3]-'0');
read2 = ((sbuffer[6]-'0')*100) + ((sbuffer[7]-'0')*10) +(sbuffer[8]-'0');
read3 = ((sbuffer[11]-'0')*100) + ((sbuffer[12]-'0')*10) +(sbuffer[13]-'0');

// Do whatever you wish to do with this sensor integer variables
// Show on LCD or Do some action as per your application
// Value of variables will be between 0-255

// example: send demo output to serial monitor on "Serial"
Serial.print(read1);
Serial.print('\t');
Serial.print(read2);
Serial.print('\t');
Serial.print(read3);
Serial.print('\t');
Serial.println();
} else { //store serial data to buffer
sbuffer[pos] = ch;
pos++;
}
}// end loop

All I keep getting is 48 in all the result

Help :frowning:

reference:

@CoolestKou, stop cross-posting. Post removed, thread split, threads merged. Basically copious vomit removed.

Code tags would not go amiss.

CoolestKou:
I cant display the right results to the serial monitor
Im using Arduino Uno

Perhaps it's due to using the same serial (as in, the Uno's only) port to read the sensor and print to the monitor?

I think you may need to use software serial for the sensor.

(edit: I see the comment says Serial1 for the sensor, which means it was written originally for a Mega.)

But that said, what values do you get when you just hook it up to a terminal like they do in your reference link?

edit... here's OP's code in tags

char sbuffer[30], ch;
unsigned char pos;
unsigned char read1, read2, read3;

void setup(){
  Serial.begin(9600); // Serial is used for output on PCs "Serial Monitor"
  Serial.begin(9600); // Serial1 is used for serial input from connected sensor
} 

char mygetchar(void)
{ //receive serial character from sensor (blocking while nothing received)
  while (!Serial.available());
  return Serial.read();
}

 
void loop()
{
  ch = mygetchar(); //loop till character received
  if(ch==0x0A) // if received character is <LF>, 0x0A, 10 then process buffer
  {
      pos = 0; // buffer position reset for next reading
      Serial.println("Calculating Results");
      // extract data from serial buffer to 8 bit integer value
      // convert data from ASCII to decimal
      read1 = ((sbuffer[1]-'0')*100) + ((sbuffer[2]-'0')*10) +(sbuffer[3]-'0');
      read2 = ((sbuffer[6]-'0')*100) + ((sbuffer[7]-'0')*10) +(sbuffer[8]-'0');
      read3 = ((sbuffer[11]-'0')*100) + ((sbuffer[12]-'0')*10) +(sbuffer[13]-'0');
       
      // Do whatever you wish to do with this sensor integer variables
      // Show on LCD or Do some action as per your application
      // Value of variables will be between 0-255
      
      // example: send demo output to serial monitor on "Serial"
      Serial.print(read1);
      Serial.print('\t');
      Serial.print(read2);
      Serial.print('\t');
      Serial.print(read3);
      Serial.print('\t');
      Serial.println();
  } else { //store serial data to buffer
      sbuffer[pos] = ch;
      pos++;
  }
}// end loop

I tried including Software serial and Im still getting the 48 for some reason and this code was for mega but not tested I tried testing it for my arduino uno and fix some stuffs a little and the result I keep getting is 48 instead of 122 79 92 where 122 is the systolic 79 is diastolic and 92 is for the Pulse

I have connected the Tx-out pin to Rx of Arduino. 5V and GND have also been connected appropriately. Following are example output readings from sensor. Each reading consist of 15 bytes at 9600 baud rate. The reading packet's last byte is always enter key character(0x0A in hex and 10 in decimal).The output reading is 8bit value in ASCII format fixed digits, from 000 to 255.

Tried making a new one with the software serial this time

#include <SoftwareSerial.h>
int sensorValue; // variable to store the value coming from the sensor

SoftwareSerial serial(9,10);

char sbuffer[14], ch;
unsigned char pos;
unsigned char read1, read2, read3;
boolean newData=false;

void setup() {
Serial.begin(9600);
Serial.begin(9600);
Serial.println("");
}

void loop() {
recvChar();
showNewData();
}

void recvChar() {
if (Serial.available() > 0)
{
while(Serial.available()>0)
{
ch = Serial.read(); //loop till character received
if(ch==0x0A) // if received character is , 0x0A, 10 then process buffer
{
pos = 0; // buffer position reset for next reading
newData=true;
// extract data from serial buffer to 8 bit integer value
// convert data from ASCII to decimal
read1 = ((sbuffer[1]-'0')*100) + ((sbuffer[2]-'0')*10) +(sbuffer[3]-'0');
read2 = ((sbuffer[6]-'0')*100) + ((sbuffer[7]-'0')*10) +(sbuffer[8]-'0');
read3 = ((sbuffer[11]-'0')*100) + ((sbuffer[12]-'0')*10) +(sbuffer[13]-'0');

}
else
{ //store serial data to buffer
sbuffer[pos] = ch;
pos++;
}
}
}
}

void showNewData() {
if (newData == true)
{
Serial.println("Calculating Results ... ");
Serial.println(read1);
Serial.println(read2);
Serial.println(read3);
newData = false;
}
}

CoolestKou:
I tried including Software serial and Im still getting the 48 for some reason and this code was for mega but not tested I tried testing it for my arduino uno and fix some stuffs a little and the result I keep getting is 48 instead of 122 79 92 where 122 is the systolic 79 is diastolic and 92 is for the Pulse

I have connected the Tx-out pin to Rx of Arduino. 5V and GND have also been connected appropriately. Following are example output readings from sensor. Each reading consist of 15 bytes at 9600 baud rate. The reading packet's last byte is always enter key character(0x0A in hex and 10 in decimal).The output reading is 8bit value in ASCII format fixed digits, from 000 to 255.

Tried making a new one with the software serial this time

#include <SoftwareSerial.h>
int sensorValue; // variable to store the value coming from the sensor

SoftwareSerial serial(9,10);

char sbuffer[14], ch;
unsigned char pos;
unsigned char read1, read2, read3;
boolean newData=false;

void setup() {
Serial.begin(9600);
Serial.begin(9600);
Serial.println("");
}

void loop() {
recvChar();
showNewData();
}

void recvChar() {
if (Serial.available() > 0)
{
while(Serial.available()>0)
{
ch = Serial.read(); //loop till character received
if(ch==0x0A) // if received character is , 0x0A, 10 then process buffer
{
pos = 0; // buffer position reset for next reading
newData=true;
// extract data from serial buffer to 8 bit integer value
// convert data from ASCII to decimal
read1 = ((sbuffer[1]-'0')*100) + ((sbuffer[2]-'0')*10) +(sbuffer[3]-'0');
read2 = ((sbuffer[6]-'0')*100) + ((sbuffer[7]-'0')*10) +(sbuffer[8]-'0');
read3 = ((sbuffer[11]-'0')*100) + ((sbuffer[12]-'0')*10) +(sbuffer[13]-'0');

}
else
{ //store serial data to buffer
sbuffer[pos] = ch;
pos++;
}
}
}
}

void showNewData() {
if (newData == true)
{
Serial.println("Calculating Results ... ");
Serial.println(read1);
Serial.println(read2);
Serial.println(read3);
newData = false;
}
}

is the code working ? i tried using it but getting error

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00

avrdude done. Thank you.

An error occurred while uploading the sketch

plz help what can be the issue?

kammatisai:
is the code working ? i tried using it but getting error

Error is unrelated to the code in the old thread you replied to. This error basically means you either set the wrong port in the IDE or you forgot to connect your Arduino to your computer.

Use below Code already answered by Jur here
https://forum.arduino.cc/index.php?topic=349767.msg4517142#msg4517142

Connect the SunRom's Tx output to Rx 0 pin. That's it.

// Demo program for Arduino MEGA2560 board and sensor with serial output
char sbuffer[30], ch;
unsigned char pos;
unsigned char read1, read2, read3;

void setup(){
 Serial.begin(9600); // Serial is used for output on PCs "Serial Monitor"
 //Serial1.begin(9600); // Serial1 is used for serial input from connected sensor
}

char mygetchar(void)
{ //receive serial character from sensor (blocking while nothing received)
 while (!Serial.available());
 return Serial.read();
}


void loop()
{
 ch = mygetchar(); //loop till character received
 if(ch==0x0A) // if received character is <LF>, 0x0A, 10 then process buffer
 {
     pos = 0; // buffer position reset for next reading
     
     // extract data from serial buffer to 8 bit integer value
     // convert data from ASCII to decimal
     read1 = ((sbuffer[1]-'0')*100) + ((sbuffer[2]-'0')*10) +(sbuffer[3]-'0');
     read2 = ((sbuffer[6]-'0')*100) + ((sbuffer[7]-'0')*10) +(sbuffer[8]-'0');
     read3 = ((sbuffer[11]-'0')*100) + ((sbuffer[12]-'0')*10) +(sbuffer[13]-'0');
     
     // Do whatever you wish to do with this sensor integer variables
     // Show on LCD or Do some action as per your application
     // Value of variables will be between 0-255
     
     // example: send demo output to serial monitor on "Serial"
     Serial.print(read1);
     Serial.print('\t');
     Serial.print(read2);
     Serial.print('\t');
     Serial.print(read3);
     Serial.print('\t');
     Serial.println();
 } else { //store serial data to buffer
     sbuffer[pos] = ch;
     pos++;
 }
}// end loop