Alright, I've googled getting a string from Serial with Arduino and I've had no luck even copy and pasting examples.
I'm trying to get a string from the Serial. Here's my code:
void setup() {
Serial.begin(9600);
Serial.write("Power On");
}
void loop()
{
while(!Serial.available());
while (Serial.available() > 0) {
Serial.write(Serial.read());
}
Serial.println();
}
And it's printing out character by character.
I also tried
char* read(int len) {
while (!Serial.available());
char str[len];
int i = 0;
while (i < len) {
str[i] = '\0';
int inByte = Serial.read();
Serial.println(inByte);
if (inByte == -1) {
return str;
} else {
str[i++] = inByte;
}
}
return str;
}
And it returns 1 character at a time (serial.print(inByte) gives -1 every other time). Why is the Serial splitting each character?
If I enter 'hello' and I call serial.read() it gives a character then says there's nothing, then gives another character and says there's nothing.