Forums > MaxMSP

BS2 Word/16 Bit Communication

July 18, 2006 | 3:00 pm

Hi everyone,

I’m trying to get a BS2SX talking with MAXMsp’s serial object using Word sized variables. So far I can communicate just fine using any numbers below 255 (byte sized) but after that it gets a bit messy. I realized that I should send over the word variable as a HIGHBYTE and a LOWBYTE and have MAXMsp shift the Highbyte and then add them together.

This seems to *want* to work, but MAXMsp appears to get off track when taking in the numbers as the HIGHBYTE and LOWBYTE values appear to erratically swap places. I’m trying to find a good method to get consistent and clean input and separation of the two byte’s.

I’ve tried having MAX send a single ASCII character out to the stamp when it’s ready to get the next byte, the problem there is how to I only want to get a bang from the serial object when it receives input. As of right now it passes bangs from the metro right through, which makes it impossible to have MAX send out a new character only when it receives input.

Thoughts and suggestions?


July 18, 2006 | 3:44 pm

Jake,

check out the serial examples with Max on Tom Igoe’s Physical Computing
pages.

http://www.tigoe.net

i found his web pages (and his book) to be the best resources for
getting micro controllers to play nice with the Max serial object.
(though i use midi now ’cause [serial] is too unstable for live
performance…)


July 18, 2006 | 4:55 pm

Thanks for your link langdon. I had been to his page prior but your re-link made me look closer at his BS2 code. I’ve been wrestling with this for the better part of a week and finally got it working this morning. The simplicity of my final patch made me smack my head against the desk. You should’ve seen my patches before…there was tons of stuff about bi-directional communication and Gswitches to direct the different bytes…it was a mess. I’ll post my bs2 code and the patch for anyone who needs large number support.

BS2(sx) Code:

‘ {$STAMP BS2sx}
‘ {$PBASIC 2.5}
‘ {$PORT COM4}

SerInData VAR Byte ‘number to match to incoming data
SerWait CON 1000 ‘ms to wait for input before timing out
N9600 CON 240 ‘BS2 baudmode values: 16468/9600, 16416/19200, 16390/38400
‘See SEROUT in the Basic Stamp manual for details.

RCvar VAR Word

Main:
HIGH 8
PAUSE 1
RCTIME 8,1,RCvar

SERIN 16,N9600,SerWait,Main,[SerInData]
SEROUT 16,N9600,[RCvar.HIGHBYTE, RCvar.LOWBYTE]
GOTO Main

MAXMsp (4.5.7) patch:

#P window setfont "Sans Serif" 9.;
#P number 126 242 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 142 147 34 9109513 thresh;
#P newex 142 174 56 9109513 unpack i i i;
#P newex 163 92 33 9109513 list 61;
#P toggle 142 25 15 0;
#P newex 142 59 45 9109513 metro 25;
#P number 165 308 61 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 165 288 27 9109513 +;
#P newex 165 262 27 9109513 < < 8;
#P number 165 242 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 206 242 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 107 61 32 9109513 port d;
#P message 67 61 32 9109513 port a;
#P newex 142 122 61 9109513 serial d 9600;
#P fasten 11 0 13 0 147 217 131 217;
#P connect 9 0 8 0;
#P connect 8 0 0 0;
#P fasten 10 0 0 0 168 117 147 117;
#P fasten 2 0 0 0 112 100 147 100;
#P fasten 1 0 0 0 72 100 147 100;
#P connect 0 0 12 0;
#P connect 12 0 11 0;
#P fasten 8 0 10 0 147 86 168 86;
#P connect 11 1 4 0;
#P connect 4 0 5 0;
#P connect 5 0 6 0;
#P connect 6 0 7 0;
#P fasten 3 0 6 1 211 283 187 283;
#P fasten 11 2 3 0 193 220 211 220;
#P window clipboard copycount 14;


Viewing 3 posts - 1 through 3 (of 3 total)