Send structured data over serial from MaxMSP to uC

jeremy savonet's icon

Hi there,

I'm new to MaxMSP and this is my first post at all.
I hope my post follow the rules and is at the right place.
I looked over the forum and Google my problem without success so I came here to get help.

What I want to do:

Send a strctured data over serial to a microcontroller:

Here is an example of such a data stream

struct data
{
uint8 magic = 0xA5;
uint8 val1 = 125;
uint16 val2 = 470;
float val3 = 3.2;
}

And here is my actual patch:

Max Patch
Copy patch and select New From Clipboard in Max.


When I monitor what Max send over the serial link, it appears uint16 values are cast to uint8 value and only the first byte is sent.
For the float value it is the same issue.

Any help would be greatly appreciated,

Regards,
Jeremy SAVONET

Source Audio's icon

patch you posted does not show what and how you try to send
to serial object.
And also not what is that uC expecting to receive and parse.

In Max semicolon in a message has special meanning
and you have to either escape it with backslash
or enclose whole massage with quotas, otherwise max will break the
data structure
"{
uint8 magic = 0xA5;
uint8 val1 = 125;
uint16 val2 = 470;
float val3 = 3.2;
}"
serial objects sends ascii chars 0 - 255, you need atoi
object


jeremy savonet's icon

Thank you for the quick reply.

Patch I have posted have a pack object that get the value, then a prepend object to add the magic number and this is passed to the serial object.

What did you mean by:

patch you posted does not show what and how you try to send
to serial object.

And also not what is that uC expecting to receive and parse.

This is a custom board with a PIC microcontroller but this does not impact the way the data is sent by MaxMSP as far I know. It can be replace by an arduino if needed for debug purpose.

Not sure to understand what you mean by:

serial objects sends ascii chars 0 - 255, you need atoi
object

I need atoi on the uC side or in Max before sending data to the serial object ?

Thank you for your time,

Source Audio's icon

this is the patch you posted :
no trace of serial object in there

you need atoi in max in order to convert what you want to send to ascii
code

Max Patch
Copy patch and select New From Clipboard in Max.

jeremy savonet's icon

Thank you for the feedbacks.

Indeed very weird. I'm not able to copy my patch to the clipboard apparently.

Thank you for the patch. This is a way of doing it. It complexify the parsing on the uC side but this seems the only solution as Max send only ascii char.

Have a nice day and thanks again for the support,
Kind regards,