Physical Computing | The Poetics of Virtual Spaces
 
Week 1 --> Basic Electronics
Week 2/3 --> BasicX, BX24 Programming
Week 4 --> Memory & Variables
Week 5 --> Analog Input
Week 6 --> Transistors & Relays & A Tech Research About TTC (Motion/Color Capture)
Week 7 --> Analog Output
Week 8 --> Midterm Project - The LED 5x7 Matrix Quest
Week 9 --> Serial Communication
Week 10 --> Serial To Director
Wooooo, this sounds familiar. Previous life maybe? Nop. Tech research at week 6

It was nice to be familiar with the material for a change. I can't say that I am the master of serial communication, but it was a thorough cover of a subject we briefly research. Maybe briefly is not the right word here, because I recall week 6 to be extremely busy in trying to figure out this new form of communication - BX to Director (at this point Director is out of the picture, but soon to join). By saying briefly I mean to express how clueless I was back then. I realize in this class as the others, that I find myself is constant loops of knowledge. Meaning that for every new element I learn, a more comprehensive explanation arrives at a later time, and then is when it catches on. It feels intense.

So, now I want the BX to communicate with my computer. The most important term to remember is the Buffer, which is the storage space in the BX for info that come in thru the serial port. While the buffer waits for info, it allows for more events to occur at the same time (good boy, buffer).
We need to set up a queue for the buffers in the form of an array. Like such:

    dim inputBuffer(1 To 13) As Byte
    dim outputBuffer(1 To 10) As Byte

Next I need to define the com3:

    call defineCom3(serInPin, serOutPin, bx1000_1000)
serInPin - a byte variable, the pin number you want to receive serial information on (5-20)
serOutPin - a byte variable, the pin number you want to send serial data out on (5-20)
parameter mask- a byte variable defining the communications parameters.

Next, I need to open a port. The code below, define port com3 but I found that port com1 is the one my computer is willing to provide (what a snob). The code still call com3 but somewhere else I will open port com1:

    call openQueue(inputBuffer, 13) call openQueue(outputBuffer, 10)
    ' open COM3: call openCom(3, 9600, inputBuffer, outputBuffer)
port number- a byte variable, the serial port you want to open (1 or 3).
Baudrate- a long integer variable, the baud rate you want to communicate at (common baud rates range from 300 to 19200 on Com3)
input buffer- a queue for input data;
output buffer- a queue for output data

And finally, I shoot my data out:

    call putQueue(OutputBuffer, outData, numBytes)

outputBuffer- a queue of bytes into which you're going to put the byte to be sent
outData- data to be sent; can be any data type, but you have to state how many bytes you're sending in numBytes
numBytes- how many bytes you're putting in the queue. If outData is a byte, numBytes is 1. If outdata is an integer, numBytes is 2, and so forth.

When sending the code to the BX, the serial cable is at pins 1 to 4, but (and it's a bit annoying) when I need the BX to send out data back to the computer, the serial cable pins go to pins 11 and 12 (11 - BX sends data, 12 - BX recieves). The third pin goes to a blank location, and the last pin gets ground.
To see the data being sent from my lil' BX I opened the HyperTerminal program (comes with Windows) and here is when I call port com1.

This 0's and 1's is what BX told my computer
before pressing switch:
After pressing switch:



  


When I used a potentiometer gibberish came out. I replaced the getPin() line in the main do loop to this:
    thisByte = cByte(getADC(14)\4)


Take a look at this ascii table to understand why the gibberish.

Finally the hello world process:
  

�2005 Limor (Garcia) Hader | limilim (at) gmail