November 22, 2024, 12:48:26 AM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Hyperterminal serial output and Prop 1 or 2

Started by imagineerdan, March 14, 2008, 07:48:37 PM

Previous topic - Next topic

imagineerdan

I am working on a project where I need to send simple hyper terminal ASCII commands to control an led chaser unit. How would I send these commands through a BS1 or BS2

I would like the basic stamp to basically send serial out commands to this led unit. Also how would I wire it etc.

I do need the stamp to do this because this is a LED device is going to be in a vehicle, so I really am trying to have the stamp send hypertermial ascii commands to the led chaser board which accepts hyperterminal ascii commands via serial to make its leds run. It is possible to send hyperterminal commands in ascii from the basic stampl serial out and how would I go about doing it?

JonnyMac

March 14, 2008, 09:52:00 PM #1 Last Edit: March 14, 2008, 09:54:05 PM by JonnyMac
The Prop-1 really isn't good for this because it has no ability to do a serial timeout -- if you don't send a command the Prop-1 will sit on the SERIN forever; no moving lights.

The Prop-2 does have a timeout on serial input, but it's not ideal.  You need to use the timeout as part of your cycle timing, which means you have to make it long enough to be able to detect a key while it's sitting on the SERIN.

The Prop-SX is best, but is probably not within reach programming wise (not yet, anyway).  With the Prop-SX one can do background serial communications while the foreground is running the show -- but this is advanced stuff (see my programs in the VSA library for examples of receiving serial in the background while the foreground does other things.

Here's a VERY simple demo with the Prop-2 using just eight LEDs on P0..P7.  Again, not ideal, but may work for your application.  The timing of the moving lights is handled by the timeout factor in the SERIN -- there are no other delays.  Again, keep in mind that you may not capture every key press, if you press a key just as the SERIN timeout expires you won't have a chance until it runs the preset step.

You can try this without opening HyperTerminal (though that works, too).  Once you've downloaded the program to your Prop-2, open a terminal window within the editor and set it to 9600 baud.  Press "0" - "3" to see it work, any other key has no effect.

' =========================================================================
'
'   File...... Simple_Lights.BS2
'   Purpose...
'   Author.... Jon Williams, EFX-TEK (www.efx-tek.com)
'   E-mail.... jwilliams@efx-tek.com
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              see: http://creativecommons.org/licenses/by/3.0/us/
'   Started...
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

Lights          VAR     OUTL                    ' on P0..P7


' -----[ Constants ]-------------------------------------------------------

Speed           CON     100


' -----[ Variables ]-------------------------------------------------------

cmd             VAR     Byte                    ' command from PC
show            VAR     Byte                    ' show to play
showLen         VAR     Byte                    ' length of show
offset          VAR     Byte                    ' offset into data


' -----[ Initialization ]--------------------------------------------------

Reset:
  Lights = %00000000                            ' all off
  DIRL = %11111111                              ' make pins ouputs

  show = 0
  showLen = 0


' -----[ Program Code ]----------------------------------------------------

Main:
  '
  ' receive command at 9600 baud on programming port (pin 16)
  '
  SERIN 16, $4054, Speed, No_Cmd, [cmd]         ' SERIN on programming port

  LOOKDOWN cmd, ["0123"], cmd                   ' convert if valid
  IF (cmd < 4) THEN                             ' if in range update show
    show = cmd
    LOOKUP show, [0, 8, 5, 5], showLen          ' set length
    offset = 0                                  ' reset data offset
  ENDIF

No_Cmd:
  BRANCH show, [Reset, Play_Show1, Play_Show2, Play_Show3]
  GOTO Reset

Play_Show1:
  READ Show_1 + offset, Lights
  offset = offset + 1 // showLen
  GOTO Main

Play_Show2:
  READ Show_2 + offset, Lights
  offset = offset + 1 // showLen
  GOTO Main

Play_Show3:
  READ Show_3 + offset, Lights
  offset = offset + 1 // showLen
  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------

Show_1          DATA    %00000001, %00000010, %00000100, %00001000
                DATA    %00010000, %00100000, %01000000, %10000000

Show_2          DATA    %00000000, %00011000, %00100100, %01000010
                DATA    %10000001

Show_3          DATA    %00000000, %10000001, %11000011, %11100111
                DATA    %11111111






Jon McPhalen
EFX-TEK Hollywood Office

imagineerdan

Is there a way to send serial ascii out with the prop 2? like words. The unit im using takes ascii commands from serial of "fire" or "delaytime" simple text words. Can I trigger the prop2 which then in turn sends one of these commands to the running light LED unit ?

JonnyMac

Sure.  If you give me more specifics I can whip up a demo program.  As an example, you could have something like this:

  IF Trigger = IsOn THE
    SEROUT Sio, Baud, ["fire"]
    PAUSE 10
  ENDIF


I'm sorry I misunderstood your original question.  As I suggested elsewhere in the forums, giving me more details than you think are necessary is always helpful -- especially when I have a billion things going on the night before I drive to Las Vegas....  I thought you wanted to recieve a simple command and then do a chase on your prop controller.  What is the baud rate of your LED device?  If it will operate at 2400 then the Prop-1 becomes a control candidate.
Jon McPhalen
EFX-TEK Hollywood Office

imagineerdan

March 15, 2008, 01:37:06 PM #4 Last Edit: March 18, 2008, 06:28:48 PM by imagineerdan
No problem Jon, thanks for helping in the first place! I believe the device operates at 9600 baud, I will have to check, does the bs2 handle that speed?

I would like the program to send out a "fire 1" ascii serial command through pin1 if it gets triggered once, then if it gets triggered again to send a "fire 0" ascii serial command. I think that will get me started. Thanks again and hope the convention goes well and is a blast! :)

JonnyMac

The Prop-2 can handle 9600 baud with ease.  You could toggle a bit variable to control what gets fired.  Let's say you define something called fireState like this:

fireState       VAR     Bit

On detecting an input you could send the correct fire state like this:

  SEROUT Sio, Baud, ["fire ", BIN1 fireState]
  fireState = 1 - fireState


The BIN1 modifier will convert the bit value (0 or 1) to its text representation ("0" or "1").  The second line toggles the value from 0 to 1, or 1 to 0.
Jon McPhalen
EFX-TEK Hollywood Office

imagineerdan

Thanks Jon that help, how would I hook a serial port out to this arrangment, and what would an example code be if pin 1 is closed then serial out asii "fire", if pin 0 is closed then serial out ascii "backward"

JonnyMac

Here you go.  You may be surprised to see DEBUG instead of SEROUT.  Well, DEBUG is a special form of SEROUT that uses 9600 baud and sends the data out of the programming port instead of one of the normal I/O pins.

' =========================================================================
'
'   File...... Ascii_Shooter.BS2
'   Purpose...
'   Author.... Jon Williams, EFX-TEK (www.efx-tek.com)
'   E-mail.... jwilliams@efx-tek.com
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              see: http://creativecommons.org/licenses/by/3.0/us/
'   Started...
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

PgmPort         CON     16                      ' for serial output


' -----[ Constants ]-------------------------------------------------------

T1200           CON     813
T2400           CON     396
T4800           CON     188
T9600           CON     84
T19K2           CON     32
T38K4           CON     6

SevenBit        CON     $2000
Inverted        CON     $4000
Open            CON     $8000

Baud            CON     T9600


' -----[ Variables ]-------------------------------------------------------

fireState       VAR     Bit
btns            VAR     Byte
idx             VAR     Byte


' -----[ Initialization ]--------------------------------------------------

Reset:
  fireState = 1                                 ' start with "fire 1"


' -----[ Program Code ]----------------------------------------------------

Main:
  GOSUB Scan_Buttons

  IF (btns = %10) THEN
    DEBUG "fire ", BIN1 fireState
    fireState = 1 - fireState
  ENDIF

  IF (btns = %01) THEN
    DEBUG "backward"
  ENDIF

  PAUSE 150
  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

' scans/debounces buttson on P0 and P1

Scan_Buttons:
  btns = %0011                                  ' activate P0 an P1
  FOR idx = 1 TO 5
    btns = btns & INA
    PAUSE 10
  NEXT
  RETURN


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------

Jon McPhalen
EFX-TEK Hollywood Office

imagineerdan

Since the sirout data is sent back out the programming port I assum I download the BS2 program from the computer, disconnect the serial cable, then hook up my LED device to the BS2 serial programing port?

I was noticing in the DEBUG window that whatever I was placing in the " " sending ascii though the serial would get a 0 or a 1 behind it. Is there a way to send just whats in the " " as ascii serial out.

Also is there an equivlent of ENTER button in serial out or ascii language? Thanks!

JonnyMac

Once the Prop-2 is programmed it can be disconnected from your PC and connected to the device you want to control. 

You can send any bit of text using DEBUG -- just put it in quotes:

  DEBUG "EFX-TEK rocks!"

In the demo code the only time you should get the zero or one is for the fire toggle -- isn't this what you asked for?  A carriage return in ASCII 13, and there's a pre-defined constant, CR:

  DEBUG "For props that rock", CR, "get EFX-TEK"

If you run the line above you'll see that it actually prints two lines in the DEBUG window; the CR in the middle inserts the carriage return.

Jon McPhalen
EFX-TEK Hollywood Office

imagineerdan

Alrighty, they was it Jon the CR command, thanks soo much ! Works like a champ

JonnyMac

Just to be clear, CR is a pre-defined constant (a value that doesn't change), it has a value of 13.
Jon McPhalen
EFX-TEK Hollywood Office