Interface & Application Programming

This week was about using different programs to portray the data received from sensors in audio or visual format. After using Neil's step response Python program to configure the output of my proximity sensor last week and learning Pyhton in the process I decided to try something different for this week's assignment and try using Processing.

The online documentation and tutorials for Processing are really clear and useful and I managed to teach myself basic use in a day.

Calculations

I built Neil's temp sensor board with the thermistor and used the data from the thermistor datasheet in the Steinhart-Hart equation:

thermistor_equation (1K)

to calculate the resistance of the thermistor across its operating range of temperatures, 'To' being 25 degrees Celsius

As the bridge in the circuit creates a simple voltage divider between the thermistor and the 10k resistor I was able to predict the output of the ADC as follows:

thermistor_ADC_output (52K)

Note The USB voltage reference was measured at 5.06V and the divided PB4 input as 2.52V

Processing
The trickiest part for me in developing the Processing sketch was the timing for reading the serial data from the microcontroller. The mistake I made was trying to read the incoming data as a constant stream of bytes. I had converted Neil's C program into assembly language and this included a 10us delay between bytes to ensure there was no bit confusion. Therefore there wasn't always a byte waiting in the buffer to read so I had to create a wait loop (while) to stay in until a byte arrived. In Processing I achieved it like this:

while (test==1) { //will stay in loop until 1,2,3,4 framing received)
if (myPort.available() > 0) { //tests for byte available in buffer
int byte1 = byte2;
byte2 = byte3;
byte3 = byte4;
byte4 = myPort.read();//reads byte from serial port
if ((byte1 == 1) && (byte2 == 2) && (byte3 == 3) && (byte4 == 4)) {
test = 2; //to skip out of 'while' loop
}
}
}
while (test==2) { //after 1,2,3,4 framing received, will stay in loop until lowbyte received
if (myPort.available() > 0) {
lowbyte = myPort.read();
test = 3; //to skip out of 'while' loop
}
}
.....

I used the 'void setup()' function to create my window and any static graphics such as the bottom bulb and the temperature markings as 'setup' only runs once and then read my data and reprinted the height of the 'mercury' in the 'void draw()' function as this repeats over and over while the program is running. The final result is shown here:

I must point out that this is not properly calibrated but instead the values calculated based on the electronics and microcontroller.