Pages: [1]   Go Down
Author Topic: how can I input a delimiter to a Arduino through Serial Monitor?  (Read 1278 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49077
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Atlanta, USA
Offline Offline
Edison Member
*
Karma: 53
Posts: 1790
AKA: Ray Burne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

texas
Offline Offline
God Member
*****
Karma: 27
Posts: 862
old, but not dead
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Experience, it's what you get when you were expecting something else.

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9549
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Some delimiter test code.

Code:
//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
    }
  }
}

Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Pages: [1]   Go Up
Jump to: