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
(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
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++;
}
}
}
}
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
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++;
}
}
}
}
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
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.
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