Go Down

Topic: how can I input a delimiter to a Arduino through Serial Monitor? (Read 1 time) previous topic - next topic

ahwahha

As subject,
I don't know how to properly use parseInt without timeout at the end. :smiley-roll:

PaulS

Quote
I don't know how to properly use parseInt without timeout at the end.

You can use just about anything for the delimiter. Space, comma, semicolon, carriage return, line feed...

Some of them, the Serial Monitor will even append for you.

mrburnette


As subject,
I don't know how to properly use parseInt without timeout at the end. :smiley-roll:


I have a simple sketch that you can run and try all types of delimeters for Stream.
http://arduino.cc/forum/index.php?PHPSESSID=85ee2ddde632fc6521bfdf2513efdfe9&topic=147550.0

Disguised as a calculator.  Use Space, comma, etc. to try out.


afremont


As subject,
I don't know how to properly use parseInt without timeout at the end. :smiley-roll:


You could use the strtok() and atoi() functions.  You have to first read the serial data into a character array to process it.
Experience, it's what you get when you were expecting something else.

zoomkat

Some delimiter test code.

Code: [Select]

//zoomkat 3-5-12 simple delimited ',' string parce
//from serial port input (via serial monitor)
//and print result out serial port
// CR/LF could also be a delimiter

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
    }
  }
}

Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

Go Up