Shop OBEX P1 Docs P2 Docs Learn Events
Basic Stamp 1 or 2 & REALBasic? — Parallax Forums

Basic Stamp 1 or 2 & REALBasic?

martintelefontmartintelefont Posts: 9
edited 2008-03-31 19:00 in BASIC Stamp
Hi
I was wondering if anybody has any experience with making REALBasic talk to the Stamps? Anybody? I already asked at the REALBasic forum and got zip. So I thought I try the other end of the spectrum. I got a program running that looks like this:

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

val VAR Byte
val = 1

DO
DEBUGIN STR val \1


IF val = "1" THEN
  LOW 15
  PAUSE 200
  HIGH 15
  PAUSE 200
  LOW 15
  DEBUG "blinked"
ENDIF

IF val = "2" THEN
  DEBUG  "didn't blink"
ENDIF

LOOP




and this in REALBasic

  dim a as Integer = System.SerialPortCount
  
  Listbox1.DeleteAllRows
  for i as Integer = 0 to a-1
    Serial1.SerialPort=System.SerialPort(i)//= in my case "COM5"
    if serial1.open then serial1.Write("1") else MsgBox "The serial port could not be opened."
    Listbox1.AddRow system.SerialPort(i).Name+" done"
  next




anybody know why it won't blink?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-30 17:27
    Your REALBasic code doesn't show the Baud which is fixed for the DEBUG / DEBUGIN statements at 9600 for most of the Stamp models. Make sure the Baud is 9600. For the BS2px, it's 19200 Baud.
  • martintelefontmartintelefont Posts: 9
    edited 2008-03-30 17:34
    Mike,
    First of all you are quick, wow, 2 posts in 2 days and you are the first to respond to both, cudos.
    well I tried that with both 9600 and 19200 and still no blinking. Yes I checked the wiring and I do get blinking if I send the signal out of the stamp environement.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-30 19:04
    The only other thing I can think of is that the Stamp is very slow compared to the PC and, when the PC opens the serial port, the Stamp will normally be reset (toggling the DTR handshake line does this). The Stamp may not have enough time to reach the DEBUGIN statement before the PC sends the character. Try inserting a few milliseconds' delay before sending the "1" character.
  • martintelefontmartintelefont Posts: 9
    edited 2008-03-30 20:26
    Well I tried that just now, and nope that wasn't it.
  • terry_bearterry_bear Posts: 84
    edited 2008-03-30 23:24
    martintelefont,

    Did you load the Stamp program with the Parallax IDE? if you did so without error, can you enter a "1" manually in the upper pane? If so, the problem lies somewhere within the PC (port parameters, REALBasic code, COM port number, etc.) If not, then the issue is probably external to the PC (Stamp code, cable, USB-serial adapter, etc.)

    Just my two cents,

    Terry
  • martintelefontmartintelefont Posts: 9
    edited 2008-03-31 04:59
    my thoughts exactly.
    I ran the whole thing out of the parallax program and 1 in the debugger window will make the LED flash and give me back the text and everything. And I know the RB code works up to the point where it opens the port. I just have no idea where the message gets lost after that.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-31 06:00
    Another PC timing thing ... serial I/O on the PC is buffered at several levels and you don't show any checking that the transmission has actually taken place before you acknowledge it with a "done" message. Closing the serial port should force it out, but there may be other ways as well. Closing the serial port may reset the Stamp again too.
  • terry_bearterry_bear Posts: 84
    edited 2008-03-31 14:15
    It definitely looks as if you need to concentrate on the PC side. As Mike says, the "done" message could easily happened before the port is, in fact, released. As for the Stamp being reset when the port is closed, yes, it can happen, so hit the manual reset on the board just before starting the REALBasic program...

    I know that this can be done in Linux, but it is much harder to access (or it is for me, anyway) to do so in Windows...

    Have fun,

    Terry
  • martintelefontmartintelefont Posts: 9
    edited 2008-03-31 15:46
    Thanks, that's what I was afraid off. I posted another post in the REALBasic forum, but unless they got a magical bullet hidden somewhere I guess that's it for REALBasic and Basic Stamp I/II.

    On another front. I found an article by Chris McAvoy "how I Feed my cats with linux". Well I tried to install the PySerial that he uses to talk to the Stamp and well I am not getting anywhere. Is it a Win problem or a the piece is some 4 years old problem?
    Here is the error:

    Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [noparse][[/noparse]MSC v.1310 32 bit (Intel)] on win32
    Type "copyright", "credits" or "license()" for more information.

    ****************************************************************
    Personal firewall software may warn about the connection IDLE
    makes to its subprocess using this computer's internal loopback
    interface. This connection is not visible on any external
    interface and no data is sent to or received from the Internet.
    ****************************************************************

    IDLE 1.2.1
    >>> import serial

    Traceback (most recent call last):
    File "<pyshell#0>", line 1, in <module>
    import serial
    File "C:\Python25\lib\site-packages\serial\__init__.py", line 13, in <module>
    from serialwin32 import *
    File "C:\Python25\lib\site-packages\serial\serialwin32.py", line 9, in <module>
    import win32file # The base COM port and file IO functions.
    ImportError: No module named win32file
    >>> sp = serial.Serial(0)

    Traceback (most recent call last):
    File "<pyshell#1>", line 1, in <module>
    sp = serial.Serial(0)
    NameError: name 'serial' is not defined
  • terry_bearterry_bear Posts: 84
    edited 2008-03-31 16:34
    Martintelefont,

    Sorry, I have NO experience with Python. I can tell you that Microsoft tends to put its own tweaks on other languages, and then tries to call them "standard". At one time it used to be quite to use the serial ports in Liberty Basic, but I don't know if Liberty will even load under WinXP... The last time that I tried to do anything with serial ports on Windows, I discovered that I had to run Hyperterm first, and set the port parameters that way. No matter what I did in Perl, C, or C++, some lower level driver or wrapper wouldn't recognize the parameters, except by way of Hyperterm.

    Now, that's a thought; go into Hyperterm, set the port parameters, (send your "1" just for grins), close Hyperterm and try your REALBasic program. It's not good, it's not acceptable, but it would tell you where the trouble lies...

    Regards,

    Terry
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-31 16:39
    There are all sorts of PC programs that can communicate with a Stamp including the Stamp Editor and Stamp Plot (w.selmaware.com). There have been any number of projects posted using a PC as a robot controller with a Stamp doing the low level sensor and motor control. Unfortunately, every Windows programming system (REALBasic / Python / Visual Basic / ...) does serial I/O a little differently and the details can often make the difference between success and failure. The fact that your Stamp program works properly when you use the Stamp Editor's debug window says that the problem is not on the Stamp end of things.
  • martintelefontmartintelefont Posts: 9
    edited 2008-03-31 18:36
    I just had an odd thought could it be that the coding for "1" isn't the same in both programs? I mean something at the bit level or is PBASIC using just plain old ASCII?
  • terry_bearterry_bear Posts: 84
    edited 2008-03-31 19:00
    A good thought, but it looks to me as if REALBasic is sending an ASCII "1". Does the Stamp respond to a "1" when entered into the upper DEBUG window?

    Terry
Sign In or Register to comment.