So I was playing around with code and instead of changing my device(ESP 8266 to Arduino Nano) got lazy and figured it should not matter on a simple text code. I have tried to use '\r' in the code so that when the serial monitor starts it will see a carriage return , like it was sent from user hitting enter to start the text. I have moved it around the code several ways and was just wondering if there was a way to do this.
ty[code]
String myName ;
String msg1 = "What is your name ?";
String msg2 = "My name is ,";
String msg3 = "Congratulation ";
String msg4 = "now you can start learning to code ";
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.write( '\r');
delay(500);
Serial.println (msg1);
while (Serial.available() == 0) {
}
myName = Serial.readString();
Serial.print(msg2);
Serial.println(myName);
Serial.print (msg3);
Serial.println(msg4);
}
I understand that, I can get it to work if I hit enter to start, what I was looking to see if it could have been sent in the code when started .
Maybe I didn’t make that clear, if I upload to a Nano, it works as expected but with the 8266 I have to hit enter to get it to start. It’s no big deal , just curious if there was a way to do it.
Not sure I understand not using code tags, thought I was supposed to use the </> tags when posting code . I saved to forum in Arduino before posting, again thought that was proper.
As far as string prompts , that is how that program is written in other examples. Also I tried all the options for serial monitor and none make a difference.
This works perfectly if I use a Nano but when uploaded to an ESP it needs user to hit enter in the serial windows before it runs in the monitor.
Ok , I thought if I clicked on copy for forum in the IDE program, that would be correct. But that is off topic anyway.
What I was attempting to ask is if there was a way when send to serial monitor using ESP 8266 was there a way to in software to emulate a user pressing enter.
If I send exact same code to a Nano it asks “What is your name” , if I send it to the ESP nothing happens unless you hit enter first. Then and only then will it ask “What’s your name”.
Hope this clears things up , it’s not a big deal either way, was just trying to learn something here.
I guess asking a simple question here is harder than it looks. Seems that instead of helping , you get snarky results. Sorry I bother to as this quest, it got more question than answers.
Seems like instead of answering questions that you have been asked, in order to find out more about your problem, so that help can be targeted, you just duck the questions and whine, and actually make it harder to help you.
Once again, I asked for help on a issue I was having, I answered any questions asked so what exactly was it that I didn’t respond to? I am not wining as you put it, just frustrated.
I get it, didn’t like how I posted code, I addressed that, I used copy to forum from the Arduino IDE, thought that was the preferred method.
As far as what the settings on the serial monitor I said I tried them all so I guess I should have said , BothNL &CR , Carriage return, Newline and No line ending.
The original question pertains to the difference between the ESP 8266 Node MCU 12E running the same exact sketch as the Arduino Nano. It works perfectly in the Arduino Nano but the ESP I have to hit send or enter in the Serial monitor. So I asked if there was a way to have the code input a carriage return or whatever to get it to start with the ESP. I don’t have to use that ESP , just asking it there was a way to write in code to work.
I try extremely hard to use this forum the way it’s supposed to be used , it’s disheartening to get some of the remarks given here. If I knew enough of code I would not ask for help. So please tell me where I am wrong.
Serial.write( '\r');
delay(500);
Serial.println (msg1);
while (Serial.available() == 0) {
Serial.print("I am stuck here!");
}
You cannot simulate user entry in the terminal or receiving a '\r' or a '\n' by writing it to the terminal. You would need a crossover or loopback to do this and then you wouldn't see your output on the serial monitor.