contact info:
info@blueink.com

Blueink.com
3014 Bluff #101
Boulder CO 80301

The BX24 and Director
Jen Lewin, Physical Computing 2001

Sending data from the BX24 to and from director is relatively easy.

Some very important things to keep in mind:

1) Always find a way to check your code (and debug.print) to make sure what you think you are sending is in fact, what you are sending.

2) once you know your code is 'ok', always check by opening hyperterm or Zterm (mac). Make sure you are receiving serial info, at the specified baud/port/etc.

3) Once you have completed steps 1 -2, you can then start working in director. If you have trouble running the director open port functions, it is because you probably have the com port still open somewhere else.

To use serial with director you will need Geoff Smiths Serial Extra. (copy or download this extra to your director extra's directory).

The link above also describes all of the commands, and features for this extra.

Here is a quick piece of BX code that sends serial information to Director (using a photocell on pin 13, and a potentiometer on pin 19).

Click here to download the complete BX code plus Director file

If you cannot download the examples above- I have included the code below.

'----------------------------------------------
'BX24 Serial to Director- Jen Lewin
'in the below example, a photocell is wired to pin 13, and a potentiometer
'is wired to pin 19. This pot, is used tune the photocell range.

'The program sends the photocell and pot values out to director.
'A number 1 is sent to initiate this sequence.
'The pot is used to 'tune' the range of the photocell- depending on the
'existing lighting conditions (this is a nice way to 'tune' your sensors
'on the fly, without needing to reprogram.


dim outputBuffer(1 To 30) as byte
dim inputBuffer(1 To 30) as byte

'dim getlight as integer
dim light as integer
dim tune as integer
dim color as byte
dim out as byte
dim serialOUTpin as byte
dim serialINpin as byte

sub main()

serialOUTpin = 12
serialINpin = 11

' open the input and output buffers:
call openQueue(outputBuffer, 30)
call openQueue(inputBuffer, 30)

' define which pins we'll use for serial in and out:
call defineCom3(serialINpin, serialOUTpin, bx1000_1000)
call openCom(3, 9600, inputBuffer, outputBuffer)

do
tune = getADC(19) \ 4 'a range of 0 to 255- must be a byte
light = getADC(13) \ 4 + 2 'a range is 0 - 255 - must be a byte
'I add 2 here to make sure that I never recieve anything close to a 1 value
'as I need 1 to send to director to start my sequence.

out = 1 'director knows to start sequence when 1 is recieved.
call putQueue(outputBuffer, out, 1)' tell director to GET READY
call putQueue(outputBuffer, light, 1) 'send LIGHT value (photocell)
call putQueue(outputBuffer, tune, 1) 'send Tune value (pot)


loop

End Sub

Once you can test this code, and see it working in Hyperterminal (or Zterm)...
Try out the following director piece

--Director 8.0 BX24
global gSerialPort

on startMovie
global gserialPort

if the platform contains "macintosh" then
-- open the mac xtra
openxlib "SerialXtra"
else
--open the PC xtra
openxlib "SerialXtra.x32"
end if

-- make a new instance of the xtra
-- if you are not using COM1,
-- put the name of your serial port in below:
put new(xtra "serialXtra", "COM1") into gserialPort

-- set the data rate, start bits, etc:
setProtocol(gSerialPort, 9600, "n", 8, 1)

end

on stopMovie
global gSerialPort

-- dispose of the xtra and close the xtra file
set gSerialPort to 0
closeXlib
end


on enterframe

indata = readnumber( gSerialPort )

if indata = 1 then
sun = gSerialPort.readNumber()--read in one number
suncolor = gSerialPort.readNumber() / 30
sprite(6).width=sun * suncolor--do something with it
sprite(6).height=sun * suncolor
put sun into field "photocell"
put suncolor into field "potdata"
end if

gSerialPort.readString() -- clear out the serial port

end

on exitFrame
go to frame 1
end