Loading...
Pages: [1]   Go Down
Author Topic: how can I input a delimiter to a Arduino through Serial Monitor?  (Read 308 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: 311
Posts: 35483
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
Jr. Member
**
Karma: 4
Posts: 64
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: 26
Posts: 839
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: 50
Posts: 6540
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

Why I like my 2005 rio yellow Honda S2000 with the top down, and more!
GOOGLE ADVANCED FORUM SEARCH BELOW!  
Go to:  http://www.google.com/advanced_search?hl=en
put in key search words,
use site or domain:  http://arduino.cc/forum
or in a google search box put key words site:http://arduino.cc/forum

Pages: [1]   Go Up
Print
 
Jump to: