Shop OBEX P1 Docs P2 Docs Learn Events
PC controlled BS2 (a non stand-alone controller) — Parallax Forums

PC controlled BS2 (a non stand-alone controller)

cclaud2cclaud2 Posts: 21
edited 2007-08-14 00:38 in BASIC Stamp
Hi,
Is there anyway to to control the BS2 with your PC so that you are not restrained by the amount of memory the BS2 has or the processor speed the BS2 runs at? I just want to be able to control all the I/Os on the BS2 while having the BS2 connected to my computer via its USB port. Does parallax sell anything like this?

The controller would never have to act as a stand alone controller.

Please help.

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-08-12 22:37
    You don't need any additional hardware — just a short program running on the BS2 that reads commands from the DEBUG port and executes them. The following command set, each of which takes a 4-digit hexadecimal argument, is all you need for simple I/O:

    D xxxx Set the direction for each port pin.
    O xxxx Output to the port pins.
    I xxxx Input from the port pins and send the data back to the PC.

    Of course, the BASIC Stamp is capable of more than simple I/O. If you want pulsed output, audio output, etc., you can always create and interpret commands for those as well.

    -Phil
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-08-12 23:01
    Hi cclaud2, yes the Stamp can be used to·transmit and recieve I/O serially to and·from the PC and at the same time perform and control other functions. Check out this thread for an example http://forums.parallax.com/showthread.php?p=654587

    Jeff T.
  • D FaustD Faust Posts: 608
    edited 2007-08-12 23:10
    This may not be what cclaud2 was getting at, but what software can be used on a PC to write programs that would communicate with a stamp (or other micro). Thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    LOOKDOWN ThisThread, [noparse][[/noparse]Your_?, My_?, Cool_Thing], looknum
    LOOKUP looknum, [noparse][[/noparse]1, 2, 3], subnum
    ON subnum GOTO Hope_this_helps, Thanks!, WOW!!
    END 
    
  • cclaud2cclaud2 Posts: 21
    edited 2007-08-12 23:33
    So if you have a very large program and many variables, when you go to debug your program the basic stamp will not run out of memory because the computer is using its own memory and processor?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-08-12 23:35
    That's right. The BASIC Stamp is just acting as a dumb I/O terminus. All the computing is being done by the PC.

    -Phil
  • D FaustD Faust Posts: 608
    edited 2007-08-12 23:43
    I am confused! cclaud2 you are writing about putting a PBASIC code into the stamp and not running out of memory right?
    How does the following help with that?
    D xxxx Set the direction for each port pin.
    O xxxx Output to the port pins.
    I xxxx Input from the port pins and send the data back to the PC.
    All I see that this program would do is make a primitive user interface, not run any programs. Sorry to burst into the post like this, but isn't something (software) missing on the PC side?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    LOOKDOWN ThisThread, [noparse][[/noparse]Your_?, My_?, Cool_Thing], looknum
    LOOKUP looknum, [noparse][[/noparse]1, 2, 3], subnum
    ON subnum GOTO Hope_this_helps, Thanks!, WOW!!
    END 
    

    Post Edited (D Faust) : 8/12/2007 11:58:41 PM GMT
  • pwillardpwillard Posts: 321
    edited 2007-08-12 23:53
    Somewhat confusing request... btw.

    If you want I/O control, you COULD make a stamp respond to serial input from a PC program... but it's not really something you would do with the STAMP IDE it would be better accomplised as a separate program... like hyperterm.· But you still need good code in the STAMP to listen to it.· I take it that you don't want to write the code yourself.· This type of PC-microcontroller-I/O interface is common in robotics... I've seen websites selling items like this.

    Hmmm. You might want something like a pbasic to run on the PC and drive real world I/O's that isn't necessarily the STAMP? Isn't that what the PC's parallel port can be used for if driven by Visual Basic or something similar? Like this, maybe: http://www.anthillsolutions.com/prim_en.html

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

    There's nothing like a new idea and a warm soldering iron.

    Post Edited (pwillard) : 8/13/2007 12:03:19 AM GMT
  • D FaustD Faust Posts: 608
    edited 2007-08-13 00:00
    Is hyperterm a program that runs on your pc and can use a serial port to communicate to the outside? If so, what do you use to program it. Sorry, trying to expand.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    LOOKDOWN ThisThread, [noparse][[/noparse]Your_?, My_?, Cool_Thing], looknum
    LOOKUP looknum, [noparse][[/noparse]1, 2, 3], subnum
    ON subnum GOTO Hope_this_helps, Thanks!, WOW!!
    END 
    
  • cclaud2cclaud2 Posts: 21
    edited 2007-08-13 00:00
    I want to use the BS2 because I am in no way an experienced programmer or controls expert. I like the stamp because of all of its tutorials and online support. Maybe from here (BS2) I will venture elsewhere, but for now I want to stick with what is familiar to me. Thanks for the input.
  • D FaustD Faust Posts: 608
    edited 2007-08-13 00:05
    It looks to me that you are looking for a simulator for the stamp, correct. cclaud2, waht do you want to do, run a PBASIC program on your computer and use the stamps I/Os. OR just recieve data (from IOs) and create output. In the second case YOU are the processor not the stamp. BASICally (haha) what are you looking to do?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    LOOKDOWN ThisThread, [noparse][[/noparse]Your_?, My_?, Cool_Thing], looknum
    LOOKUP looknum, [noparse][[/noparse]1, 2, 3], subnum
    ON subnum GOTO Hope_this_helps, Thanks!, WOW!!
    END 
    
  • cclaud2cclaud2 Posts: 21
    edited 2007-08-13 00:17
    Yes, I want to "run a PBASIC program on [noparse][[/noparse]my] computer and use the stamps I/Os." I would also like to receive data such as temperature and pressure from from devices such as the LM34 and ADC0834 and use those variable in my program, which is running on my computer and not the stamp. Is this possible, or is there a better way to do this while still using PBASIC.
  • D FaustD Faust Posts: 608
    edited 2007-08-13 00:50
    Your question is now a lot clearer. I know of nothing that would do such a thing, but I myself am new to computer programming. As far as bypassing speed and memory limitations, there is a wide variety of stamps with different memory size and processor speeds. You should probably just buy a better stamp unless you want to convert you PBASIC into something that can run on a computer.

    From what you are saying you want to do it won't work.(simply anyway) Hope this helps.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    LOOKDOWN ThisThread, [noparse][[/noparse]Your_?, My_?, Cool_Thing], looknum
    LOOKUP looknum, [noparse][[/noparse]1, 2, 3], subnum
    ON subnum GOTO Hope_this_helps, Thanks!, WOW!!
    END 
    
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-08-13 01:15
    I am coming into this a little late but if you’re trying to run the PBASIC code on the PC you cannot. PBASIC can only execute from the BASIC Stamp. You must download the code. If you’re out of memory on the BS2 then you may be able to optimize your code or switch to another model that has more program memory. Of course, with another model the code will have to be written specifically to take advantage of the slot architecture. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-08-13 01:45
    cclaud2 said...
    Yes, I want to "run a PBASIC program on [noparse][[/noparse]my] computer and use the stamps I/Os."
    Chris is right: there are no PC-resident PBASIC interpreters that I know of (not that that wouldn't be an interesting project in its own right). But that doesn't preclude your using Visual Basic, Perl, Python, QBASIC, or any number of other PC-resident languages that have serial communication capabilities. You will still have to write a program in one of those other languages to send comands to the BS2, receive responses, and perform calculations. But again, the BS2-resident program to carry out the commands that it receives from the PC could be rather simple.

    -Phil
  • Kevin WoodKevin Wood Posts: 1,266
    edited 2007-08-13 02:21
    When using your PC to control a BS2, you really have 2 different programs running - one on the BS2, written in PBasic, and another running on the PC, written in whatever language you choose (but NOT PBasic, as it only "runs" on the Basic Stamps).

    So let's suppose you want to use your computer to run a program that monitors temperature and pressure of some system, and you want to connect the temperature and pressure sensors to a BS2. Since the BS2 will be handling the sensors, there has to be a program there to at least read the sensors. However, since the BS2 also needs to a) receive instructions from the PC, and b) send data to the PC, the PBasic program also need to be able to do this, too.

    So this is 4 tasks for the BS2:
    1. Get input from the PC
    2. Get the temperature reading
    3. Get the pressure reading
    4. Send the data to the PC

    Since we want to use the PC to request the current temperature or pressure readings, we'll create some kind of program that has 2 buttons called (you guessed it!) Get Temperature and Get Pressure. When either of these buttons is pressed, the application will do several things:

    1. It will create a serial port connection to the BS2
    2. It will send a "command" to the BS2 requesting the appropriate info
    3. It will wait for and receive the info back from the BS2
    4. It will close the serial port connection to the BS2
    5. It will play a variety of musical tunes based on the temperature and pressure readings

    Since there are only 2 buttons for this PC application, and since each has to send a "command" to the BS2, and since the BS2 is well suited to receiving bytes, we decide to send a "1" to get the temperature, and a "2" to get the pressure. This allows us to write a Pbasic program that looks something like this:


    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    ' ===================== Declarations ============================
    
    Cmd              VAR     Byte
    IoPin            CON     16
    Baudmode         CON     16468
    Temeperature     VAR     Byte
    Pressure         VAR     Byte
    
    ' ===================== Begin Program ============================
    
    Main:
      DO
        GOSUB GetInputFromPc
        GOSUB PerformSomeAction
      LOOP
    
    GetInputFromPc:
      SERIN  IoPin, Baudmode, [noparse][[/noparse]Cmd]  ' sets value of Cmd
      RETURN
    
    PerformSomeAction:
      SELECT Cmd
        CASE "1"
          GOSUB ReadTemperatureSensor
        CASE "2"
          GOSUB ReadPressureSensor
      ENDSELECT
      RETURN
    
    ReadTemperatureSensor:
      'Temperature sensor code goes here
      GOSUB SendDataToPc
      RETURN
    
    ReadPressureSensor:
      'Pressure sensor code goes here
      GOSUB SendDataToPc
      RETURN
    
    SendDataToPc:
      'Output code goes here
      RETURN
    
    



    Since the Stamp is looking for a command from the PC, or doing something, we'll put it into a loop that gets input from the PC and then does something based on that input. In this case there are only 2 choices for BS2 - get the temperture reading and send the info to the PC or get the pressure reading and send the info to the PC.

    Once the PC gets the info, it will play its' tunes based on the values it receives from the BS2. For example:

    if TemperatureValue < 50 then play Song1
    else
    if TemperatureValue = 50 then play Song2
    else
    if TemperatureValue > 50 then play Song3
    etc.

    So all of this depends on a knowing which tasks to assign to the PC & BS2, creating the appropriate program for each. What Phil Pilgrim is describing here...

    D xxxx Set the direction for each port pin.
    O xxxx Output to the port pins.
    I xxxx Input from the port pins and send the data back to the PC.

    ...is a basic communication protocol that he's suggesting between the PC and BS2. If I'm not mistaken, it's a format that he uses, so you'll have to ask him for samples of code in action. He did post a Perl application that had something similar, and the docs for that were fairly thorough. Again, he can give more info.

    The PBasic code that I wrote above is adapted from a simple robot simulator that I was working on, built with a HomeWork board. Anybody interested in seeing a snippet from the PC side can see it here:

    http://forums.parallax.com/showthread.php?p=663025
  • pwillardpwillard Posts: 321
    edited 2007-08-13 17:32
    Maybe build or have somebody build you one of these:

    http://www.parallax.com/dl/docs/cols/nv/vol6/col/nv125.pdf

    Might be close to what you want even though it's not a stamp emulator.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

    There's nothing like a new idea and a warm soldering iron.
  • cclaud2cclaud2 Posts: 21
    edited 2007-08-14 00:38
    Thanks guys. You all have been extremely helpful.
Sign In or Register to comment.