Recently, I purchased an Arduino and some other various assorted parts from Sparkfun, including a Melexis Infrared Thermometer ( Infrared Thermometer - MLX90614 - SEN-09570 - SparkFun Electronics )
I wired up the unit according to these instructions, using this arduino code (posted below): http://bildr.org/2011/02/mlx90614-arduino/
After a little bit of farting around, I managed to get some usable data from the sensor into Processing.
My dilemma is that the temperature data only comes in a few times a second.
What can I do to squeeze more data samples out of this nifty little sensor in a given timeframe?
I'm a newbie to electronics, but I'm pretty familiar with programming. Here's the arduino code:
#include <i2cmaster.h>
void setup(){
Serial.begin(19200);
Serial.println("Setup...");
i2c_init(); //Initialise the i2c bus
PORTC = (1 << PORTC4) | (1 << PORTC5);//enable pullups
}
void loop(){
int dev = 0x5A<<1;
int data_low = 0;
int data_high = 0;
int pec = 0;
i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x07);
// read
i2c_rep_start(dev+I2C_READ);
data_low = i2c_readAck(); //Read 1 byte and then send ack
data_high = i2c_readAck(); //Read 1 byte and then send ack
pec = i2c_readNak();
i2c_stop();
//This converts high and low bytes together and processes temperature, MSB is a error bit and is ignored for temps
double tempFactor = 0.02; // 0.02 degrees per LSB (measurement resolution of the MLX90614)
double tempData = 0x0000; // zero out the data
int frac; // data past the decimal point
// This masks off the error bit of the high byte, then moves it left 8 bits and adds the low byte.
tempData = (double)(((data_high & 0x007F) << 8) + data_low);
tempData = (tempData * tempFactor)-0.01;
float celcius = tempData - 273.15;
float fahrenheit = (celcius*1.8) + 32;
// Serial.print("Celcius: ");
// Serial.println(celcius);
Serial.println(fahrenheit);
// Serial.println(fahrenheit);
// delay(10); // wait a second before printing again
}
And here's the processing script:
import processing.serial.*;
Serial myPort; // The serial port
int xPos = 0; // horizontal position of the graph
int yPos = 0; // vertical position of the graph
String nString = "lol";
float pinByte = 0;
void setup () {
// set the window size:
size(100, 100);
strokeWeight(1);
// List all the available serial ports
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my Arduino, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[1], 19200);
// don't generate a serialEvent() unless you get a newline character:
myPort.bufferUntil('\n');
// set inital background:
background(0);
}
void draw () {
// everything happens in the serialEvent()
}
void serialEvent (Serial myPort) {
// get the ASCII string:
String inString = myPort.readStringUntil('\n');
if ((inString != null)&&(inString.equals(nString)!=true)){
nString = inString;
// trim off any whitespace:
inString = trim(inString);
// convert to an int and map to the screen height:
float inByte = float(inString);
print(inByte+"\n");
inByte = map(inByte, 79, 90, 0, 255);
// draw the line:
stroke(inByte);
line(xPos, yPos, xPos, yPos);
// background(inByte);
// at the edge of the screen, go back to the beginning:
if (xPos >= width) {
xPos = 0;
yPos++;
}
else {
// increment the horizontal position:
xPos++;
pinByte = inByte;
}
}
}
Basically, the arduino sends the temperature in Fahrenheit through a serial cable at 19200 baud (increasing it does nothing) to the processing application which takes the temperature (ignoring duplicates) and graphs them in a scan-line pattern across the domain. Unfortunately, this could take a while at the current speed of transmissions.
I heard that this thermometer could do PWM? How would I be able to take advantage of that for speed?
If the arduino can't extract the data fast enough alone, would this be more suitable?
Alternatively, can I have the arduino recieve data really fast from the sensor, store it in a buffer, and then dump the data later?
Thanks.

