Shop OBEX P1 Docs P2 Docs Learn Events
Basic Stamp communication with max/msp — Parallax Forums

Basic Stamp communication with max/msp

JonAJonA Posts: 4
edited 2005-05-04 20:41 in BASIC Stamp
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

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-04 02:07
    It may be easier to send all four values in on packet; it will certainly simplify processing on the receving end.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • JonAJonA Posts: 4
    edited 2005-05-04 14:22
    Ok, ill give that a try, thanks.

    J
  • JonAJonA Posts: 4
    edited 2005-05-04 15:53
    Hello again,

    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
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-04 16:04
    If you have the variable space, use a four-word array for your RCTIME values. Then, unless you want to scale them to an 8-bit value, you'll need to send them as two-bytes each. I don't know what you're referring to when you use the term "max/msp" so I can't help on that end.

    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
  • JonAJonA Posts: 4
    edited 2005-05-04 20:41
    Thanks for the info, ill see how i get on with that. Max/msp is a signal processing patch-cord style software program.
Sign In or Register to comment.