I spend some time now, trying out some things and realized the following behaviour:
1. I have changed the serial.print() to serial.println()
Now, the following things happen:
Case 1: (the one before)
I transmit a single char and get: there is always a single char output, but always the first one I transmitted:
Example:
I transmit one char after another ( with a few seconds time inbetween ) 'A', 'B', 'C', 'D' and get output: AAAAAAAAA
Case 2:
I use println() instead of print()
I transmit a single char and end up with the same result as before, but after the first char delivered the println() command jumps into the next line after
result:
A
AAAAAAAAAAAAAAA
Case 3:
I use println() instead of print()
I transmit 'ABDC' as one command and get the output:
A
ABCD
Now I change the code a bit to:
while(Serial1.available())
{
char c = Serial1.read();
Serial.print(c);
}
which works fine, but only if I output one char after another. As soon as I want to do something with the received char ( to += onto a String for example ) I`m not able to do that ( it just doesn`t appear in the string, the compiler takes it, but the char doesn`t get added to the string )
This lead me to another test:
while(Serial1.available())
{
int c = (int) Serial1.read();
Serial.println(c);
}
And: surprise surprise, all chars I transmit get received and printed, BUT for each line of a char, I also get a second line with a 0 in it.
Example:
I transmit 'a', 'b', 'c', 'd' with some time inbetween and get:
97
0
98
0
99
0
100
0
So, for every char I receive, I also get a '0' and that seems to be the problem for the += operator in the string.
- Any thoughts what I can do?
- any workaround?
- can I shut off the debugger to solve the problem?