Shop OBEX P1 Docs P2 Docs Learn Events
digital i/o board communication problem — Parallax Forums

digital i/o board communication problem

peleus21peleus21 Posts: 16
edited 2011-06-11 07:44 in BASIC Stamp
hey all

i am new to microcontrollers and programming. i am working hard to learn fast. i have studied the "what is a microcontroller" and "stamp works"

so here is my query or actually 2 of them
i have the Parallax Digital I/O Board connected to a BS2pe MOBO using serial connection

here is my code is basically the demo code
' {$STAMP BS2pe}
' {$PBASIC 2.5}
DataIO PIN 8 ' (AP8)DIN & DATA_RLY
Clock PIN 9 ' (AP9)DIGITAL I/O
HC595 PIN 11 ' (AA2)LAT_RLY Pin
HC165 PIN 12 ' (AA3)LOAD_IN Pin
' constants
Yes CON 1 ' Yes Constant
No CON 0 ' No Constant
' variables
rlout VAR Byte ' relay out Variable
optos VAR Byte ' Opto Status Byte
' program
DEBUG CLS
HIGH HC165 ' Make Output And HIGH
DO
GOSUB Out_595 ' Update 74HC595
GOSUB In_165 ' Read 74HC165
GOSUB door_Open
LOOP
STOP
' subroutines
Out_595:
SHIFTOUT DataIO, Clock, MSBFIRST, [rlout]
PULSOUT HC595, 5 ' Latch Outputs
RETURN
In_165:
PULSOUT HC165, 5 ' Load Inputs
SHIFTIN DataIO, Clock, MSBPRE, [optos]
RETURN
Door_Open:
DO
GOSUB Out_595
GOSUB In_165
IF optos = %00001111 THEN
rlout = %00000011
ELSEIF optos = %00001011 THEN
rlout = %00000011
ELSEIF optos = %00000111 THEN
rlout = %00000011
ELSEIF optos = %00000011 THEN
rlout = %00000011
ELSEIF optos = %00000010 THEN
rlout = %00000010
ELSEIF optos = %00000001 THEN
rlout = %00000001
ELSEIF optos = %00000000 THEN
rlout = %00000000
RETURN
ELSE
ENDIF
LOOP

relay 1 and 2 open the doors, inputs 1,2 and 3,4 define when it is all the way closed or open so motors do not burn out.

question one: is there a way to define only the info i want ie. make get and send data to relay and input 2 for instance without haveing to define all other input / output possibilities

second problem might not be anything if there is a better way but if i try to add "door_open" subroutine into another command ( i added a gas sensor program) or subroutine it will leave the 2 relays on and carry on. in fact nothing i do will turn them off. it must be something simple i am missing

Comments

  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2011-06-04 06:34
    Can you post where you got this demo from web site link to it thanks
  • peleus21peleus21 Posts: 16
    edited 2011-06-04 07:10
    sure can

    http://www.parallax.com/Portals/0/Downloads/docs/prod/boards/DIOBBASICStampCodeV1.0.zip

    it is the Diob serial test bs2 file

    i am trying to expand on it but have never programmed a serial communication code before
  • FranklinFranklin Posts: 4,747
    edited 2011-06-04 07:52
    It would help if you would post your actual app you are having trouble with (ad an attachment) and enclose any code you post with "[code]" tags.
  • peleus21peleus21 Posts: 16
    edited 2011-06-04 09:12
    well here is my code file
    my application is as stated above
    Parallax Digital I/O Board connected to a BS2pe MOBO using serial connection

    i want to control a set of motors to move a door. it has switches that tell controller when the door is all the way open or closed so that it does not keep on trying to open or close it after it is opened or closed all the way. i am having trouble with this part


    [
    GOSUB Out_595
    GOSUB In_165
    IF optos = %00001111 THEN
    rlout = %00000011
    ELSEIF optos = %00001011 THEN
    rlout = %00000011
    ELSEIF optos = %00000111 THEN
    rlout = %00000011
    ELSEIF optos = %00000011 THEN
    rlout = %00000011
    ELSEIF optos = %00000010 THEN
    rlout = %00000010
    ELSEIF optos = %00000001 THEN
    rlout = %00000001
    ELSEIF optos = %00000000 THEN
    rlout = %00000000
    RETURN
    ELSE
    ENDIF
    LOOP
    ]
    is there a better way to do this
    say i want only to deal with the third and fourth digit in the binary string regardless what the other binary numbers were or better yet is there a way to get away from using the binary all together without using to much program space. would rather use less space regardless the method
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-06-04 09:32
    peleus21,

    Welcome to the forum!

    attachment.php?attachmentid=78421&d=1297987572

    -Phil
  • peleus21peleus21 Posts: 16
    edited 2011-06-10 23:00
    sooo.....
    can anybody refer me to a refrence on how to write and or understand serial communication programming?
  • Mike GreenMike Green Posts: 23,101
    edited 2011-06-11 07:44
    "Serial communication programming" covers a wide range of topics. If you're referring to the use of the 74HC165 and 74HC595 for I/O expansion, the StampWorks Manual covers this pretty well. There are also several Nuts and Volts Columns. For the StampWorks Manual, click on the Downloads button on Parallax's main webpage, then you'll see a button for all the tutorials. Click on that. For the Nuts and Volts Column, click on the Resources button on the main webpage. You'll get an index to the columns. I don't remember which one. I suggest investing the time to browse through the index. They're rich with advice and examples.
Sign In or Register to comment.