From the arduino documentation, the Serial.read()
function is supposed to return a single character at a time from incoming serial messages. So if I program the arduino with the following:
#include "SPI.h"
void setup() {
Serial.begin(115200);
}
void loop() {
if (Serial.available() > 0) {
char data1 = Serial.read();
Serial.print(data1);
}
}
And I open the serial monitor and send "Hello, World!"
I would expect the received message to be the individual characters printed one at time but instead I get back the whole message. So what gives? What am I not understanding?
1 Answer 1
You only think it is a string, it actually returns character by character. You can know by adding something like a delay after you Serial.print(). What the program actually does is that it receives one character each time you type one and it prints it, then the void loop repeats.
delay()
in there and It makes more sense now. I am not that smart, apparently.