I am sure this has been covered but I don't know how to build a query to search for answers. I am sending from an arduino serial port "h", a 2 digit value, a comma and another 2 digit value and an "f" so the serial stream looks like this:
h62,56fh34,54fh22,78f...
At the comport in puredata I just see a 3digit number?
What I want is to recognize the 2 number pairs by parsing the h as a header, the first number then the second number and f as a footer. The first 2 digit value is an x value. The second is a y value. These are coming from ultrasonic sensors.
Where can I find a deeper explanation of how to accept a packet structure and parse it in pure data?
Is thare an easier or better way? Thank-you.
-
how to use serial data sent with header and footer and comma delimiters
-
@lulu_joe13 This might work:
comport3.pdLike the previous version, it doesn't check for the consistency of the messages, just assumes that they come in the right order. If anything goes wrong, the counter and the list need to be reset.
A little update with some minimal consistency checking: comport4.pd (not very reliable though...)
-
@ingox @lulu_joe13 ....... check this thoroughly when you have a moment.......parse2.pd
It can cope with any data (including values of 44 and 102 and 104..... i.e. the same values as the header separator and footer) and the "worst" it will do is repeat the last data set up to 6 times before moving on......
If that is a problem then try this, which removes repeated lists (of the 4 "data" floats)............parse3.pd
David. -
@whale-av I can think of a few ways to do this. the best way depends on what you are going for. If externals are an option, cyclone can do it in just a few objects.
]comport]
|
[zl group 6]
|
[zl iter 3]
|
[route 102 44]A simple way in vanilla would be this
-
@whale-av Yes, i took your approach, modified it a little bit and put everything together. Should be very tight now: parse2b.pd
-
@ingox Ah! Yes...... I missed the data range 48 plus.......
Good idea to constrain the data range!
..... but where do you find "57 or less"?
In the OP there was data of 78......
What do you know that I don't?..... is the "78" a misprint by @lulu_joe13 ?
David. -
@whale-av 78 will be the result of 7 * 10 + 8, where 7 is 55 in ASCII and 8 is 56 in ASCII.
-
@ingox Ah!...... mixed data in the OP..... well spotted!
I am getting old and more easily confused.
David. -
Thanx to all. It'll probably take weeks to figure out what you all did. But, the longest journey starts with one step...
If you want to see where x and y come from then look at the link below. In this iteration I am calculating the hypotenuse of a triangle on the arduino and sending that one value as a midi note number to pd. Now, I am sending the x and y so I can have 2 values to use in pd. Depending on the image printed the sequence changes but is unique and repeatable for each image. -
@whale-av. Dang. Works like a charm! Tx to all. Again.
-
badass!