Parse a stream of integers
Hi,
I am using a serial port in my patch to receive data from my arduino circuit. My arduino is sending data using Serial.write() so max directly receives data in the form of bytes as follows. The data is parse by sending (255) twice. I have pasted the stream of data received by max below. I am struggling to find an object in max that will parse my stream whenever it encounters 255 255. Can anyone please push me in the right direction to parse this data in max? I am looking into zl object but haven't been able to work it out yet.
data: 255 255 149 196 156 60 179 92 125 38 128 180 127 68 255 255 149 240 156 64 179 224 125 54 128 195 127 151 255 255 149 156 156 224 179 236 125 62 128 154 127 169 255 255 149 220 156 100 181 28 125 96 128 126 127 231 255 255 149 44 157 40 180 180 125 141 128 81 128 59 255 255 149 44 156 176 180 204 125 192 128 55 128 196 255 255 149 88 156 104 180 236 125 220 128 86 129 64 255 255 149 44 156 12 180 148 125 208 128 71 129 111 255 255 149 20 156 80 181 16 125 172 128 72 129 128 255 255 148 64 155 108 180 148 1
Thanks!
Hi
just off the top of my head (I'm not at Max or Arduino here), you could use [select 255], there's no real need to send 255 twice. Or even once - just terminate your data stream with Serial.println(); and use [select 13 10] in Max. Do these numbers represent several sensors/sources or just one?
HTH
Brendan
see if this helps:
This works, too:
Thanks Brendan, Benniy and Mzed!
@Brendan, the numbers represent the gyrometer and accelerometer readings in x,y & z axes. Actually, I am also using the same arduino in pd where it is configured to parse using 255 255. So even though Serial.println() would have made things easier with Max I did not want to change it.
I finally made it work using zl sub, zl group, zl slice and zl iter.
@Benniy and Mzed, your patches are totally better than what I managed. They use much fewer objects. I just had to make some more compensation because not every stream starts with 255 255. So I looked for the index of the first "255 255" match and then sliced the redundant part.
Thank you again for the patches!