Authoring Languages for Talking with Microcontrollers

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.

The basic steps are:

  1. Find the serial extension file or files for your environment. Thank god for the internet. (Director eg. Macromedia.com,or Geoff Smith)
  2. Find the right place for these files on your machine. (Director eg. in the same folder as the movie or in the Xtras folder)
  3. Give your authoring environment access to these files. (director eg. openXlib "serialXtra")
  4. 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" ) )
  5. Use the reference in the variable configure the port (Director eg. gSerialPort.SetProtocol(9600, "n",8,1) )
  6. Use the reference in the variable get stuff (Director eg. set heatVar = gSerialPort.readNumber() )
  7. Use the reference in the variable send stuff (Director eg. gSerialPort.writeChar("B"))

 

Director
  1. 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.
    1. openxlib "SerialXtra" --use the file name
    2. 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).
    3. 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.
  2. 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

  3. 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 
    
    

  4. 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