Arduino communication with bluetooth

Hello everyone.

I managed to make communication between bluetooth and arduino, tho, after reciving the data which I transmitted which is the following:

13
28

NOTE: I’M USING ARDUINO MEGA 2560 R3 WITH SERIAL1 AS COMMUNICATION AND SERIAL AS DATA DISPLAY FOR THE SERIAL MONITOR

I received the following:

-35
-49

this is my code:

void setup() {
  lcd.begin (20 , 4);
  Serial1.begin(9600);
  Serial.begin(9600);
  pinMode (in1, OUTPUT);
  pinMode (in2, OUTPUT);
  digitalWrite (in1, HIGH);
  digitalWrite (in2, HIGH);

}
void loop (){
    else if (key == '3') {
      while (1) {
        lcd.clear();
        bl_m();
        break;
      }
}
}

void bl_m() {
  lcd.clear();
  lcd.print ("bluetooth mode");
  while(1){
    char h=NULL,m=NULL;
   if(Serial1.available() > 0){
    h = Serial1.read();
    m=Serial1.read();
    Serial.println(h-'0');
    Serial.println(m-'0');
    break;
   }

   }
}

Another note: I only put related code to Bluetooth, nothing else, as my code is 600lines long, and now I’m working the bluetooth alone.

(deleted)

spycatcher2k: Serial.println(h-'0');     Serial.println(m-'0');

Change to

Serial.println(h);
    Serial.println(m);

as you are not sending ASCII.

thanks, will check and update!

spycatcher2k: Serial.println(h-'0');     Serial.println(m-'0');

Change to

Serial.println(h);
    Serial.println(m);

as you are not sending ASCII.

now I'm getting the following:

a square mark on the Serial Monitor.

(deleted)

   if(Serial1.available() > 0){
    h = Serial1.read();
    m=Serial1.read();

If there is at least one byte of serial data available, it is NOT okay to read two bytes.

PaulS:   if(Serial1.available() > 0){     h = Serial1.read();     m=Serial1.read();

If there is at least one byte of serial data available, it is NOT okay to read two bytes.

I read one byte at a time.

EDIT:

I need to read an hour as a byte:

I manage to read only the hour, as of example: 16:34

I managed to read only 16, but not 34. any idea how to solve this?

PacificThunder: I read one byte at a time.

You are reading h which is byte #1 and m which is byte #2

.

I read one byte at a time.

But, you read the second byte whether there is anything to read, or not.

PaulS: But, you read the second byte whether there is anything to read, or not.

oh okay, I'll change my code and see how it works, I'll update tomorrow on it if needed.

Thanks!