PDA

View Full Version : BS2SX and QBasic?



romshark
06-11-2005, 07:56 AM
Greetings.
I'm trying to get QBasic to send data to my Basic Stamp 2SX. I want to send numbers to the stamp, which it will then write to a Parallax Stampmem.
I have the program set up and it works within the Stamp Editor Debug window (I have it writing to an LCD for now to make sure the numbers are being read correctly.) However, I can't make it work with QBasic. Can anyone help me out?

here's what I have for the QBasic test side (most likely where my problem is)

FOR y = 1 TO 7
READ x
a$ = INPUT$(1)
PRINT x, ", ",
PRINT #1, CHR$(x)
NEXT y

DATA 20, 96, 21, 110, 22, 88, 23, 5, 185, 8, 131, 8, 141, 8

and this is my 2SX side (skipping declarations)

start:
DEBUGIN incoming
SEROUT LCDp,baud,[254,1]
SEROUT LCDp,baud,[DEC incoming]
GOTO start

Thanks for reading.

Jon Williams
06-11-2005, 08:06 AM
Is your QBASIC program transmitting at 9600 baud? The other thing that's happening is that you're not allowing any time for the BASIC Stamp to process the by it's just received before your QBASIC program sends another. If it seems to be working but is skipping values, then you may just need to add a delay in your QBASIC FOR-NEXT.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

romshark
06-11-2005, 08:18 AM
Forgot that part of my QBasic program. I mean I have it in my program, but didn't copy it into my post.
OPEN "com1:9600,n,8,1,cd0,cs0,ds0" FOR output AS #1

Com port 1, 9600 baud, no parity, 8 data bits, 1 stop bit, timeouts disabled.
I think that's right. I'm not to sure about stop bits, but the only other coices are 1.5 and 2

Right now, I do have some flow control in my test program. a$=input$(1), which pauses the program until I press a key.
In the final product, I plan to have the stamp write the number to the Stampmem, then send·the number back to the computer. Once my PC gets the number, it'll send out the next.

Chris Savage
06-11-2005, 09:49 AM
Hello,

·· Why do you have the line "a$ = INPUT$(1)" in your QBASIC program?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)

romshark
06-11-2005, 10:38 AM
It's something I learned in computer programming class years ago. The program waits for input at that line. Once I press any key (or nearly any key anyway), the program will continue on it's way. a$ is just a dummy variable that input$ writes to.
Here it's just temporary, so I can send numbers one at a time at my discretion. It'll be different in later versions.

Post Edited (romshark) : 6/11/2005 2:41:16 AM GMT

Chris Savage
06-11-2005, 11:18 AM
Okay,

·· I knew what it did, I just wondered why you put it there...It might be best to actually attach your code so we can verify everything.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)

romshark
06-11-2005, 08:44 PM
Okay, I attached the code for the PC and BS2SX. Everything works except they don't talk to each other (the programs don't crash or anything.)
The LCD is set up for a BPI-216 from Scott Edwards Electronics. That's also where I got the coding for talking with anything using the serial port (the paperwork for the LCD came with examples for controlling it using QBasic, and I've gotten that to work.) Talking with the stamp itself is proving more difficult.
I did find a page about communicating between the stamp and PC, but it didn't work either.
http://home.pacifier.com/~mcginty/qbstamp.htm
Yes, I did change the baudrates to 2SX as needed.

Hopefully we can figure this out.

Oh, and in the Qbasic program, I have tried sending the numbers both with and without the CHR$ .

Post Edited (romshark) : 6/11/2005 1:09:36 PM GMT

Bruce Bates
06-11-2005, 10:20 PM
romshark -

I suspect you want to read the serial input from the programming port, and not from the DEBUG terminal. Presuming that to be the case, you want to remove the DEBUGIN statement and replace it with a SERIN (with the appropriate parameters) from Pin Port 16 (the programming port).

Regards,

Bruce Bates

Jon Williams
06-11-2005, 10:54 PM
Per Bruce's suggestion, give the attached program a try, then modify it to send it's output to the LCD.· After you run this program, manually open a Debug terminal and select the comm port that your BASIC Stamp is attached to.· When you press a key on your keyboard, you'll see the ASCII value printed in the terminal window (note: I have my Debug Terminal window set to Echo Off).· After this is working, change the SEROUT line to accomodate your LCD.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

romshark
06-11-2005, 11:27 PM
I tried it, and it works in the debug terminal (including with the LCD), but I still can't get QBasic to talk to it.
Is the line I'm using in my QBasic program correct?

OPEN "com1:9600,n,8,1,cd0,cs0,ds0" FOR output AS #1

That's correct for the LCD, but does the stamp have different settings? Is one supposed to have something inverted? I think I read that PC communications are inverted.

Post Edited (romshark) : 6/11/2005 3:49:06 PM GMT

romshark
06-12-2005, 08:08 AM
Problem solved!
I tried hyperterminal, and it didn't work either. I then decided to try and use by 2SX with my carrier board (I've got one 2SX on my robot, the one I've been using, and another one on a carrier board.) The one on the carrier board worked perfectly. A quick search revealed that I need to add capacitors to my robot board. I've got the schematics for adding the capacitors from a forum search (posted by Jon·in another topic.)
Thanks anyway, and sorry for taking up your time for something so simple.

Edit: Yup, my robot can now read the data properly. Thanks again.

Post Edited (romshark) : 6/12/2005 12:43:40 AM GMT

Jon Williams
06-13-2005, 02:21 AM
Excellent news -- have fun!

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax