Arduino Tutorial # 4.5: Better Serial Parsing

preview_player
Показать описание
Today's Arduino tutorial is a response to several requests asking for how to accomplish multiple argument commands from the PC to the Arduino.

Have a comment or suggestion? Contact me via:
Рекомендации по теме
Комментарии
Автор

Hey man, I know this video is 5 years old or whatever, but it's a great tutorial on separating out data from serial input. I have spent hours reading Arduino forums about methods of doing this, but they are SO convoluted (making temporary indexes and arrays, etc). Thanks so much man, this is so much cleaner and easier to understand.

Just_Ignorant
Автор

Perfect tutorial style. Make tutorials for everything please!

skrame
Автор

you posted this a while back but I still found use in it today (2018). Thanks for taking the time to make this.

samyahmed
Автор

Just as a slight efficiency note: It would be better to only calculate the index of the space *once* and use it both locations, rather than looking it up twice:

int spaceIndex = com.indexOf(" ");
part1 = com.substring(0, spaceIndex);
part2= com.substring(spaceIndex + 1); 

rjjs
Автор

Thx mate, that's what I'v looking for for more than 2 months

nergalian
Автор

I always like and learn interesting things from your video tutorials, thanks!
I just want to say 2 times "int pin = part2.toInt();" is unneeded, 1 time defining it later than part2 definition will be enough.

onurolce
Автор

Honestly I like your tutorial and I think that it's great and useful . Thank you for all the things you shared with us

sarrieri
Автор

Very classy way to perform this function

HowardHowie
Автор

Excellent video on parsing.  Thank you Mr Harddrive.

jeffbeck
Автор

This is an excellent video, Thank you very much!

djddale
Автор

your way of making video tutorials is superb! Thank you for sharing, I am a fan:)

zennicliffzennicliff
Автор

His code works really great. I built it in Arduino IDE and worked well. I just had a hard time not getting the pins on or off and this was because I forgot to select (Both NL and CR) in the serial monitor. hope this helps other people.

ROCKBOYRLND
Автор

Thanks this really helped. ..This is way faster than the slow Serial.parseInt(). To just parseInt() 2 integer values it takes a little over 6000micros but doing it this way and converting to integers only takes 320micros.

paulksycki
Автор

Thanks for this example.
Q: besides an int input for "part2", how can I handle hexadecimal or int values?

irgski
Автор

I disagree with Istace's assertion that there's anything wrong with your protocol itself, but the kind of manual pulling apart of strings that you're doing there gets messy and buggy very quickly. You should look at using something like Ragel, which will generate a state machine based on a higher-level pattern description. I use it for parsing GPS data and AT command responses. Apart from being more maintainable, it also has the advantage that you don't necessarily need to buffer an entire string before you process it.

DanEllis
Автор

Thank you for your tutorial.
I need it to parse gcode!👍

galihtanu
Автор

Hi, I just used the parsing procedure of your code and it work beautifully. But just a little problem though, I do not know if it is due to the parsing but my servo reactions are delayed. Any ideas why. Here's My Code, Hope you could help.

/* Servo Control
 
*/ 

#include <VarSpeedServo.h> 
 
VarSpeedServo myservo1;  // create servo object to control a servo 
                // twelve servo objects can be created on most boards
 
int pos = 0;    // variable to store the servo position 
String command;

void setup() 

  myservo1.attach(9);  // attaches the servo on pin 9 to the servo object 
  Serial.begin(115200); //begins serial communication


void loop() 

  if (Serial.available()){
    delay(100);
    while(Serial.available()>0){
      command=Serial.readString();
      parseCommand(command);
    }
  }


void parseCommand(String com)
{
  String Part1;
  String Part2;
  String Part3;

  Part1 = com.substring(0, com.indexOf("/"));
  Part2 = com.substring(com.indexOf("/")+1, com.indexOf("#"));
  Part3 = com.substring(com.indexOf("#")+1, com.indexOf("s"));
  
  int pin = Part1.toInt();
  int pos = Part2.toInt();
  int spd = Part3.toInt();
  
  if(pin==9)
  {
  myservo1.write(pos, spd, true);
  }


}

dprintwiz
Автор

got a link to the code? i know its pretty lazy of me, but its often helpful to have an example of good working code that you can then modify, specially from a beginners perspective.

letsgocamping
Автор

Thanx for that, How about syntax for two externals? Reading a sensor onto an OLED or something?

wrqnine
Автор

Hello, how can I read a returned message after using GET method? Basically, I am able to push data with GET and recieving back "success" message on Serial Monitor. I want "success" message to be read and trigger a PIN. Is it possible? Thanks

gdisnwhere
visit shbcf.ru