String and serial comunication Problem

HI there, I got a problem with a serial communication program:

String sinal; void setup() { Serial.begin(9600); } void loop() { if(Serial.available()) { sinal=Serial.read(); Serial.println(sinal); }

}

ANd in the problem says: invalid conversion from 'int' to 'const char*' I tried to fix it adding a (byte) before Serial.read(),but still dont work!

Pealdu: HI there, I got a problem with a serial communication program:

String sinal; void setup() { Serial.begin(9600); } void loop() { if(Serial.available()) { sinal=Serial.read(); Serial.println(sinal); }

}

ANd in the problem says: invalid conversion from 'int' to 'const char*' I tried to fix it adding a (byte) before Serial.read(),but still dont work!

You're trying to assign a single byte (read from Serial.read()) to an entire String. Ditch the string class altogether before it comes back to byte you in the add and use a char array.

Thank you man,

I know another way to solve my problem,but I found a video where the code is like I post, "sinal =Serial.read();" and it works,then I thought that is something wrong with my IDE version or something like that,weird Thank you again

sinal += Serial.read(); works, because the += operator is overloaded to take a variety of right hand types.

sinal = Serial.read(); fails, because the only version of the = operator expects a String on the right.

sinal = String(Serial.read()); would also work, because the constructor for the String class is overloaded to take a variety of types, but it would NOT do what you expect.

Best to get rid of the String class altogether, and learn about char arrays, NULL termination, and the whole "how to read serial data" scene.