HeatCam examples .... Please help!

Hi!
I’m the real beginner in this field :frowning:
I tried to follow various examples with my Sparkfun parts.
And I’m trying to do the example with processing Heatcam. ( Example 4 - Processing Heat Cam)

I do everything what they said (also checked the COM number) but it kept popping the the message of (NullPointerException).

/*
  Visualizing the Panasonic Grid-EYE Sensor Data using Processing
  By: Nick Poole
  SparkFun Electronics
  Date: January 12th, 2018
  
  MIT License: Permission is hereby granted, free of charge, to any person obtaining a copy of this 
  software and associated documentation files (the "Software"), to deal in the Software without 
  restriction, including without limitation the rights to use, copy, modify, merge, publish, 
  distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 
  Software is furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in all copies or 
  substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
  BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  
  Feel like supporting our work? Buy a board from SparkFun!
  https://www.sparkfun.com/products/14568
  
  This example is intended as a companion sketch to the Arduino sketch found in the same folder.
  Once the accompanying code is running on your hardware, run this Processing sketch. 
  This Processing sketch will receive the comma separated values generated by the Arduino code and
  use them to generate a thermal image.
  
  Hardware Connections:
  Attach the Qwiic Shield to your Arduino/Photon/ESP32 or other
  Plug the sensor onto the shield
*/

import processing.serial.*;

String myString = null;
Serial myPort;  // The serial port

float[] temps =  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

// The statements in the setup() function 
// execute once when the program begins
void setup() {
  size(400, 400);  // Size must be the first statement
  noStroke();
  frameRate(30);
  
  // Print a list of connected serial devices in the console
  printArray(Serial.list());
  // Depending on where your GridEYE falls on this list, you
  // may need to change Serial.list()[0] to a different number
  myPort = new Serial(this, Serial.list()[0], 115200);
  myPort.clear();
  // Throw out the first chunk in case we caught it in the 
  // middle of a frame
  myString = myPort.readStringUntil(13);
  myString = null;
  // change to HSB color mode, this will make it easier to color
  // code the temperature data
  colorMode(HSB, 360, 100, 100);
}

// The statements in draw() are executed until the 
// program is stopped. Each statement is executed in 
// sequence and after the last line is read, the first 
// line is executed again.
void draw() { 
  
  // When there is a sizeable amount of data on the serial port
  // read everything up to the first linefeed
  if(myPort.available() > 64){
  myString = myPort.readStringUntil(13);
  
  // generate an array of strings that contains each of the comma
  // separated values
  String splitString[] = splitTokens(myString, ",");
  
  // for each of the 64 values, map the temperatures between 20C and 40C
  // to the blue through red portion of the color space
  for(int q = 0; q < 64; q++){
   
    temps[q] = map(float(splitString[q]), 20, 40, 240, 360);
    
  }
  }
  
  
  // Prepare variables needed to draw our heatmap
  int x = 0;
  int y = 0;
  int i = 0;
  background(0);   // Clear the screen with a black background
  
  
  // each GridEYE pixel will be represented by a 50px square: 
  // because 50 x 8 = 400, we draw squares until our y location
  // is 400
  while(y < 400){
  
    
  // for each increment in the y direction, draw 8 boxes in the 
  // x direction, creating a 64 pixel matrix
  while(x < 400){
  // before drawing each pixel, set our paintcan color to the 
  // appropriate mapped color value
  fill(temps[i], 100, 100);
  rect(x,y,50,50);
  x = x + 50;
  i++;
  }
  
  y = y + 50;
  x = 0;
  }
  
  // Add a gaussian blur to the canvas in order to create a rough
  // visual interpolation between pixels.
  filter(BLUR,10);
} 


I can’t understand what’s wrong at all.
Can you please give me some comments?

Hello,

Are you able to send data to the Arduino serial monitor?
Do not run the Processing sketch when doing this.
Please show a screengrab of this output.

If you are receiving data on the Arduino serial monitor then you should be able to send this data to another software application (Processing or otherwise) with that COM port.

Did you select the correct COM port on the Processing side and modify this here?

  // Depending on where your GridEYE falls on this list, you
  // may need to change Serial.list()[0] to a different number
  myPort = new Serial(this, Serial.list()[0], 115200);

Be sure to turn the Arduino serial monitor (or plotter) are off when you are connecting your Processing sketch to the COM port.

:)

Thank you so much for your reply!!!

  • I checked the serial monitor/plotter and it worked well! (1st image)

  • When I run the Processing sketch, I turned off the serial plotter. (When I didn’t turn if off, it was popped up that the COM11 is busy.)

  • In Arduino, my COM port is viewed as COM11 in Arduino. (2nd image)

  • In Processing, it was written that [0] “COM11” as below so I let the number “0” in the code. (3rd image)

  • So, the problem is as below… (NullPointerException & something wrong which was marked with yellow line maybe…?) (4th image)

  • I put the images together in one file because I only can upload one because I’m new!

I know this could be kinda very basic question… Sorry for that. :frowning: !!!
Many thanks !!!

Hello,

This was just a quick look at this !
I have a lot of experience getting examples working. :)

Try this:

Arduino Code
void setup() 
  {
  Serial.begin(115200);
  }

void loop() 
  {
  // Print the temperature value of each pixel in floating point degrees Celsius
  // separated by commas

  float temp = 10.00; 
  for(unsigned char i = 0; i < 64; i++)
    { 
    //Serial.print(grideye.getPixelTemperature(i));
    Serial.print(temp, 2);
    Serial.print(",");
    temp += 0.25; 
    } 

  // End each frame with a linefeed
  Serial.println();

  // Give Processing time to chew
  delay(100);
  }
Processing Code
if(myPort.available() > 64)
    {
    myString = myPort.readStringUntil(13);
  
    // generate an array of strings that contains each of the comma
    // separated values
    //println(myString);
    
    if (myString != null)  
      {
      trim(myString);  
      String splitString[] = splitTokens(myString, ",");
      //printArray(splitString);
      if (splitString.length == 65) //65 for that last bit of data after the last ',' !
        {
    // for each of the 64 values, map the temperatures between 20C and 40C
    // to the blue through red portion of the color space
        for(int q = 0; q < 64; q++)
          {
          temps[q] = map(float(splitString[q]), 20, 40, 240, 360);
          }
        //printArray(temps);
        }  
      }
    }

Please take a close look at what I did.
I added a lot of checks!
I used trim to remove the linefeed (goes along for the ride from println()) before splitting it.
I added a lot of print statements to see what was being received; uncomment these to understand this.
The data length of spitString array is actually 65 because there is an empty string after the last ‘,’

Reference:
SparkFun_GridEYE_Arduino_Library/examples/Example4-ProcessingHeatCam at master · sparkfun/SparkFun_GridEYE_Arduino_Library · GitHub

image

That is a lot of zeroes!

//float[] temps =  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
float[] temps = new float [64];
printArray(temps);

:)

Dear glv,

Thank you so much for your help!!!
There were big advances with your comments!
Still there’s a problem of “NullPointerException” (don’t know why) , but it pops up the “HeatCam” anyway.
image

Maybe I should try with other laptop again.

I really appreciate for your help :slight_smile:
Have a great day and hope your happiness !!!

1 Like

Hi @SLEE, You still have the NullPointerException? I don’t know if the images from your first post are still valid now the program has changed, I’ll assume they are. (It’s usually better to post text so everyone can copy/paste/refer more easily.) In the console window the “[0]COM11” is fine, just the result of the printarray on line 59.

The NullPointerException is that the contents of myString is not valid for splitTokens. Maybe it is valid sometimes and not others depending on what comes from the Arduino. Suggest you put this line before that line and it will show you the length and content of the myString.


println(String.format(“myString Len=%d, Content=%s~”, myString.length(), myString));

The ~ is there so you see where the string finishes, including any spaces/cr/lf.

Dear glv and RichardDL,

Sorry for replying too late.
I tried again with the codes (Arduino example code + Processing code of glv) and it worked!!!
NullPointerException message wasn’t popped up anymore. Really really appreciate for you :slight_smile:
Thank you so much for your help :slight_smile:

Many thanks!!

1 Like