Shop OBEX P1 Docs P2 Docs Learn Events
How to connect two colorpal sensors at the same time to a boe? — Parallax Forums

How to connect two colorpal sensors at the same time to a boe?

tlflorestlflores Posts: 6
edited 2016-01-27 10:51 in BASIC Stamp
I am trying to connect two colorpal sensors to a boe. One on each side of the robot so that a target on either side can be identified. I have no problem with one that works great. But when I connect the other I cannot get it to work also. When I try to adapt the code I get a sio already defined error or if I connect both colorpals to the same pin both do not work correctly. Does anyone know of a way that this can be done? Thanks.

Comments

  • Post your code and a wiring diagram?
  • Here is a little more explanation on what I am trying to do. I have attached pictures and the code that I am using. I am trying to get the colorpal to identify yellow and turn a light on indicating that it has identified yellow. When I attach one sensor it works fine. But when I attach two sensors there is a conflict and neither sensor identifies yellow. I know that the conflict is in the code but I do not know what to do to resolve it. This pictures show one sensor and then two sensors attached. I ran the cables so that I could get everything in the photo. When testing I move the sensors to face the target.

    '
    [ I/O Definitions ]

    sio PIN 15 ' Serial I/O com pin for ColorPAL.


    '
    [ Constants ]

    ' Baudrate definitions. Serial I/O must be open-drain. The ColorPAL includes
    ' a pullup internally.


    baud CON 119 + 32768


    '
    [ Variables ]

    red VAR Word ' Received RGB values from ColorPAL.
    grn VAR Word
    blu VAR Word

    '
    [ Initialization ]

    GOSUB Reset ' Reset the ColorPAL and enter direct command mode.

    '
    [ Program Code ]

    SEROUT sio, baud, ["= (00 $ m) !"] 'Program ColorPAL to send $ then color data.

    DO
    SERIN sio, baud, [WAIT("$"), HEX3 red, HEX3 grn, HEX3 blu] ' Receive RGB data back.
    'turn on light for yellow
    IF (red <= 255 AND red >=100) AND (grn <= 255 AND grn >= 100) AND (blu >= 0 AND blu <=100) THEN
    HIGH 13
    PAUSE 2000
    LOW 13
    ENDIF
    LOOP

    '
    [ Subroutines ]

    ' Reset: Sends a long break to reset ColorPAL and enter direct command mode.

    Reset:
    LOW sio 'Pull sio low to eliminate any residual charge.
    INPUT sio 'Return pin to input.
    DO UNTIL sio : LOOP 'Wait for pin to be pulled high by ColorPAL.
    LOW sio 'Pull pin low.
    PAUSE 80 'Keep low for 80ms to enter Direct mode.
    INPUT sio 'Return pin to input.
    PAUSE 10 'Pause another 10ms
    RETURN
    4160 x 2020 - 262K
    3768 x 1908 - 345K
  • You need to assign separate pins for the two ColorPals:
    LeftCP     pin   15
    RightCP    pin   14
    

    and wire them accordingly.

    Then I would make sio a variable
    sio   VAR   Nib
    

    Then, for example, you can do the resetting, one at a time
    sio = LeftCP
    gosub reset
    SEROUT LeftCP, baud, ["= (00 $ m) !"] 'Program ColorPAL to send $ then color data
    
    sio = RightCP
    gosub reset
    SEROUT RightCP, baud, ["= (00 $ m) !"] 'Program ColorPAL to send $ then color data
    

    finally, now you can
    SERIN LeftCP, baud, [WAIT("$"), HEX3 red, HEX3 grn, HEX3 blu] ' Receive RGB data back
    'do something based on the color returned from the left
    
    SERIN RightCP, baud, [WAIT("$"), HEX3 red, HEX3 grn, HEX3 blu] ' Receive RGB data back
    'and then the right
    
  • to: tomcrawford
    This is a good idea and I tried it but it does not work. As far as I can see a variable cannot accept a pin value. I will keep trying this to make sure. Thanks
  • Don't know what I was thinking about. Define them with CON
    LeftCP    CON   15
    RightCP   CON   14
    
    
  • Thanks this is now working.
Sign In or Register to comment.