Shop OBEX P1 Docs P2 Docs Learn Events
bs2 serial comm. specs needed — Parallax Forums

bs2 serial comm. specs needed

Unit042Unit042 Posts: 21
edited 2009-03-15 21:26 in BASIC Stamp
I have a Basic Stamp 2 Homework Board as part of the·what's a microcontroller kit, and I've gotten the idea that I could click something on the computer screen, and have something in real life move(idea simplified for ease of communication brevity's sake).

It's a very nice microcontroller, but my manual (to my knowledge,·the forum also)·does not cover what I am trying to find out: what the specs for the serial communication of the bs2 are·and what commands will accomplish it.

Will debug and debugin work? If they produce standard serial communication, does it have a "stop bit", what baud is it, etc.?

The links as to what I'm doing, see:

http://www.communitymx.com/content/article.cfm?page=2&cid=8658A

http://www.instructables.com/id/Control-real-world-devices-with-your-PC/
(more links·can be given, for example, the perl tutorial I'm reading to be able to·use the serial port program·at the first link)


Generally, instead of visual basic interfacing with a picaxe, I want perl (on the computer)·interfacing to bs2.

I could use my picaxe (visual basic failed to install on my yucky vista OS), but I was hoping that the bs2 would use it's programming port or other easy pin interface for standard serial communication so that I would not have to change wiring so much (program mode Vs. serial operation mode).

If this has been talked about already, please point me toward it,burger.gif as I have already tried searching this forum.

Any suggestions? If anyone wants, I can give much,· much more detail as to what I'm attempting.
«1

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-10-27 03:33
    Read the chapters in the Basic Stamp Manual on the SERIN and SEROUT statements. These do the serial communications for the Stamp. You should also read the chapters on the DEBUGIN and DEBUG statements. These are special cases, simpler than SERIN and SEROUT, that work only on the comm port used for programming. They also are intended to work with the Stamp Editor's debug window, but can be used for other communications through the programming/debug port.

    Please use black text. The color you chose is very hard to read. It's a nice color, but not for significant amounts of text.
  • Unit042Unit042 Posts: 21
    edited 2008-10-29 15:03
    Sorry about the color. I usually do red text on cyan background. Easy to read and looks nice!

    From what I gather...

    DEBUG and DEBUGIN send/receive serial data (through the programming port) to the programmer terminal, but this data is not standard serial comm that can be used by another program on the computer.

    SERIN and SEROUT are piaxe commands that send/receive serial data through user specified pins.

    I could not find where my "What's a Microcontroller?" book mentioned SERIN or SEROUT. The Index and Table of Contents fail me.
    I hate to be a burden, but as you seem to know what you're talking about, could you point me to an online "dictionary" of PBASIC commands? I have the awfullest time navigating this site, what with all the huge banners trumpeting the Propeller et cetera.
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-10-29 15:10
    The "Dictionary" is in the 'Help' file you can reach from the IDE.

    SERIN and SEROUT can target "16" (as in " SEROUT 16, [noparse][[/noparse]"Hi", CR] ") which will send stuff out the programming port using the built-in RS-232 level shifting transistors on the BS2.

    I understand this isn't obvious from the documentation.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-10-29 15:14
    You want the "Basic Stamp Syntax and Reference Manual" which you can download from here: www.parallax.com/tabid/440/Default.aspx

    There are chapters on each of the statements like SERIN and SEROUT.

    DEBUG and DEBUGIN do handle standard serial comm, but they are specific for the programming port and the Baud used by the Stamp Editor for its debug window. They have special syntax to show the names of variables in addition to the usual "formatters" provided by SEROUT and SERIN.
  • Unit042Unit042 Posts: 21
    edited 2008-10-29 15:37
    That was a quick reply!

    I'm downloading it (software guide or another for PBASIC version 1, 2, 2.5) now.

    While I wait (dialup), you say that DEBUG is essentially just an easy, canned function that's essentially a serial output string that can allow the computer program to get the variable name too? Not sure what you meant by formatters, but I guess it's what determines the baud rate and other stuff.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-10-29 15:42
    Read the manual. It will answer your questions.
  • Unit042Unit042 Posts: 21
    edited 2008-10-29 15:46
    I wish I could---It's still downloading! Wish I had something faster.
  • Unit042Unit042 Posts: 21
    edited 2008-10-29 16:13
    I got it! 14 day money back garantee, errata, disclaimer... skip-skip-skip...

    (I just figured out what the formatting means: text shifting around by use of CR, CLS, and whatever the newline command was.)

    ...aha! Page 169:

    On all the BS2 models, DEBUG is actually a special case of the SEROUT
    instruction. It is set for inverted (RS-232-compatible) serial output through
    the programming connector (the SOUT pin) at 9600 baud, no parity, 8 data
    bits, and 1 stop bit. For example,
    DEBUG "Hello"
    is exactly like:
    ' {$STAMP BS2}
    SEROUT 16, $4054, [noparse][[/noparse]"Hello"]

    //What's with the $4054? I guess I'll have to read on.

    Page 172 has more info on the debugin.

    Thank you muchly for your help, I will have to do a bunch of reading as to how I'll get the computer to coperate with the BS2. I could use SEROUT to give just the facts, and DEBUGIN to receive a string of numbers/characters....

    Now the information digesting begins!
  • Unit042Unit042 Posts: 21
    edited 2008-10-29 16:21
    OOOOoooooooh! DTMFOUT looks cool!
    I'm just going to have this printed up so I can read it easier.
  • JDJD Posts: 570
    edited 2008-10-29 16:21
    DN,

    $4054 is the baud setting in HEX ( 16468 in decimal ). There is a baud mode table in the Basic Stamp Syntax & Reference Manual on page 419; you can reference to get the actual speed so you can set up any other application.

    Hope this helps

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Joshua Donelson

    www.parallax.com
  • Unit042Unit042 Posts: 21
    edited 2008-10-29 16:31
    Yes, it helps immensely. DN? Wait a minute... I thought that it was my username that was shown and not the display na.... Ohhh, the display name is what's shown, not username.

    I'll have to go change it.
  • Unit042Unit042 Posts: 21
    edited 2008-10-29 16:41
    There, much better! Hey, my avatar is moving, unlike on other forums....
    (If it's too bloody, I have a few alternate ones I can switch to)

    EDIT: I've also looked at the IDE's dictionary. Thanks for the tip!burger.gifcool.gif

    Post Edited (Unit042) : 10/29/2008 4:46:57 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2008-10-29 16:51
    Please stick with a static avatar. It's very distracting.
  • Unit042Unit042 Posts: 21
    edited 2008-10-29 17:02
    Sorry. I'll change it to my static one.sad.gif
  • Unit042Unit042 Posts: 21
    edited 2008-10-30 02:58
    The IDE manual's entry on serin mentions serial pins used for serial communications. My Homework board (containing BS2) has an inbuilt serial plug(for programming and DEBUG-ing). What pins do I specify for serial port communication?
    Now, lemme see... will the following work?

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    ' {$PORT COM4}

    'pin 0 has an LED on it. Computer sends a 0 or 1 @9600 baud·to set LED state.
    'myvar VAR Byte 'Variable used for storing serial data
    DO

    · redo:

    ··SERIN 16, 84, [noparse][[/noparse]DEC myvar]

    ··· IF myvar = 0 THEN
    ··· LOW 0
    ··· ENDIF

    ··· IF·myvar = 1 THEN
    ··· HIGH·0
    ··· ENDIF

    LOOP


    darn coloring is giving me trouble....


    EDIT: I hooked my BS2 and it didn't work. I don't know if it was my computer's software, the BS2, or what. So many links in the chain that could be wrong. Maybe if I had a program that is already proven to work with the serial port....
    Then, once the BS2 is running, then I can switch to the computer.

    Suggestions?

    Post Edited (Unit042) : 10/30/2008 3:48:24 AM GMT
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-10-30 12:46
    Well, it WILL work, but the program will 'hang' almost indefinitely in the "SERIN" statement, until you give it a good decimal "number-string" followed by a CR (also known as CHR(10)).

    Personally, when testing RS-232 links, I tend to use:

    MAIN:
    SEROUT 16, 16864, [noparse][[/noparse]"Hi", CR]
    PAUSE 1000
    GOTO MAIN

    This has several benefits. First, it's really short, so hard to get wrong. I used to leave out the "PAUSE", but then "Hi" goes screaming down the screen. Next, it doesn't depend on ANYTHING going right on the PC, it just keeps putting out "Hi" once a second. This gives you LOTS of time on the PC to figure things out. And it will work with a "terminal" on the PC, so you can debug the hardware interface using known-good PC software.

    Oh, I assume you're using the BOE board -- it properly 'decouples' the DTR/ATN/RESET signal so the BS2 can run.

    I'm not sure about the "Homework" board -- you may have to set DTREnable = FALSE for it to work there.
  • Unit042Unit042 Posts: 21
    edited 2008-10-30 17:21
    Good advice. I'm currently doing this for fun in bewtween meetings of my team. Busy doing:

    bestinc.org

    also, I just now finished posting this:

    http://tech.groups.yahoo.com/group/bestinc/message/376

    I'm conqueor042.

    Anyway, that serial send every second is genius!
    NO, I don't have a BOE, wish I did, though.

    DTREnable... lemme check the IDE help file...
    Not there!
    I'll check the software guide pdf...
    using adobe's pdf text searching feature, it's not there!

    Sorry about the dumb question, but:
    What is DTREnable, and is it compatible with BS2?
  • Mike GreenMike Green Posts: 23,101
    edited 2008-10-30 17:29
    All Stamps use DTR to trigger a reset so that the Stamp Editor can download a new program. If the PC doesn't have DTR enabled, it can't toggle the DTR line to cause this reset. If you're using the programming port for data, you may want to disable DTR so that whatever program you're using for the data doesn't accidentally reset the Stamp when you don't want it to.
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-10-31 19:28
    Mike has it right -- the "DTREnable" is a "property" of the MSComm control under VB6. Pretty obscure, right? Sorry about that.

    Basically, any program you run on the PC side (Hyperterm, a Java program, a C++ program) will need to 'disable' the DTR signal so the BS2 program can run. On the BOE, there's a couple of capacitors on this signal, so holding it 'high' from the PC side will just generate one reset and let the program continue. Every time you close and reopen the port from the PC side, it'll reset the BS2, though.
  • Unit042Unit042 Posts: 21
    edited 2008-11-03 01:39
    So, the DTR is something that the BS2·(not PC)·does to receive programs, but this hinders communication as it resets the BS. Disabling will allow serial data·receiving.

    Do I need to worry about re-enabling DTR or else the BS2 won't receive new programs?
  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-03 05:21
    Comm ports have to be opened on the PC side and DTRenable is provided to Windows at that time by your VB program as a property of the MSComm control. The Stamp Editor also opens a comm port to identify or program a Stamp and enables DTR for that comm port while it's in use.
  • Unit042Unit042 Posts: 21
    edited 2008-11-04 15:47
    My head!
    Sorry to be rude, but COM ports try my patience: do I have to worry about DTREnable yes/no?

    cin.get(DTREnable);
    If(DTREnable_worry == yes){
    How-do-I-make-it-a-nonissue?(); //SOS! I'm dreaming in code!
    Mental_state = insane;
    }else{
    Mental_state = yay * woohoo("Happy days!" /n);
    }
  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-04 17:33
    I wouldn't say "worry". The Stamp Editor will take care of itself and whatever com ports it uses. Your program should disable DTREnable IF you don't want to bother with the Stamp resetting when your program opens (or closes) the com port.
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-11-04 18:43
    1. Simple answer: NO, you don't have to worry about DTREnable

    2. More complicated answer: What are you using on the PC side to open the serial port?
  • Unit042Unit042 Posts: 21
    edited 2008-11-09 18:03
    The first link I posted, in the first post of this thread. It has the stuff I'm trying to do. When I try to run the PHP, I get an error saying something about not being able to open the com port that the BS2 is on (COM4). I'll have to work on it, but right now, I'll take a slight detour, and build a robot that uses 12v windshield wiper motors (cheap and easy to get), a 12v batt. , and some homebrew electronics for a 10 to 30 pound radio control robot. It's time I had a (relatively)big, cheap robotic platform to work with. I could experiment with robotic applications including a vacuum attachment, and maybe even lawn mowing. Or how about a seek-and-"destroy" paintball robot that has military uses?

    Don't worry, I'll try to get it under computer control, but first, the mechanical base/RC system!

    btw, my team's robot got 4th place in Music City BEST. Darn good considering we were against an army of noob's and three (huge) magnet schools with infinite rescources, and my team was just a small (15 people) homeschool group. We can do better than other fair players, but the daddy-bots (that daddy built for the kids) always stayed two (short) steps ahead of us.

    No regionals for us, but we learned quite a bit, and made friends. That counts, right?
  • Unit042Unit042 Posts: 21
    edited 2008-11-11 00:52
    Hey! I just found:
    http://www.aaroncake.net/circuits/crombuld.asp

    You guys think it's workable? BS2 out/inputting to the parallel port?
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-11-11 14:53
    I think it's much easier to use the PC serial port to talk to a BOE board with a BS2 on it useing SERIN/SEROUT, then use the BS2 16 I/O pins as a parallel port. Finding PC parallel ports these days is getting difficult. While USB to Serial adapters are about $20.
  • Unit042Unit042 Posts: 21
    edited 2008-11-12 20:25
    Well, I have two computers:

    The "big" one is a new one running vista(uncapitalised on purpose) with all USB. I've used it (and a USB to serial converter) to program my BS2 and a Picaxe or two, so I know that my serial converter is fully compatible.



    The "small" computer runs 95 (or was it 98?), has 2 USB, one serial, two PS2(keyboard and mouse are using those), and one parallel port.



    I figure that I could do the parallel port because it seems easier, then I move on to serial; that way, I'd be putting that unused port to good use. I dream of making my own laser printer. Not ones that use toner, but use the laser to burn the paper. First I'll do ascii text, then move on to maybe pictures. Why? Ink is more expensive than the printer itself, and not being able to print even simple text is quite a handicap, as my family of 5 must be at the one computer if they wish to view/edit text documents while doing internet research papers and whatnot etc. etc. I'm ranting so I'll take a break for my finger's sake.
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-11-12 20:31
    You can buy a very good printer these days for $100. One of my rules for myself is not to invest thousands of dollars to do what other people have already done, and the other people are selling stuff TODAY for less than I could possibly make it.

    Just a thought. Don't let me discourage you too much.
  • Unit042Unit042 Posts: 21
    edited 2008-11-12 20:47
    You mean, laser burning printers that work on normal 8 & 1/2" x 11" paper?
    Where?---I want one!
Sign In or Register to comment.