Communicating with Processing through a PIC has been something i have loathed (and avoided) ever since first trying about a year ago. Today I still don't enjoy the process, I can say, with confidence, that it is something I am comfortable in doing...

Why the turnaround? Simply, because it was something I had to do.

While the assignment was not aking for much, it took several days (4) of banging my head against the wall for it to sink in. I basically took the code samples Tom provided, used a basic potentiometer as a sensor, and tried to get those to work properly. Once those codes worked, I started to add bells and whistles.

After successfully implementing Tom's Processing Datalogger, I repurposed it to suit my whims.

I wanted to depart from the green and black horizontal scrolling mountains I so closely associate with computer-ness. I ended up using circles that grow as sensor data increases (turning a pot, pushing on an FSR, bending a flex sensor, et cetera). I also mapped the color of the circle to reflect the changing sensor levels. For reference, I added markers every 50 steps. Right now, the color changes with the growing circles but i would like to change it to reflect something different (like magnitude of change in peak value or an additional sensor's reading).

Following are the codes I used in this week's assignment (easier to read version):

Sending All Sensor Data - PIC Code

define OSC 4
DEFINE  ADC_BITS        10
DEFINE  ADC_CLOCK       3
DEFINE  ADC_SAMPLEUS    20

SensorValue var word
SensorValueB var Byte

tx var portc.6
rx var portc.7

n9600 con 16468
Threshold = 30
PeakValue = 0
noise = 5

TRISA = %11111111
ADCON1 = %10000010

Main:
    high portb.0
    ADCin 0, SensorValue
SensorValueB = SensorValue/4

    serout2 tx, n9600, [SensorValueB]

    low portb.0
    pause 50
Goto main

Sending only Peak Values - PIC code
define OSC 4
DEFINE  ADC_BITS        10          
DEFINE  ADC_CLOCK       3         
DEFINE  ADC_SAMPLEUS    20         
PeakValue var word
SensorValue var word
LastSensorValue var word
Threshold var word
Noise var word
PeakValueB var byte
tx var portc.6
rx var portc.7
n9600 con 16468 Threshold = 50     
PeakValue = 0
noise = 5          
TRISA = %11111111
ADCON1 = %10000010   
Main:
    high portb.0
    ADCin 0, sensorValue
' check to see that it's above the threshold:
    If sensorValue >= threshold + noise then
' if it's greater than the last reading,
' then make it our current peak:
        If sensorValue >= lastSensorValue + Noise then
            PeakValue = sensorValue
        endif
' if the sensorValue is not above the threshold,
' then the last peak value we got would be the actual peak:
    Else
        If peakValue >= threshold then
' this is the final peak value; take action
            PeakValueB = peakvalue/4
            serout2 tx, n9600, [peakValueB]
        endif
' reset peakValue, since we've finished with this peak:
        peakValue = 0
           Endif
    low portb.0
' store the current sensor value for the next loop:
    lastSensorValue = sensorValue
    pause 50
Goto main

Datalogger - Ellipse - Processing Code

import processing.serial.*;
Serial myPort;
int serial = 1; // data from serial port
void setup () {
size(300, 300);
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
background(255);
noFill();
stroke (200);
ellipse (150, 150, 50, 50);
ellipse (150, 150, 100, 100);
ellipse (150, 150, 150, 150);
ellipse (150, 150, 200, 200);
ellipse (150, 150, 250, 250);
}
void draw () {
if (myPort.available() > 0) {
serial = myPort.read();
serialEvent();
}
}
void serialEvent () {
background(255);
fill(serial, serial/3, 100);
stroke (0);
ellipse(150, 150, serial, serial);
noFill();
stroke (200);
ellipse (150, 150, 50, 50);
ellipse (150, 150, 100, 100);
ellipse (150, 150, 150, 150);
ellipse (150, 150, 200, 200);
ellipse (150, 150, 250, 250);
println (serial);
}


Image 2