Serial port issue

Feb 9, 2009 at 8:22pm

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:

description:

—————————————————————–
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 )

ex data
< <
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:

http://tedor2.extra.hu/mix/serial.jpg

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!

K

#42212
Feb 9, 2009 at 9:16pm

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.

HTH,
David

– Pasted Max Patch, click to expand. –
#151011
Feb 9, 2009 at 9:39pm

David,

I had a look at the sample! GREAT! I own you a pint at least:)

K

#151012
Feb 10, 2009 at 9:42am

well,

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.

Thank you,

K

#151013
Feb 11, 2009 at 6:35am

Hey Tedor,

> 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:

– Pasted Max Patch, click to expand. –

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.

Cheers,
David

#151014
Feb 12, 2009 at 6:43pm

Hello David,

> 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.
===================================================
SR n

n : 1 .. 2000

set sampling rate

default is 1 Hz

— ex ————-
SR 120 

 :
1ad 0fb 0d2 0b9
1de 144 11e 10c
sr 120
20f 187 15f 14f
239 1ea 186 1f4
 :
—-
===================================================
FR n
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

—ex ———
FR 0.37  

 :
1ad 0fb 0d2 0b9
1de 144 11e 10c
fr 0.37
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,
K

#151015
Feb 14, 2009 at 5:42pm

wait a minute… I am useless…

I have to change the hex back to integers now so the modem can understand it, I guess… :)

#151016
Feb 14, 2009 at 6:36pm

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.

David

#151017
Feb 16, 2009 at 7:43pm

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.

Thanks David.

Krisztian

#151018

You must be logged in to reply to this topic.