I can't get My Nano to write the correct data values to serial. I'm fairly new to arduino, mostly used it for lighting leds before. Code is attached i'll copy the serial bellow
-1
49
50
51
(It started with -1, then I sent it 1,2,3)
it's using No Line Editing and 9600 Buad
Code bellow:
void setup() {
// put your setup code here, to run once:
Serial.begin(96010);
}
void loop() {
// put your main code here, to run repeatedly:
int c=Serial.read();
Serial.println(c);
Serial.read();
while (Serial.available()==0){}
}
isn't doing anything, it's possible that the compiler optimizes it away. At the top of this Forum is a topic titled Tutorials. Inside that is a general heading Communications. A subclass in that area is Serial Basics. Read that and you will likely answer your own questions. Also, before you post your code, place the cursor in the IDE Source Code Window and press Ctrl-T. This will reformat your code to a standard C style which most of us will find easier to read.
Whandall:
I disagree. The statement is a vaild wait for something from Serial and will not optimized away.
What I meant was that the loop does nothing. I checked the assembler code and it does spin around waiting for the Serial object. Still, with nothing controlled by the loop, it seems kinda silly.
econjack:
Still, with nothing controlled by the loop, it seems kinda silly.
Why? What could you do to speedup serial events if you ever choose to wait for some?*
Which is usually a bad idea anyway, but that does not really matter, does it?
added: * on an esp8266 a delay(0); would avoid watchdog resets on longer waits