Serial port issue
dear Max user/developer
If anyone could give me a tip!
I am receiving data from a bluetooth device.
With the provided patches (in Quartz Composer) I receive the data in hex, where only the first two channels are useful:
raw data format is :
4 date is one packet.
CH1 , CH2, CH3, CH4 is data order.
each data is 10 bit : 000 .. 3ff (hex)
10 bit : 000.. 3ff
000 is 0V input. -> -2.5 V AD input ( – 100 micro V brain wave input )
200 is 2.5V input. -> 0 V AD input( 0 micro V brain wave input )
3ff is 5V input. -> +2.5 V AD input ( + 100 micro V brain wave input )
10 bit mean 1024 resolution from +-100 micro V brain wave input. ( 200 micro V full scale )
1 resolution is 0.1953125 0 micro V ( 200 micro V / 1024 )
only CH1 and CH2 ( left and right ) use.
CH3 and CH4 is not connect. (-2.5V connection that inside IBVA hardware )
CH1 CH2 CH3 CH4
221 18f 003 002
222 121 002 002
1b8 0f6 002 002
181 0b3 002 002
1ad 0fb 002 002
1de 144 002 002
20f 187 002 002
239 1ea 002 002
What I receive in Max/Msp with the serial object looks like this:
My question is:
Why couldn’t I receive the same sort of data? Why is the received data in integers in Max and why is it in hex in Quartz Composer and in the manual which comes with the device?
As far as I am concerned: In max, one line (4 integers) should represent on hex number >
Ch1 = 49 101 101 9
Ch2 = 49 102 49 9
Ch3 = 49 48 59 9
Ch4 = 48 48 50 13
How could I get a hex number out of one line if my presumptions are right?
Any help appreciated!
connect an atoi object after the serial object and you’ll get what you want. Note that "13" = carriage return, and "9" = tab. To get all your numbers to come out as a list, send the output of atoi to a "zl group", then when you receive a "13", bang the "zl group" to get your data as a list. Here’s a little example.
----------begin_max5_patcher---------- 409.3ocuTFsaCBBEF9Z8ofv0tFATqc2smiklEpxrrnfQvrt1z28InlZ2bK1p o2H47ePO+mON3IWG3N4AlBBdF7Jvw4jqiiUxH3zE6.KnGRxoJ61fELkhlwfd s43oVU4tOdJpW6coPKnELalWp3z79LkTcxdtH6sJVhtspj.xJeO.IbiYAs1F ghW4C118Rh5BtHmos0GeQTVq6UQCprhezVYDZU3lN81sp+pj0VTHDr0j4rqq 4g2D6cA6ylFsuYzrC1d.dLGjUIqKA3vnQ3Rv8wExZKWPQlk0AlmX+aCK3aFK dKLZTrb.hLBTHyAJ3vXyR.5g.kcTQ1hCFtVRGAK36CKsWdvwXKVh9erPVlqP bgdgGUF1kCXBZViJDKSHw+OSPKynhgI+ZRwVQXNW7yezZcsQ+ZXoj0UI8ewt 6JfK9NkozbAUykhA6I3p8rmmlxro86TJ3okxF60Yg+3fapNBu7NhDEuJr4fx 2NJSZFh6iloWClfWa9sM.cCdsycAgFuF5eIZldkbkOF2q3G5IMZBziLCG0Db 18a.OGV7z. -----------end_max5_patcher-----------
I had a look at the sample! GREAT! I own you a pint at least:)
I think I could manage, somehow:
http://tedor2.extra.hu/mix/max raw to hex.jpg
and Attached patch: serialworks.maxpat
1, I am wondering whether there is an easier way to separate the string into the 4 groups, mine looks very ugly.
2, I also will be trying to use the "select 13" object to make sure the data in the groups are always the same.
> I think I could manage, somehow:
> http://tedor2.extra.hu/mix/max raw to hex.jpg
> and Attached patch: serialworks.maxpat
> 1, I am wondering whether there is an easier way to separate the string into the 4 groups, mine looks very ugly.
Not too sure I understand what you are trying to do here. What is the purpose of the "zl lookup" here?
Here’s a patch with a bit more comments. Plus I was a bit hasty in the last patch and had the "itoa" object too early…well…it still works but you need to add a "fromsymbol" after the itoa. See if this helps any better:
----------begin_max5_patcher---------- 1179.3oc2YsraaiCEcs8WwEdUKfm.cIokrJvrXlcc+LqlTLfVlNlsRjFRz4Q K5+9vGxSTbjhcjRbhKPhnIEi44d38wgL+X7nIKz2Jpl.eB9GXzneLdzH+PtA FU2ezjB9sY47J+zljoKJDJyjog2YD2ZpGWcsnz.RkALZfWkIkv077shcSUtz OQ8hu9az46FbkVYT7Bg+U+Qojmu6Ma3lr0R0U+aoHyDPHIJ8hno.IN10fyh7 8rOguT+Go1VHU4BiGq38Cp2Z1MZTiUtR9c+Ji3EyRcC+ywicOldjjQgnphek 3QjAoMaNte1bJwYkrnYgFukOuKSlzpIicYx0iGl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B4kBs6AjNPqsnEfmrXo81J6.S yNoXZufgNvD6jhI7nvD8zhoiI27yzcp14u9xWnVAf65MPvxNlb1Imz5HOb2p cHwdl4NR841HTVipH9dCcu9XnO5Ik9RdEfDA8YaQVypv9dCk+nGS76I28K5k 08aOsei+43+Cqip5N -----------end_max5_patcher-----------
Couple other things to note. I’m using "zl nth" to divvy up the list of the 4 values vs. unpack since unpack gets a bit confused with hex (am I an int or am I a symbol?…zl nth doesn’t care). Also, since you are merely polling for data waiting at the serial port, I would change your metro 1000 to metro 10 or even 1, and use "qmetro 1" ("metro 1 @defer 1") so you can poll quickly, but it doesn’t get in the way of other more time-sensitive activities in your patch. That way you’ll get your data with minimal latency.
Let me know if you still have questions, but you might want to poke around a bit on the forum to see how others have dealt with data coming out of the serial object. There’s quite a bit of very useful information here.
> Not too sure I understand what you are trying to do here. What is the purpose of the "zl lookup" here? <
I have to set the chunk message to 16 and send it to the "serial object", than I use the "zl lookup" to get the 4 groups separated. Well, yours is more advanced. I did not know the "fromsymbol" before, very useful.
I was looking for some answers for my question on the forum but, no luck.
I would like to send a message to the device from Max/Msp whereby I would change the sampling rate of the hardware and also a filter. Well I have got something from the manufacturer, but id I just sent the code in a message to the serial object, I received an error in the post window.
I received this:
other command to set and control hardware sampling rate and set filter frequency.
n : 1 .. 2000
set sampling rate
default is 1 Hz
— ex ————-
1ad 0fb 0d2 0b9
1de 144 11e 10c
20f 187 15f 14f
239 1ea 186 1f4
n : 0.1000 .. 1.0000
set filter high cut off frequency ratio )
( in case sampling frequency is 120 Hz,
120 Hz X 0.3333 = 40 Hz : cut off F at -3bd )
default is 0.3333
1ad 0fb 0d2 0b9
1de 144 11e 10c
20f 187 15f 14f
239 1ea 186 1f4
Well, do you have an idea, how to send these messages to the device?
Thank you for your help,
wait a minute… I am useless…
I have to change the hex back to integers now so the modem can understand it, I guess… :)
Yup. serial object receives ints only, and spits out ints only.
Serial help is your friend.
Communications tutorial #2 is your friend.
And again, the forum is your friend, too…this question has come up several times before.
Right. The issue was, I sent a wrong message.
"sr 120" instead of "SR 120"
Works, and the tutorial helped me also to understand more of the serial communication.