Wednesday, October 20, 2004

Lab 5 10.20.04 - Analogue Input through to Serial Processing

Norretranders, User Illusion, ch. 6, "The Bandwidth of Consciousness" deals with human brain cell capacity to process information from the outside world. I'm unclear on the point of this reading but I get the sense that it's part scientific, part qualitative. The argument goes that we cannot possibly register everything in our sensory environment so the brain has to decipher messages in a complex fashion.

Here is a connector schematic from Tom Igoe's site to solder a serial connection.




For the lab assignment, I hooked up 2 potentiometers to a PIC, using the BASIC program from the serial lab. Here is the processing code to vary amplitude of the sine waves:


/* Serial call-and-response
by Tom Igoe (with adjustments by Dan)

Sends a byte out the serial port, and reads 3 bytes in.
sets background color, x location and rotation of a rect

Updated October 12, 2004
*/

int bkcolor; // background color
int[] serialStuff = new int[3]; // where we'll put what we receive
int serialCount = 0; // a count of how many bytes we receive
int xpos; // x location of rectangle
int rot; // rotation of rectangle
//BFont font;

void setup() {
//begin serial communication
beginSerial();
size(640, 240);
// font = loadFont("Garamond-Bold.vlw.gz");

//start off our call and response by sending 65;
serialWrite(65);
}

void loop() {
println(xpos);
//draw background with red value from sensor
background(bkcolor,bkcolor,bkcolor);
//textFont(font, 44);
float xoff = 0.0;

background(153,51,0);
stroke(255,255,255);
xoff = xoff + .25;
float n = noise(xoff) * 1000;
float a = 60.0;
float inc = TWO_PI/18.0;



for(int i=0; i<900; i=i+10)
{
line(i+400, bkcolor, i, +noise(xoff)*sin(a)*xpos);
// line(i+400, random(int(height)), i+400, +noise(xoff)*sin(a)*800.0);
a = a + inc/5;
}

}

void serialEvent() {
// add the latest byte from the serial port to array:
serialStuff[serialCount] = serial;
serialCount++;

// if we have 3 things set our variables:
if (serialCount > 2 ) {
bkcolor = serialStuff[0];
xpos = serialStuff[1];
rot = serialStuff[2];
// clear the string when we're done, and ask for more:
serialCount = 0;
// send a capital A to request new sensor readings:
serialWrite(65);
}
}

Here is the PIC code from Wlodek's Journal for Serial Output:

PIC CODE

'****************************************************************
'* Author : wk372 *
'* Date : 10/20/2004 *
'****************************************************************

txPin var portc.6
rxPin var portc.7
grLed var portd.0
ylLed Var portd.1

output grled
output ylLed
output txpin
input rxpin

inputVar VAR byte
pot1 VAR WORD ' Create variable to store result pot1
pot2 VAR WORD ' Create variable to store result pot2

' POTENTIOMETER SETUP
' Define ADCIN parameters
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 10 ' Set sampling time in uS

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify result

'light green LED to know program is working

high grled
pause 300
low grled
pause 150
high grled

PAUSE 500 ' Wait .5 second

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

main:

'Yellow LED to know program is running

low ylled

ADCIN 0, pot1 'potentiometer1 variable
ADCIN 1, pot2 'potentiometer2 variable
pot1 = pot1/4 'divide the value because it's too big
pot2 = pot2/4 'divide the value because it's too big

'----------------------
' THE LISTENING CODE - puts message into inputVar
serin2 rxpin, 16468, [inputVar] 'listening for processing signal

high ylled

if inputVar=65 then ' if received message is 65, then respond to processing

serout2 txpin, 16468, [pot1,pot2] 'talk to processing

ENDif

goto main









Processing accepts serial data from the PIC, so I used a program with a Sine function and varied the function parameters according to input from the potentiometers.

As a side note, I am working with Wlodek to parse sound data from the Sonia plug-in into Processing.

For the Lab assignment, Java-based processing receives serial input from the PIC. Here is a photo of two potentiometers controlling a Processing assignment.



The two potentiometers control extremities on a Sine curve.

Here is a photo of the output to Processing