Problems receiving data from Processing using HC05 BT-module

Hello everyone,

We got stuck receiving wrong data from Processing on our Arduino Uno. We only need 4 different values to control the system. It works the other way though: Getting data from Arduino to Processing has not been a problem. We got data straight away after sending a command in processing, but only random numbers so far. Strangely the width was never greater than 8 bits, e.g. it seems to read exactly one byte from the buffer.

Baud rate is 9600 and we also avoided using Serial.print() to troubleshoot at one point as we thought it might interfere with the transmission. In the setup routine we import the library SoftwareSerial.h.

What we have tried so far:
-Using bytes, chars, ints and String on both ends.
-Using Serial.parseInt() instead of Serial.read() to get the data from the buffer

void getBluetooth() {

  if (Serial.available() >= MESSAGE_BYTES)
  {
    //if (Serial.read() == HEADER) {
      int receivedmsg = (Serial.read());  //programm

      Serial.print("received: ");
      Serial.println(receivedmsg);
      if (decryptmsg(receivedmsg) != -1) {
        programm = decryptmsg(receivedmsg);

        //achtung Serial.prints() auskommentieren für eigentliche Anwendung, schreibt sonst auf BT
        Serial.println("succesful msg ->" + programm);
      } else {
        Serial.println("failed msg!");
    //  }
    }
  }
}

What does "wrong data" mean?

ieee488:
What does "wrong data" mean?

Sorry for being unspecific. We're sending either 0,1,2 or 3 to be used in a switch case routine on the arduino. What we're receiving is a random number between 0 and 255.

The character 0 would be 48 decimal.
The character 1 would be 49 decimal.
etc.

You may want to get familiar with the ASCII table.

ieee488:
The character 0 would be 48 decimal.
The character 1 would be 49 decimal.
etc.

You may want to get familiar with the ASCII table.

I've heard of it. It's literally random though. We send the number 5 times in a row to make sure there are no errors. And we get 5 different values.

I don't use Processing so I can't help further. Good luck.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example.

...R

It would also be useful to show your Processing program. It may be riddled with errors.

It would also be useful to show the output from Processing.

It would also be useful to show ALL of your Arduino code.

      int receivedmsg = (Serial.read());  //programm

(Parentheses) (are) (good.) (Useless) (ones) (are) (not.)

PaulS, you're right. We were looking on the wrong end. Processing code it was. The error was caused by a parenthese :-X