How to draw a 8x8 array to present the Panasonic infrared array sensor "Grid-eye" in Processing via Arduino?
in
Integration and Hardware
•
4 months ago
Hello!!!
I tried to draw a 8x8 array to present the temperature situation with an infrared array sensor. First,I used the Arduino to communicate the sensor and got a list of temperature readings which seemed correct. However, I used Processing to draw the 8x8 array, It gave me a list of temperature readings which seemed correct as well,but the 8x8 array flashed somehow. Is there anyone could help me correct my codes?
Thx a lot !!!!!
Arduino
--------------------------------------------------------------------------------------------------
#include <Wire.h>
byte pixelTempL;
byte pixelTempH;
char addr = 0x69;
float celsius;
void setup() {
Wire.begin();
Serial.begin(115200);
}
void loop()
{
//First two data registers for the pixel temp data are 0x80 and 0x81
pixelTempL=0x80;
pixelTempH=0x81;
//Get Temperature Data for each pixel in the 8x8 array. Will loop 64 times.
for(int pixel = 0; pixel <= 63; pixel++)
{
//Get lower level pixel temp byte
Wire.beginTransmission(addr);
Wire.write(pixelTempL);
Wire.endTransmission();
Wire.requestFrom(addr,1);
byte lowerLevel = Wire.read(); //
//Get upper level pixel temp byte
Wire.beginTransmission(addr);
Wire.write(pixelTempH);
Wire.endTransmission();
Wire.requestFrom(addr,1);
byte upperLevel = Wire.read();
//Combine the two bytes together to complete the 12-bit temp reading
int temperature = ((upperLevel << 8) | lowerLevel);
//Temperature data is in two's compliment, do conversion.
if (upperLevel != 0)
{
temperature = -(2048 - temperature);
}
celsius = temperature*0.25;
pixelTempL=pixelTempL+2;
pixelTempH=pixelTempH+2;
Serial.print(celsius,DEC);
Serial.println(",");
}
} //end loop
Processing
--------------------------------------------------------------------------------------------------
import processing.serial.*;
Serial port;
int i,j;
String data = "";
float temp ;
int cols = 8;
int rows = 8;
int lf = 10;
Cell[][] grid;
void setup()
{
size(640,640);
grid = new Cell[cols][rows];
println(Serial.list());
frameRate(10);
port = new Serial(this, Serial.list()[0], 115200);
port.bufferUntil(',');
for (int i = 0; i < cols; i++)
{
for (int j = 0; j < rows; j++)
{
grid[i][j] = new Cell(i*80,j*80,80,80);
}
}
}
void draw(){
background(255);
for (int i = 0; i < cols; i++)
{
for (int j = 0; j < rows; j++)
{
grid[i][j].reads();
grid[i][j].fills();
}
}
}
class Cell {
float x,y;
float w,h;
Cell(float tempX, float tempY, float tempW, float tempH)
{
x = tempX;
y = tempY;
w = tempW;
h = tempH;
}
void reads()
{
temp = float(data);
println(temp);
}
void fills()
{
if(temp > 25.0)
{
rect(x,y,w,h);
fill(255,0,0);
}
else if(temp <= 18.0)
{
rect(x,y,w,h);
fill(0,0,255);
}
else
{
rect(x,y,w,h);
fill(0,250,0);
}
}
}
void serialEvent(Serial port)
{
data = port.readStringUntil(',');
data = data.substring(0, data.length()-1);
}
1