Authoring Languages for Talking with Microcontrollers
- Contents of this page:
See
Microcontroller Programming
MAIN
PHYSICAL COMPUTING PAGE
Authoring Environments
When you want to use a microcontroller as part of a Multimedia experience,
you will have to find an authoring environment that will fill your needs for
displaying your pictures and sounds and also use serial communication to
activate and listen to the microcontroller. Because everybody's multimedia needs
will be so different, these pages only cover the serial communication between
the microcontroller and the authoring environment and not how to make the sounds
and pixels move once the messages have arrived.
The examples given here are for Macromedia Director which is a very nice
authoring environment. If you are already comfortable in some other environment,
it can probably support serial communciation somehow, perhaps using an extension
of some kind.Extentions are little bits of software that allow your authoring
tool to go beyond its native capabilities. They are usually a single file that
has to be strategically placed. The hard parts are gettting (sometimes buying)
the file and then finding where to put it.
- Director 2,3,4,5 and 6 (can be extended by both xtras and xobjects)
- serialport Xobject. This is built into the Macintosh version so you
don't have to get anything or put it anywhere. On the PC you need a free
file called "commport.dll" but it does not work with NT. You can put this
file in the same directory as your movie and then say openxlib
"commport.dll"
- Xtra "serialXtra" from
Geoff Smith's PhysicalBits.com This costs money but it works on 95, MAC and
NT but you can get a demo version. You can put xtras in the Xtras folder
near the Director application and say nothing more. I prefer to put them in
the same folder as the movie and explicitly say openxlib "xtrafilename".
- Director 7 (can only be extended by xtras)
- Xtra "serialXtra" from
Geoff Smith's PhysicalBits.com This costs money but it works on 95, MAC and
NT but you can get a demo version. You can put xtras in the Xtras folder
near the Director application and say nothing more. I prefer to put them in
the same folder as the movie and explicitly say openxlib "xtrafilename".
- MAX has a built in serial object. You don't have to do anything.
- Hypercard. You have to get the Serial
Communications XCMDs and resedit them into your movie
- Java. You can buy
serial classes for Java although I think Sun is doing something new with Java 2.0.
- Visual Basic
The basic steps are:
- Find the serial extension file or files for your environment. Thank god
for the internet. (Director eg. Macromedia.com,or Geoff
Smith)
- Find the right place for these files on your machine. (Director eg. in the
same folder as the movie or in the Xtras folder)
- Give your authoring environment access to these files. (director eg.
openXlib "serialXtra")
- Create an instance of the serial object and make a global variable that
holds the reference to the object. (Director eg.set gSerialPort = new( xtra
"SerialXtra", "COM2" ) )
- Use the reference in the variable configure the port (Director eg.
gSerialPort.SetProtocol(9600, "n",8,1) )
- Use the reference in the variable get stuff (Director eg. set heatVar =
gSerialPort.readNumber() )
- Use the reference in the variable send stuff (Director eg.
gSerialPort.writeChar("B"))
- Director
-
- Xtras Serial communication is not supported within the native
vocabulary of Director so you have to exend it with an Xtra. If I were you I
would put the xtra in the same folder as your movie (not in the xtras
folder). I would manually tell director about the xtra using openxlib (see
below in the configure handler). Most xtras are self documenting so you
might want to type these things first in the message box before you do any
scripting in order to learn how to use the xtra.
- openxlib "SerialXtra" --use the file name
- showxlib --this will show you a list of xtras that direct knows about
by the name director uses (not neccessarily the same as the filename).
- put mmessageList( xtra "SerialXtra") -- use director's name for the
xtra rather than the filename. This should spew into the message box all
the possible commands and functions for this xtra and a their syntaxes.
- Configuring Serial Port When using XObjects you generally have to
start them up by creating a variable that refers to them. After that to use
the XObject you have to use that global variable to refer to the XObject.
Right after starting up the serial XObject you should configure it for speed
and port. You should generally always have a script for killing the XObjects
that you create.
global gSerialPort
on startMovie
configureSerial
end
on stopMovie
killSerial
end
on configureSerial
openxlib "SerialXtra"
--tell director that you want to use the xtra
set gSerialPort = new( xtra "SerialXtra", "COM2" )
--specify which port. you can say modem and printer from mac
gSerialPort.SetProtocol(9600, "n",8,1)
-- the default is 9600,"n",8,1 so we don't really need say this
gSerialPort.readString()
--clear out anything that was in there
gSerialPort.writeString("Z")
--prime the pump with some character in case the stamp was stuck in serin
end
on killSerial
set gSerialPort to 0
end
Table of
Contents
- Recieving Serial Info You can always be looking for serial
information as well as doing other things by putting the mreadstring command
in an idle or exitframe script.
on exitFrame
checkserial
end
on checkserial
if objectP(gSerialPort) then -- if this is a valid object
if gSerialPort.CharsAvailable() > 0 then
-- if there is something waiting to read
set heatVar = gSerialPort.readNumber() --read in one number
set the width of sprite 1 to heatvar --do something with it
set the height of sprite 1 to heatvar
gSerialPort.WriteNumber("B")
--send something back to satisfy serin
end if
end if
end
*********Checkserial (COMPLICATED MANY SENOSRS )
on checkserial
if objectP(gSerialPort) then
-- if this is a valid object
if gSerialPort.CharsAvailable() > 3 then
-- if there is something waiting to read
--read them in the same order that you sent them in the serout statement in the stamp
set heatVar = 255-gSerialPort.readNumber() --read in one number
set lightVar = gSerialPort.readNumber() --read in one number
set flexVar = gSerialPort.readNumber() --read in one number
set switchVar = gSerialPort.readNumber() --read in one number
set the width of sprite 1 to heatvar
set the height of sprite 1 to heatvar
set the rotation of sprite 2 = flexvar
set the blend of sprite 3 = 100 -lightvar*10
if switchVar = 65 then
set the visible of sprite 4 = true
else
set the visible of sprite 4 = false
end if
gSerialPort.WriteNumber(the mouseh/3)
--send a number back to be used by the pulsout command
end if
end if
end
- Sending Serial Info Sending things out the serial port is quite
easy.
on mousedown
global gSerialPort --This is how you send stuff.
gSerialPort.WriteNumber(the mouseh/3)
end
Table of
Contents
If you have suggestions or corrections please contact:
dan.osullivan@nyu.edu