Go Down

Topic: Help with Serial ASCII (Read 544 times) previous topic - next topic

GeneralMcGrath

Hello All,

I am working on a project the requires me to send a mixed string of letters and numbers i.e. (1,4,qwerty;9,4,asdf...) from a computer to an arduino. I have no problem compiling and sending these strings from the computer, but I have run into a problem on the arduino side.

I am reading the incoming data into a char array without a problem and would now like to parse the array to separate out the numeric values from the letter strings. Converting the numeric portions won't be a problem with atoi, but I am stumped as to how to dump the text strings from the char array into a proper String.

Is there a good way to convert the ASCII 113119101114116121 into the String "qwerty"?
or even better, to convert and dump the entire char array into a String (both numbers, symbols, and letters) which I can then easily parse?

Thank you in advance for any help or advice!

HugoPT

can you post a simple exemple of that tricks?
I also need to convert an array that contains dec codes of letters and I dont see I can I rebuild it to a string
Debian,Mint,Ubuntu
Arduino Mega 2560
Arduino Nano
Arduino Duemilanove
MAC OS Montain Lion
Raspberry PI Model B

PaulS

Quote
I am reading the incoming data into a char array without a problem and would now like to parse the array to separate out the numeric values from the letter strings. Converting the numeric portions won't be a problem with atoi, but I am stumped as to how to dump the text strings from the char array into a proper String.

I'd recommend abandoning the idea of using the String class. There is no particular advantage in this case. Once you have collected all the data into to a NULL-terminated char array (whether or not you are actually doing this is a mystery, looking at the code you posted), you can use strtok() to get pointers to the tokens.

If you know that the first two tokens represent numbers, use atoi() to convert them the ints (or the other atoX functions for other types). Then, the non-numeric token ("qwerty" or "asdf...") can be used as is, for whatever purpose you had in mind.

Post the code you have, and a more concise description of the problem you are having, if you need more help.

Go Up