I want my sketch only to be able to continue if I´ve got the echo of my last sent serial output.
This means that I send a character and wait till the response is detected. Then it should be possible to send the next, but not before.
Has someone an idea how to implement this? Is this possible with the Serial.event function?
How can I look for my char if it has come in? My problem is, that I`m sending different chars and I have to wait for exactly the last char I´ve sent.
For example I´m sending the following data:
where the last sent char can vary and the code still stops until the Arduino received the last sent character.
This means I need a function for different values.
How could I implement this?
Sorry I have absoloutly no idea of what you are asking or what you are trying to do. One thing I do know however is that what ever it is you are going about it in totally the wrong way.
So step back and say what your over aime is not what you think a soloution to what you thnk is a problem.
I want my code to go on if the echo of my transmitted data arrives. My problem is, that my sent data is always another char, so I need a loop which can be used as standard, independent from the character which is sent
Have you read the how to use this forum sticky? It is at the start of every section.
There it will tell you how to ask for help.
What on earth is the SMT5echo that appears in the code you posted? It can't be a function because there are no brackets.
If you want to read the serial port until a specific character has been read the you can use this function:-
void echo_return(char c)
{
while(Serial.read() != c) { } // do nothing until we receive c
}
Serial code that does not send back the previously sent characters until a comma , is received.
//zoomkat 3-5-12 simple delimited ',' string
//from serial port input (via serial monitor)
//and print result out serial port
String readString;
void setup() {
Serial.begin(9600);
Serial.println("serial delimit test 1.0"); // so I can keep track of what is loaded
}
void loop() {
//expect a string like wer,qwe rty,123 456,hyre kjhg,
//or like hello world,who are you?,bye!,
if (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
if (c == ',') {
//do stuff
Serial.println(readString); //prints string to serial port out
readString=""; //clears variable for new input
}
else {
readString += c; //makes the string readString
}
}
}
It is a universal routine you pass a parameter to it, that paramater is the character you are looking for this time like you showed in that first bit of code only instead of just calling a routine with no paramaters you cal, the one I posted with the character that you are looking for.
There is no way to automatically fish out the last character you sent over the serials port.