2

I am trying to get data from D6T Omron thermal sensor. It works fine with both Arduino and Processing when I connect it to pc directly. However, it seems to always cannot read my last data in my data array when i use Xbee on them. It results in a NaN for my last data in my array in processing display [Fig 1].

Anyone having any thoughts on this? Any help will be much appreciated! =D

Another problem i having here is that i was trying to make a popup window when my sensor senses a sum of 34*4 in the center pixels with no success currently. The last data in the array returns in NaN error again and the program is not responding after that. [Similar with Figure 1.] D:

It actually works fine until we reach this stage "Serial.write(0x03)" from Arduino to processing when it senses a sum of 34*4 in the center. I am confused. Any idea on how to improve that? =) Thanks a lot in advance!

Attached below is my code (Arduino sketch):

#include <Wire.h>
#include <WireExt.h>

#define D6T_addr 0x0A
#define D6T_cmd 0x4C

int rbuf[35];
float tdata[16];
float t_PTAT;
float top_sum, bottom_sum, left_sum, right_sum, center_sum, center_row_sum;

void setup()
{
  Wire.begin();
  Serial.begin(9600);
  Serial.flush();
}

void loop()
{
  int i;

  if (Serial.available() > 0) {     
    int inByte = Serial.read();     
    if (inByte == 0x0001) {         

      Wire.beginTransmission(D6T_addr);
      Wire.write(D6T_cmd);
      Wire.endTransmission();

      if (WireExt.beginReception(D6T_addr) >= 0) {
        i = 0;
        for (i = 0; i < 35; i++) {
          rbuf[i] = WireExt.get_byte();
        }
        WireExt.endReception();

        t_PTAT = (rbuf[0]+(rbuf[1]<<8))*0.1;
        for (i = 0; i < 16; i++) {
          tdata[i]=(rbuf[(i*2+2)]+(rbuf[(i*2+3)]<<8))*0.1;
        }

        output_csv();  
        delay(250);
      }
      top_sum= tdata[0] + tdata[1] + tdata[2] + tdata[3];
      bottom_sum= tdata[12] + tdata[13] + tdata[14] + tdata[15];
      right_sum= tdata[0]+ tdata[4] + tdata[8] + tdata[12];
      left_sum= tdata[3] + tdata[7] + tdata[11] + tdata[15];
      center_sum= tdata[5] + tdata[6] + tdata[9] + tdata[10];
      center_row_sum= tdata[1] + tdata[2] + tdata[5] + tdata[6] + tdata[9] + tdata[10] + tdata[13] + tdata[14];

     if (center_sum>34*4)
    {
      //Serial.flush();
      Serial.write(0x0003);
      delay(100);

    }     
}
  }
}


void output_csv() {
  for (int i = 0; i < 16; i++) {
    Serial.print(tdata[i]);
    if (i < 15) {
      Serial.print(",");
    } 
    else {
      Serial.println();
    }
  }
}

Attached below is my code in Processing:

import processing.serial.*;
import controlP5.*;
import javax.swing.JOptionPane.*;
ControlP5 cp5;
javax.swing.JOptionPane JOptionPane;

Textlabel myTextlabelA;
boolean canStart = true;
boolean canInput = false;
boolean Start = false;
String typedText = "Comments: ";
PFont font;
int confirm;


float[] tdata = new float[17]; 
float tptat; // PTAT
String portName; 
//int serialport = 0; 

String buf; 
float colourGreen; //change green in relation to temperature 

int lbTemp = 25; //lowest relative temperature
int hbTemp = 40; //highest relative temperature 
Serial myPort;  // Create object from Serial class


void setup() {
  size(600,768);
  background(ControlP5.BLACK);
  myPort = new Serial(this, "COM15", 9600);
  myPort.clear();
  cp5 = new ControlP5(this);

  myTextlabelA = cp5.addTextlabel("label")
                    .setText("GUI of Alive Human Detection System.")
                    .setPosition(120,10)
                    .setColorValue(#FFFAF0)
                    .setFont(createFont("Georgia",20))
                    ;

  cp5.addButton("Start")
     .setPosition(115, 670)
     .setSize(100,30)
     ;

  cp5.addButton("Stop")
     .setPosition(375, 670)
     .setSize(100,30)
     ;
}

public void Start(int theValue) {
  println("Initialising...");
  println("Connected.");
  Start = !Start;
}

public void Stop(int theValue) {
  println("Shuting Down...");
  myPort.write(0x02);
  Start = !Start;

}

void draw() {
    if (Start){

    myPort.write(0x01); 
    delay(100); 
    while (myPort.available() > 0) { 
    delay(500);  
    buf = myPort.readString(); 
    myPort.clear();  
    tdata = float(split(buf, ','));  
    for (int i = 0; i <16; i++) { 
    colourGreen = map(tdata[i],lbTemp,hbTemp,255,0);
    fill (255,colourGreen,0);

      if (i == 0)
    { rect(450,64,150,150);}
      else if (i == 1)
    { rect(300,64,150,150);}
      else if (i == 2)
    { rect(150,64,150,150);}
      else if (i == 3)
    { rect(0,64,150,150);}
      else if (i == 4)
    { rect(450,214,150,150);}
      else if (i == 5)
    { rect(300,214,150,150);}
      else if (i == 6)
    { rect(150,214,150,150);}
      else if (i == 7)
    { rect(0,214,150,150);}
      else if (i == 8)
    { rect(450,364,150,150);}
      else if (i == 9)
    { rect(300,364,150,150);}
      else if (i == 10)
    { rect(150,364,150,150);}
      else if (i == 11)
    { rect(0,364,150,150);}
      else if (i == 12)
    { rect(450,514,150,150);}
      else if (i == 13)
    { rect(300,514,150,150);}
      else if (i == 14)
    { rect(150,514,150,150);}
      else if (i == 15)
    { rect(0,514,150,150); }

    if (tdata[i]<5) {fill(255);} else {fill(0);}
      if (i ==0)
      {
      textAlign(CENTER, CENTER);
      textSize(20);
      text(str(tdata[i]),525, 139);}
      else if (i == 1)
      {
      textAlign(CENTER, CENTER);
      textSize(20);
      text(str(tdata[i]),375, 139);
      }
      else if (i == 2)
      {
      textAlign(CENTER, CENTER);
      textSize(20);
      text(str(tdata[i]), 225, 139);
      }
      else if (i == 3)
      {
      textAlign(CENTER, CENTER);
      textSize(20);
      text(str(tdata[i]),75, 139); 
      }
      else if (i == 4)
      {
      textAlign(CENTER, CENTER);
      textSize(20);
      text(str(tdata[i]), 525, 289); 
      }
      else if (i == 5)
      {
      textAlign(CENTER, CENTER);
      textSize(20);
      text(str(tdata[i]), 375, 289);  
      }
      else if (i == 6)
      {
      textAlign(CENTER, CENTER);
      textSize(20);
      text(str(tdata[i]), 225, 289);  
      }
      else if (i == 7)
      {
      textAlign(CENTER, CENTER);
      textSize(20);
      text(str(tdata[i]), 75, 289); 
      }
      else if (i == 8)
      {
      textAlign(CENTER, CENTER);
      textSize(20);
      text(str(tdata[i]), 525, 439);
      }
      else if (i == 9)
      {
      textAlign(CENTER, CENTER);
      textSize(20);
      text(str(tdata[i]), 375, 439);  
      }
      else if (i == 10)
      {
      textAlign(CENTER, CENTER);
      textSize(20);
      text(str(tdata[i]), 225, 439);
      }
      else if (i == 11)
      {
      textAlign(CENTER, CENTER);
      textSize(20);
      text(str(tdata[i]), 75, 439);
      }
      else if (i == 12)
      {
      textAlign(CENTER, CENTER);
      textSize(20);
      text(str(tdata[i]), 525, 592);  
      }
      else if (i == 13)
      {
      textAlign(CENTER, CENTER);
      textSize(20);
      text(str(tdata[i]), 375, 592); 
      }
      else if (i == 14)
      {
      textAlign(CENTER, CENTER);
      textSize(20);
      text(str(tdata[i]), 225, 592);
      }
      else if (i == 15)
      {
      textAlign(CENTER, CENTER);
      textSize(20);
      text(str(tdata[i]), 75, 592);  
      }
    }
    delay(250);
    CheckSerial();  
  }

    }

}

void CheckSerial()
{  
    confirm = myPort.read(); 
    if (confirm == 0x03)
  {
  int dialogResult = JOptionPane.showConfirmDialog (null, "Human found? Please Confirm!!", "Alert!", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
  if(dialogResult == JOptionPane.YES_OPTION)
  {
  //futher action
  }
  }
}

Figure 1

3
  • Have you tried displaying the string you are receiving in order to confirm it's correct?
    – Majenko
    Apr 9, 2016 at 17:56
  • Okay! i will try again. =) thanks! @Majenko
    – lim lagoon
    Apr 11, 2016 at 13:53
  • @Majenko I tried to change my code a bit but still no positive result. Whenever it detected 32*4, Arduino should be sending Serial.print("found"); to processing and processing should be reading the string "found" and then showing a popup window in result. In real scenario, when it meet the condition, and Arduino started to Serial.print ("found") , I got ArrayIndexOutOfBoundException :1 in processing and the program is not responding after that. I have no idea where seems to be the problem. D: Any suggestion on how to improve these?
    – lim lagoon
    Apr 12, 2016 at 10:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.