Shop OBEX P1 Docs P2 Docs Learn Events
Getting a 5 volt output using VBASIC with the BS2p24? — Parallax Forums

Getting a 5 volt output using VBASIC with the BS2p24?

FreezepopFreezepop Posts: 23
edited 2007-12-22 17:33 in BASIC Stamp
Is there a command I could use in VBASIC to do that?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-12-20 00:47
    Any of the commands that produce a logic high / 1 level will provide approximately 5V on the I/O pin.
    The BS2p24 uses an SX microprocessor and Parallax has datasheets available for download that discuss
    the amount of current available from an I/O pin or group of I/O pins. The datasheets also show the
    I/O pin voltage vs current drain

    Look in the PBasic manual under the HIGH, INPUT, LOW, OUTPUT, and TOGGLE commands. Also
    look at the descriptions of the DIRS, INS, and OUTS predefined memory locations.

    Note that an I/O pin is not a power source although it can typically supply up to maybe 30ma
  • FreezepopFreezepop Posts: 23
    edited 2007-12-20 03:20
    I could do it in PBASIC no problem but the thing is that I only want the I/O pins be at HIGH when a certain condition is met in my VBASIC program.


    The only thing in my PBASIC code is asking my reader module to get the tag numbers >.>

    So the main thing I should be asking is how do I use VBASIC to communicate with my STAMP

    Post Edited (Freezepop) : 12/20/2007 3:30:48 AM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2007-12-20 03:51
    Ah!

    Generally, you have to communicate from a PC using serial I/O. Somehow, you're asking your PBasic code to send the RFID tag numbers to the PC. You have to ask your PBasic code to set the I/O pins HIGH or LOW. For example, say that whenever your Stamp receives an "A", it returns the last RFID code read or something else to indicate that nothing was read since the PC asked previously. You'd add additional codes "B" and "C" to set some I/O pin HIGH or LOW respectively. If you want multiple I/O pins, you could use a digit like 0 to 7 to represent 3 I/O pins and the numeric value received is copied to the 3 I/O pins as a group.
  • FreezepopFreezepop Posts: 23
    edited 2007-12-20 04:48
    Blargh, everything is fine and dandy but

    what I'm asking is there anyway using VB to tell the STAMP to activate one of it's IO pin.
  • FranklinFranklin Posts: 4,747
    edited 2007-12-20 04:52
    Mike Green said...
    You'd add additional codes "B" and "C" to set some I/O pin HIGH or LOW respectively. If you want multiple I/O pins, you could use a digit like 0 to 7 to represent 3 I/O pins and the numeric value received is copied to the 3 I/O pins as a group
    You can ask the stamp to set the pins high and tell it what pins to set high like Mike said but you can't TELL it to set pins high as far as I know.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-12-20 05:06
    Is VBASIC Microsoft Visual Basic and if so what version

    Jeff T
  • FreezepopFreezepop Posts: 23
    edited 2007-12-20 05:22
    Hmm, I think I'm making a bit of progress now, all I needed to do was put mscomm1.output=x

    Then x will be going to my stamp and there's where I'm stuck!
    So I went to do abit of searching and I found this
    Somebody said...
    'code by Shaun Wilson July 2/99
    'This code recieves a (1)on or (0)off state send from
    'your PC using Visual Basic 5 and controls the state of
    'pin 0

    datain var byte 'contains a 0 or a 1
    pin con 16 'stamps dedicated serial input pin
    baud con $4054 '9600 baud

    again:
    serin pin,baud, [noparse][[/noparse]datain]
    if datain = "1" then on
    if datain = "0" then off
    goto again

    on:
    high 0 'make pin 0 high
    goto again

    off:
    low 0 'make pin 0 low
    goto again

    So I guess with my BS2p24 I would write something about the SIn pin but I have no idea what to do with it since I'm not too hot with pbasic jumpin.gif

    Post Edited (Freezepop) : 12/20/2007 7:08:49 AM GMT
  • FreezepopFreezepop Posts: 23
    edited 2007-12-20 05:22
    ah yes, I'm using visual basic 6
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-12-20 07:09
    You virtually have it all. Shaun Wilsons code is set up for a BS2 so you would need to·change the baud constant·to that of·a BS2p, that would be from $4054 to $40F0.

    Jeff T.
  • FranklinFranklin Posts: 4,747
    edited 2007-12-20 18:02
    again:
    serin pin,baud, [noparse][[/noparse]datain] 
    if datain = "11" then 1on 
    if datain = "10" then 1off
    if datain = "21" then 2on 
    if datain = "20" then 2off
    goto again
    
    1on:
    high 1 'make pin 1 high
    goto again
    
    1off:
    low 1 'make pin 1 low
    goto again
     
    2on:
    high 2 'make pin 2 high
    goto again
    
    2off:
    low 2 'make pin 2 low
    goto again
    

    I'd probably use select case and a subroutine but this is the idea.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • FreezepopFreezepop Posts: 23
    edited 2007-12-21 14:40
    Eh I'm not too good with this, I basically copied all of shaun's code into my own which has the RFID tag reader code in it.


    But it says that serin is in used and I have completely no idea how to go around it any help?
    Sorry about this but I'm really not used to using PBASIC yet sad.gif
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-12-21 14:44
    Post your code as an attachment so we can see what you have.

    Jeff T.
  • FreezepopFreezepop Posts: 23
    edited 2007-12-22 00:40
    Somebody said...
    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}
    '
    [noparse][[/noparse] Program Description ]
    '
    ' Reads tags from a Parallax RFID reader and displays ID to debug screen


    '
    [noparse][[/noparse] Revision History ]


    '
    [noparse][[/noparse] I/O Definitions ]

    Enable PIN 0 ' low = reader on
    RX PIN 1 ' serial from reader



    '
    [noparse][[/noparse] Constants ]

    #SELECT $STAMP
    #CASE BS2, BS2E, BS2PE
    T2400 CON 396
    #CASE BS2SX, BS2P
    T2400 CON 1021

    #ENDSELECT

    Baud CON T2400

    LastTag CON 3


    #DEFINE __No_SPRAM = ($STAMP < BS2P) ' does module have SPRAM?


    '
    [noparse][[/noparse] Variables ]

    #IF __No_SPRAM #THEN
    buf VAR Byte(10) ' RFID bytes buffer
    #ELSE
    Char VAR Byte ' character to test
    #ENDIF

    tagNum VAR Nib ' from EEPROM table
    idx VAR Byte ' tag byte index
    number VAR Word


    '
    [noparse][[/noparse] Initialization ]

    Reset:
    HIGH Enable ' turn of RFID reader



    '
    [noparse][[/noparse] Program Code ]

    Main:
    LOW Enable ' activate the reader
    #IF __No_SPRAM #THEN
    SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), STR buf\10] ' wait for hdr + ID
    #ELSE
    SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), SPSTR 10]
    #ENDIF
    HIGH Enable ' deactivate reader
    number = 0
    Display_Tag:

    FOR idx = 0 TO 9 ' scan bytes in tag


    GET idx, Char ' read char from SPRAM
    number = number + char

    NEXT
    number = number * 8
    DEBUG DEC number," "
    DEBUG CR
    PAUSE 500
    GOTO main ' repeats code

    'code by Shaun Wilson July 2/99
    'This code recieves a (1)on or (0)off state send from
    'your PC using Visual Basic 5 and controls the state of
    'pin 0

    datain VAR Byte 'contains a 0 or a 1
    PIN CON 16 'stamps dedicated serial input pin
    baud CON $4054 '9600 baud

    again:
    SERIN PIN,baud, [noparse][[/noparse]datain]
    IF datain = "1" THEN ON
    IF datain = "0" THEN off
    goto again
  • FranklinFranklin Posts: 4,747
    edited 2007-12-22 02:33
    What is it again that you want to do?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-12-22 03:07
    Freezepop -

    "PIN" became a reserved word as of PBASIC 2.5. Use some other variable name, and the problem will disappear.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • FreezepopFreezepop Posts: 23
    edited 2007-12-22 07:08
    Thanks Bates I'll try that

    And Franklin, I want to make this code work, it has to control the RFID reader and the activation of 1 of the other pins to a 5 volt via datain by VB
  • FranklinFranklin Posts: 4,747
    edited 2007-12-22 17:33
    Take the part of the code that lights the pins when it gets input from the pc and just work with that until you get it working. Then add another part of the code until you have the whole thing working. Let us know how it goes. Good luck.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
Sign In or Register to comment.