October 31, 2024, 10:32:13 PM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


Help with Prop2 / Basic Stamp 2 serial stream from vixen

Started by viper911h, December 22, 2009, 11:34:23 AM

Previous topic - Next topic

viper911h

I have 5 prop 2s and a BS2 controlling about 100 channels and have had short looping sequences in the past, and now have exceeded the memory for storing the shows on the boards memory. I have been researching feeding the control stream directly from Vixen, but have hit some roadblocks with the pbasic code.

I have tried both the generic / Jon Williamson light controller driver.

I am using output pins on the BS2 to trigger events on the Prop2s... and the Props are working great, now its just getting the feed into the BS2 and all of its 16 lines.

I need some sample code to show what  I have to run on the Bstamp to receive the serial feed.

I have read some old posts but they were all based around serial streams to a Prop2 controlling 8 servos and I have not been able to convert into a 16 line dig io program.


I was thinking something like.......... 
DO

SERIN 16, 9600, [sdata1,sdata2]
IF sdata1 = 255 THEN

OUT0 = sdata1.BIT0
OUT1 = sdata1.BIT1
OUT2 = sdata1.BIT2
OUT3 = sdata1.BIT3
OUT4 = sdata1.BIT4
OUT5 = sdata1.BIT5
OUT6 = sdata1.BIT6
OUT7 = sdata1.BIT7

OUT8 = sdata2.BIT0
OUT9 = sdata2.BIT1
OUT10 = sdata2.BIT2
OUT11 = sdata2.BIT3
OUT12 = sdata2.BIT4
OUT13 = sdata2.BIT5
OUT14 = sdata2.BIT6
OUT15 = sdata2.BIT7

ENDIF

LOOP


- Thanks for the amazing support all the time.


JonnyMac

Okay, so what you're wanting to do is have Vixen control your 16 channels on the BS2 and have those channel outputs act as triggers to your Prop-2s?  No problem, I have a friend at Disneyland who has done similar things using a Prop-SX as a DMX receiver to trigger mini shows on connected Prop-1s and Prop-2s.

Here's the code that you'll load into your BS2 that acts as the Vixen interface:

' =========================================================================
'
'   File...... Vixen_Input.BS2
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              (remove my name if you modify and repost)
'   E-mail....
'   Started... 22 DEC 2009
'   Updated... 22 DEC 2009
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Receives channel control data from Vixen using the Generic serial driver.
' The driver should be set as follows:
'
' Baud..... 2400
' Header... (checked) EFX
' Footer... (not checked)
'
' Ensure that the Vixen project has 16 channels defined, even if some are
' not used as this program expects to receive 16 bytes after the "EFX"
' header.  If a channel value is 0-127 the output will be off, if it is
' 128-255 the output will be on.
'
' Vixen event timing should be set to 200ms or higher.


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


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

RX              CON     16                      ' for programming port


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

IsOn            CON     1                       ' for active-high in/out
IsOff           CON     0

Yes             CON     1
No              CON     0

#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T1200       CON     813
    T2400       CON     396
    T4800       CON     188
    T9600       CON     84
    T19K2       CON     32
    T38K4       CON     6
  #CASE BS2SX, BS2P
    T1200       CON     2063
    T2400       CON     1021
    T4800       CON     500
    T9600       CON     240
    T19K2       CON     110
    T38K4       CON     45
  #CASE BS2PX
    T1200       CON     3313
    T2400       CON     1646
    T4800       CON     813
    T9600       CON     396
    T19K2       CON     188
    T38K4       CON     84
#ENDSELECT

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

Baud            CON     T2400                   ' do not speed up!


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

buffer          VAR     Byte(16)                ' channels buffer

idx             VAR     Byte                    ' channel pointer
level           VAR     Byte                    ' channel level


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

Reset:
  OUTH = %00000000 : OUTL = %00000000           ' clear all
  DIRH = %11111111 : DIRL = %11111111           ' set outputs


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

Main:
  SERIN RX, Baud, [WAIT("EFX"), STR buffer\16]  ' wait for stream

  FOR idx = 0 TO 15                             ' parse channels
    level = buffer(idx)                         ' get channel level
    OUTS.LOWBIT(idx) = level.BIT7               ' set output to channel BIT7
  NEXT

  GOTO Main


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


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


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


Note that the program runs at 2400 baud -- do not change this.  I know this seems slow, but it's required; the internal mechanics of the BS2 receiving and buffering a big slug of data (19 bytes) means that time between bytes is required, at 2400 baud there is enough time to do the work.   I'm using a little advanced programming trickery here, you should study it and learn from it. 

The code works by waiting for a three-character header ("EFX") and then collecting the next 16 (channel) bytes into a buffer.  It then loops through them, copying the highest bit (BIT7) of each byte in the buffer to the corresponding output pin.  Again, this uses the generic output driver which just sends the raw channel data -- this is why it takes so many bytes to send the channels and why we just pick off the highest bit (BIT7, which is the 50% point).

Final note: make sure your Vixen event timing is 200ms or longer; this gives the BS2 enough time to set the outputs and then get ready for the next packet.

I tested this with Vixen 2.5; my project files are attached to make things easy to get started.


Jon McPhalen
EFX-TEK Hollywood Office

viper911h

Jon,

Amazing !! It is a little bit ridiculous that it took you a FULL hour to solve my problem, type up a full page of email/code, AND send me a working example  ;D

Thanks very much for the fast response.

I was really hung up on the timing issue. I had read on an old post something about 40ms @9600 and was thinking too much into trying to compensate for the added time of a header line.......  BUT your tick works amazing.  I am a .net guy and need to get back to 'Basics' I guess.


Cheers,
John

JonnyMac

December 22, 2009, 01:18:57 PM #3 Last Edit: December 22, 2009, 01:20:36 PM by JonnyMac
John,

Happy to assist.  I've been programming embedded processors since 1979 (high school) and was one of the early adopters of BASIC Stamps, suffice it to say, I have a little practice.

Vixen is written around the .Net framework so you could, perhaps, write a custom driver. 

Just for grins, I "unwound" the BS2 loop and was able to improve the sequence resolution from 200ms down to 125ms (8x per second).  Here's what that code looks like:

' =========================================================================
'
'   File...... Vixen_Input_v2.BS2
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              (remove my name if you modify and repost)
'   E-mail....
'   Started... 22 DEC 2009
'   Updated... 22 DEC 2009
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Receives channel control data from Vixen using the Generic serial driver.
' The driver should be set as follows:
'
' Baud..... 2400
' Header... (checked) EFX
' Footer... (not checked)
'
' Ensure that the Vixen project has 16 channels defined, even if some are
' not used as this program expects to receive 16 bytes after the "EFX"
' header.  If a channel value is 0-127 the output will be off, if it is
' 128-255 the output will be on.
'
' Vixen event timing should be set to 125ms or higher.


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


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

RX              CON     16                      ' for programming port


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

IsOn            CON     1                       ' for active-high in/out
IsOff           CON     0

Yes             CON     1
No              CON     0

#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T1200       CON     813
    T2400       CON     396
    T4800       CON     188
    T9600       CON     84
    T19K2       CON     32
    T38K4       CON     6
  #CASE BS2SX, BS2P
    T1200       CON     2063
    T2400       CON     1021
    T4800       CON     500
    T9600       CON     240
    T19K2       CON     110
    T38K4       CON     45
  #CASE BS2PX
    T1200       CON     3313
    T2400       CON     1646
    T4800       CON     813
    T9600       CON     396
    T19K2       CON     188
    T38K4       CON     84
#ENDSELECT

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

Baud            CON     T2400                   ' do not speed up!


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

buf0            VAR     Byte                    ' channels buffer
buf1            VAR     Byte
buf2            VAR     Byte
buf3            VAR     Byte
buf4            VAR     Byte
buf5            VAR     Byte
buf6            VAR     Byte
buf7            VAR     Byte
buf8            VAR     Byte
buf9            VAR     Byte
buf10           VAR     Byte
buf11           VAR     Byte
buf12           VAR     Byte
buf13           VAR     Byte
buf14           VAR     Byte
buf15           VAR     Byte


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

Reset:
  OUTH = %00000000 : OUTL = %00000000           ' clear all
  DIRH = %11111111 : DIRL = %11111111           ' set outputs


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

Main:
  SERIN RX, Baud, [WAIT("EFX"), STR buf0\16]    ' wait for stream

  OUT0  = buf0.BIT7
  OUT1  = buf1.BIT7
  OUT2  = buf2.BIT7
  OUT3  = buf3.BIT7
  OUT4  = buf4.BIT7
  OUT5  = buf5.BIT7
  OUT6  = buf6.BIT7
  OUT7  = buf7.BIT7
  OUT8  = buf8.BIT7
  OUT9  = buf9.BIT7
  OUT10 = buf10.BIT7
  OUT11 = buf11.BIT7
  OUT12 = buf12.BIT7
  OUT13 = buf13.BIT7
  OUT14 = buf14.BIT7
  OUT15 = buf15.BIT7

  GOTO Main


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


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


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


Yep, it's a little brute force but is in fact faster as it removes the loop overhead created for each channel.  Sometimes less pretty is actually better.
Jon McPhalen
EFX-TEK Hollywood Office