Split Serial Data

Tupac Torres Bartsch's icon

Hey Guys
I Try to read a Potentiometer with my arduino nano over serial.
the values of the potentiometer reach from 0 to 1023

i use the serial object in Max to directly read from the serial port.
and i get increasing data.
but instead of reaching from 0 to 1023, it breaks 4 times around 250 and begins with 0 again.

i have no idea what this could mean.
i guess its the right stream i get because adding all 0 to 250 (somemore) streams together comes to nearly the same range. might be some issue with the formating from serial to max. soehow cause in the serial console in arduino the ranges are fitting well.

does someone know what can come up from serial to max?
or also had a problem like this?

thanks for answeres ;)

Source Audio's icon

Without supplied patch and arduino code one has to guess what You are doing wrong.
Even if it is an easy to guess thing, it would be better to make it easier for anyone
wanting to help You if You would provide more info.
If You also like to guess about things here a tip - int limit of 0-255 in serialWrite

Tupac Torres Bartsch's icon

of course
code and patch

does it mean ther has to be a different comand for writing the numbers?

Source Audio's icon

Yes, serialWrite can send only values 0-255.
So You have 2 options, organise the 0- 1023 range into
2 byte string, similar to midi msb lsb, or simply use serialPrint.
SerialPrint sends ASCII values and takes care of dividing
numbers into bytes properly.
BUT in Max You need to convert ASCII values that get sent by
serialPrint into integers.
here is example patch that does so:

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

arduino part:

int poti = analogRead(A2);
Serial.println(poti);
---------------------------
When You need to send several analog readouts to max,
then You need either some kind of indentifier for each
channel, or combine several Inputs into a string,
and unpack that in max.
If You need some examples feel free to ask.

Tupac Torres Bartsch's icon

yes! guy this is working fine.

did i understand this right

do you clear the the zl_group_100 object with a bang?
does this mean that you can go until a 100 unit number?

how do you make the cables so nice straight?

Source Audio's icon

zl group collects data untill carriage return gets received. (ASCII 13)
thats sel 13 ->> bang = output collected data and clear zl group.
That happens when one uses println ( print line) in arduino.
If You expect larger nuber of values , increase that to 512 or whatever.
-----
Select Cables - align - then they align ...