Basic Stamp communication with max/msp
JonA
Posts: 4
Hi,
I am using a bs2 board with four photoresistors and the RCTIME command to convert the data between 0 + 255. I am trying to send this data to max/msp via the serial object but having trouble separating the information(in max) from the four sensors which are giving data ok in the basic stamp. (I want to get the data form each sensor separately). Should I ask the stamp code to display the data in one continuous stream for all sensors or a separate line of data for each sensor? for max to then try and separate. The end result is to then use the values from each separate sensor in max.
Any help would be greatly appreciated.
Thanks
Jonathan
'sInPin CON 2 'serial in pin
sOutPin CON 16 'serial out pin
'sOutPin1 CON 1
rcPin0 VAR BYTE 'pin for rcTime
rcPin1 VAR BYTE
rcPin2 VAR BYTE
rcPin3 VAR BYTE
'rcPin1 CON 1 'pin for rcTime
rValue VAR WORD 'raw reading from RCTIME
'rValue1 VAR WORD
bValue0 VAR BYTE 'result scaled and limited to fit in a single byte
bValue1 VAR BYTE
bValue2 VAR BYTE
bValue3 VAR BYTE
'bValue1 VAR BYTE
bValuePrev VAR BYTE 'previous value
'bValuePrev1 VAR BYTE 'previous value
top:
FOR rcPin0 = 0 TO 3
PAUSE 200 'pause between readings - CALIBRATE??was 200
'HIGH 10 'set pin high
HIGH rcPin0
HIGH rcPin1
HIGH rcPin2
HIGH rcPin3
PAUSE 1
'RCTIME rcPin,0,rValue 'read the pin
RCTIME 0,1,rValue
bValue0 = rValue MAX 255
RCTIME 1,1,rValue
bValue1 = rValue MAX 255
RCTIME 2,1,rValue
bValue2 = rValue MAX 255
RCTIME 3,1,rValue
bValue3 = rValue MAX 255
'bValue = rValue MAX 255 'limit result to a byte
IF bValue0 <> bValuePrev THEN report 'check if it's changed
'IF bValue1 <> bValuePrev THEN report
'IF bValue2 <> bValuePrev THEN report
'IF bValue3 <> bValuePrev THEN report
GOTO top
report:
bValuePrev = bValue0 'record current value
bValuePrev = bValue1
bValuePrev = bValue2
bValuePrev = bValue3
'bValuePrev1 = bValue1
'DEBUG DEC rValue, "photo: ",DEC rcPin, "=", DEC bValue, CR
'DEBUG DEC rValue1, " photores1: ", DEC bValue1, CR
SEROUT sOutPin,16468,[noparse][[/noparse]DEC bValue0, DEC bValue1, DEC bValue2, DEC bValue3]
'SEROUT sOutPin1,16390,[noparse][[/noparse]bValue1]
DEBUG DEC rValue, CR
NEXT
GOTO top
I am using a bs2 board with four photoresistors and the RCTIME command to convert the data between 0 + 255. I am trying to send this data to max/msp via the serial object but having trouble separating the information(in max) from the four sensors which are giving data ok in the basic stamp. (I want to get the data form each sensor separately). Should I ask the stamp code to display the data in one continuous stream for all sensors or a separate line of data for each sensor? for max to then try and separate. The end result is to then use the values from each separate sensor in max.
Any help would be greatly appreciated.
Thanks
Jonathan
'sInPin CON 2 'serial in pin
sOutPin CON 16 'serial out pin
'sOutPin1 CON 1
rcPin0 VAR BYTE 'pin for rcTime
rcPin1 VAR BYTE
rcPin2 VAR BYTE
rcPin3 VAR BYTE
'rcPin1 CON 1 'pin for rcTime
rValue VAR WORD 'raw reading from RCTIME
'rValue1 VAR WORD
bValue0 VAR BYTE 'result scaled and limited to fit in a single byte
bValue1 VAR BYTE
bValue2 VAR BYTE
bValue3 VAR BYTE
'bValue1 VAR BYTE
bValuePrev VAR BYTE 'previous value
'bValuePrev1 VAR BYTE 'previous value
top:
FOR rcPin0 = 0 TO 3
PAUSE 200 'pause between readings - CALIBRATE??was 200
'HIGH 10 'set pin high
HIGH rcPin0
HIGH rcPin1
HIGH rcPin2
HIGH rcPin3
PAUSE 1
'RCTIME rcPin,0,rValue 'read the pin
RCTIME 0,1,rValue
bValue0 = rValue MAX 255
RCTIME 1,1,rValue
bValue1 = rValue MAX 255
RCTIME 2,1,rValue
bValue2 = rValue MAX 255
RCTIME 3,1,rValue
bValue3 = rValue MAX 255
'bValue = rValue MAX 255 'limit result to a byte
IF bValue0 <> bValuePrev THEN report 'check if it's changed
'IF bValue1 <> bValuePrev THEN report
'IF bValue2 <> bValuePrev THEN report
'IF bValue3 <> bValuePrev THEN report
GOTO top
report:
bValuePrev = bValue0 'record current value
bValuePrev = bValue1
bValuePrev = bValue2
bValuePrev = bValue3
'bValuePrev1 = bValue1
'DEBUG DEC rValue, "photo: ",DEC rcPin, "=", DEC bValue, CR
'DEBUG DEC rValue1, " photores1: ", DEC bValue1, CR
SEROUT sOutPin,16468,[noparse][[/noparse]DEC bValue0, DEC bValue1, DEC bValue2, DEC bValue3]
'SEROUT sOutPin1,16390,[noparse][[/noparse]bValue1]
DEBUG DEC rValue, CR
NEXT
GOTO top
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
J
Would this code be more suitable for sending the datato max/msp?
Thanks
Jon
'read a photocell (or any other variable resistor) with RCTIME
'and report the result with SEROUT as a byte value (0 to 255)
'sInPin CON 2 'serial in pin
sOutPin CON 0 'serial out pin
rcPin VAR BYTE 'raw reading from RCTIME
rValue VAR WORD
bValue VAR BYTE 'result scaled and limited to fit in a single byte
bValuePrev VAR BYTE 'previous value
top:
FOR rcPin = 0 TO 3
PAUSE 200 'pause between readings - CALIBRATE??
HIGH rcPin
PAUSE 1
RCTIME rcPin,1,rValue 'read the pin
bValue = rValue MAX 255 'limit result to a byte
IF bValue <> bValuePrev THEN report 'check if it's changed
GOTO top
report:
bValuePrev = bValue 'record current value
' bValuePrev1 = bValue1
DEBUG DEC rValue, "photo: ", DEC rcPin, "=", DEC bValue, CR
SEROUT sOutPin,16390,[noparse][[/noparse]bValue] '16390
NEXT
GOTO top
'These are the baudmode values for usable baud rates for the BS2:
'16468 for 9600, 16416 for 19200, 16390 for 38400
Hint: Don't use embedded constants for the baudmode in SEROUT ... this ALWAYS leads to trouble. Use CON or better yet, a conditional compilation section that allows you to move from one Stamp to another without having to change constants.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA