Shop OBEX P1 Docs P2 Docs Learn Events
How would I send commands/programs to BS2 from other programming languages like C/C++ — Parallax Forums

How would I send commands/programs to BS2 from other programming languages like C/C++

naspippernaspipper Posts: 3
edited 2011-06-29 18:45 in BASIC Stamp
Hello everyone,
I'm developing a system that needs to be able to communicate a robot wirelessly. I'm going to use the XBee BS2 flashfly kit. I'm wondering if there is a way to send commands/programs to the BS2 autonomously without me typing the program on the BS2 editor, because I'll be using C/C++ or Matlab for programming. Is there a way to do this directly from this programming languages?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-06-27 11:57
    The BS2 compiler/downloader is available as a DLL that could be called from a C/C++ program. See Basic Stamp Tokenizer at the bottom of this page. This is not something for beginners and you're mostly on your own, but the Tokenizer does come with information on calling it from other programs. The Tokenizer documentation also comes with a description of the program downloading protocol, so you could write your own downloader.

    Usually, a Stamp might be controlled by a PC program, but not necessarily reprogrammed by it. The PC program opens a standard serial port and communicates with the Stamp program via SERIN and SEROUT statements using some protocol that you specify. Look at the Propeller Servo Controller for one example of how this is done (in this case with the Stamp controlling another device ... the Servo Controller).
  • naspippernaspipper Posts: 3
    edited 2011-06-27 12:43
    Thanks Mike for your reply, I'll try as you suggested!
  • naspippernaspipper Posts: 3
    edited 2011-06-29 08:56
    Hello Mike and everybody,
    I have gone through the tokenizer documentation, and it sounds confusing and too complex for a beginner like me. I was wondering if there are specific examples of using the tokenizer with C.
    May be the other alternative, using SERIN and SEROUT, would be easier for me.
    *I think my problem is easier than I make it seem, or I might easily get help if I explain it better.
    Here it is:
    I'm using a program (will most likely be in C) that will need to periodically download new program to the robot's BS2 controlling a robot.I have attached an exact sample of the program (written in Basic Stamp Editor), throughout the process only parts/variables of this code will be altered, the variables below

    a(0) = %0000011010010110 ^ %0000110011001100
    a(1) = %0000010000010100 ^ %0000110011001100
    a(2) = %0000100101101001 ^ %0000110011001100
    a(3) = %0000000101000001 ^ %0000110011001100

    r(0) = 15
    r(1) = 14
    r(2) = 15
    r(3) = 14

    and then the modified program will be downloaded again to the BS2 and see how the changes do on the robot.
    Hoping that I made this clearer, how would I go about doing this via SERIN and SEROUT or tokenizer in C?
  • Mike GMike G Posts: 2,702
    edited 2011-06-29 18:25
    On the STAMP side, replace the "Pause 20" command the the second for...next loop with a SERIN listener. The listener waits for about 20ms for an attention character. If the command times out waiting then continue on with the for...next loop. Otherwise, send an "I'm ready" character (SEROUT) back to the PC and start listening for the 12 bytes needed to fill your variables. Process the bytes and go back to the looping business.

    On the PC side, send the attention character and listen until the "I'm ready" character is returned from the STAMP. Then send your 12 bytes of data, log it, and exit.

    The STAMP can only do one thing at a time; listen or execute the loop.

    See the STAMP manual for more information and examples using the SERIN and SEROUT commands.
  • $WMc%$WMc% Posts: 1,884
    edited 2011-06-29 18:45
    You need to use PIN 16 for the programing.
    '
    Take a look in the Basic Stamp Manuel on how to do this. ( PIN 16 )-(SERIN)-(SEROUT)-(WRITE)-(READ)
    '
    Its pretty simple once you see how it works.
    '
    Pin 16 is the programming pin and also the DEBUG serial link back to the PC.
    '
    Basic Stamp Manuel (link below ) The download is free))

    http://www.parallax.com/Store/Books/BASICStamp/tabid/168/CategoryID/42/List/0/SortField/0/Level/a/ProductID/143/Default.aspx
Sign In or Register to comment.