How to react to a variable i cant read

So this is some example code for the amg88xx thermal sensor, in it, there is a variable called “pixelInts” well I want to set up an if statement but I don’t know how to read the “pixelInts” variable.

If the output is set to BIN (default) then serial output looks like this:
**** interrupt received! ****
0
1000000
0
0
0
0
0
0

And if its set to DEC it looks like this:

**** interrupt received! ****
0
64
0
0
0
0
0
0

/***************************************************************************
This is a library for the AMG88xx GridEYE 8x8 IR camera

This sketch shows how to use the interrupt on the sensor.
it will print which pixels triggered the interrupt when one is received.

Designed specifically to work with the Adafruit AMG88 breakout
----> http://www.adafruit.com/products/3538

These sensors use I2C to communicate. The device’s I2C address is 0x69

Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing products
from Adafruit!

Written by Dean Miller for Adafruit Industries.
BSD license, all text above must be included in any redistribution
***************************************************************************/

#include <Wire.h>
#include <Adafruit_AMG88xx.h>

Adafruit_AMG88xx amg;

//INT pin from the sensor board goes to this pin on your microcontroller board
#define INT_PIN 3

//interrupt levels (in degrees C)
//any reading on any pixel above TEMP_INT_HIGH degrees C, or under TEMP_INT_LOW degrees C will trigger an interrupt
//30 degrees should trigger when you wave your hand in front of the sensor
#define TEMP_INT_HIGH 30
#define TEMP_INT_LOW 0

volatile bool intReceived = false;
uint8_t pixelInts[8];
/*******
we can tell which pixels triggered the interrupt by reading the
bits in this array of bytes. Any bit that is a 1 means that pixel triggered

bit 0 bit 1 bit 2 bit 3 bit 4 bit 5 bit 6 bit 7
byte 0 | 0 1 0 0 0 0 0 1
byte 1 | 0 0 0 0 0 0 0 0
byte 2 | 0 0 0 0 0 0 0 0
byte 3 | 0 0 0 1 0 0 0 0
byte 4 | 0 0 0 0 0 0 0 0
byte 5 | 0 0 0 0 0 0 0 0
byte 6 | 0 0 0 0 0 1 0 0
byte 7 | 0 0 0 0 0 0 0 0

*****/

void setup() {

pinMode(INT_PIN, INPUT);

Serial.begin(9600);
Serial.println(F(“AMG88xx interrupt test”));

bool status;

// default settings
status = amg.begin();
if (!status) {
Serial.println(“Could not find a valid AMG88xx sensor, check wiring!”);
while (1);
}

amg.setInterruptLevels(TEMP_INT_HIGH, TEMP_INT_LOW);

//set to absolue value mode
amg.setInterruptMode(AMG88xx_ABSOLUTE_VALUE);

//enable interrupts
amg.enableInterrupt();

//attach to our Interrupt Service Routine (ISR)
attachInterrupt(digitalPinToInterrupt(INT_PIN), AMG88xx_ISR, FALLING);

}

void loop() {

if(intReceived){
//get which pixels triggered
amg.getInterrupt(pixelInts);

Serial.println("**** interrupt received! **");
for(int i=0; i<8; i++){
Serial.println(pixelInts
, BIN);

  • }*

  • Serial.println();*

  • //clear the interrupt so we can get the next one!*

  • amg.clearInterrupt();*

  • intReceived = false;*

  • }*
    }
    void AMG88xx_ISR() {

  • //keep your ISR short!*

  • //we don’t really want to be reading from or writing to the sensor from inside here.*

  • intReceived = true;*
    }
    /quote]

This:

         bit 0  bit 1  bit 2  bit 3  bit 4  bit 5  bit 6  bit 7
byte 0 |  0      1      0      0      0      0      0      1
byte 1 |  0      0      0      0      0      0      0      0
byte 2 |  0      0      0      0      0      0      0      0
byte 3 |  0      0      0      1      0      0      0      0
byte 4 |  0      0      0      0      0      0      0      0
byte 5 |  0      0      0      0      0      0      0      0
byte 6 |  0      0      0      0      0      1      0      0
byte 7 |  0      0      0      0      0      0      0      0

tells you exactly what that data means - it is 8 bit-mapped bytes, with each bit representing on pixel.

Your sample data has the pixel represented by bit 6 of byte 1 set.

What more do you need to know?

Regards,
Ray L.

variable called "pixelInts" is not variable. It is an array of bytes, just as the comments in the sample code shows you. You access it just like any other array: pixelInts(0) or pixelInts(1) clear up to pixelInts(7).

Paul

pixelInts(0)

array?

Mark

The comments in your code say :

Any bit that is a 1 means that pixel triggered

bit 0 bit 1 bit 2 bit 3 bit 4 bit 5 bit 6 bit 7
byte 0 | 0 1 0 0 0 0 0 1
byte 1 | 0 0 0 0 0 0 0 0
byte 2 | 0 0 0 0 0 0 0 0
byte 3 | 0 0 0 1 0 0 0 0
byte 4 | 0 0 0 0 0 0 0 0
byte 5 | 0 0 0 0 0 0 0 0
byte 6 | 0 0 0 0 0 1 0 0
byte 7 | 0 0 0 0 0 0 0 0

You get

         bit 0  bit 1  bit 2  bit 3  bit 4  bit 5  bit 6  bit 7
byte 0 |  0      0      0      0      0      0      0      0
byte 1 |  0      0      0      0      0      0      0      1
byte 2 |  0      0      0      0      0      0      0      0
byte 3 |  0      0      0      0      0      0      0      0
byte 4 |  0      0      0      0      0      0      0      0
byte 5 |  0      0      0      0      0      0      0      0
byte 6 |  0      0      0      0      0      0      0      0
byte 7 |  0      0      0      0      0      0      0      0

So you know that pixel (1,7) triggered the interrupt

I think you should init the array in the beginning using

uint8_t pixelInts[8]={0};

and also reset all bits to zero in the loop so there is no ambiguity if you get several interrupts in different runs of the loop for(int i=0; i<8; i++) pixelInts[i]=0;(or maybe not because if an interrupt happens on a bit just before you reset it, you won’t see it. So the reset should be done when the interrupt is disabled.

I think this

    for(int i=0; i<8; i++){
      Serial.println(pixelInts, BIN);
    }

should be

    for(int i=0; i<8; i++){
      Serial.println(pixelInts[i], BIN);  // [i]
    }

but maybe it’s a trick coming from the fact that you used quote instead of code

So I need to set up an if statement so that something happens when to string contains a set of characters and only those characters. The problem I'm having is that the string is the output from a sensor and I don't know how to put it into my code.

The output comes out like this:

110000
0
0
0
0
0
0
0

and when I tried to write my code like this:

if(pixelInts=='110000','0','0','0','0','0','0','0')

the first term didn't turn blue and it triggerd no matter the output. What am I doing wrong?

What is the data type of pixelInts? There is no data type that can hold the value '110000','0','0','0','0','0','0','0'.

You need to check each line one at a time. Then if all the lines are correct, then do what you need to.

Search for the thread here on called "Serial Input basics". Read it. Try it and then repost your question.

This is not the way to do this. There are a few things wrong here.

The comma does not do what you seem to think that it does. The comma is an operator in C/C++ and should be avoided except to separate parameters in a function call, separate parameters in a function definition, separate elements in an array declaration, or to be used by an expert. I have probably missed a few places where a comma may be used safely, but the idea is to use commas only where you have been explicitly told to use them.

Single quotes only go around single characters. Unless your keyboard has a single key for 110000, DO NOT DO ‘110000’.

The proper way to compare C strings is by using the strcmp(…) function or one of its cousins. You may also have to learn about Finite State Machines, or at least do a better job of explaining your sensor and what it sends. A manufacturer’s name, a model number, and a link would be a start.

If this question is a follow up of http://forum.arduino.cc/index.php?topic=609782, you do not have a string but an array of bytes.

In that case you can use memcmp to compare the 8 bytes to a known pattern.

The code from the above thread

/***************************************************************************
  This is a library for the AMG88xx GridEYE 8x8 IR camera

  This sketch shows how to use the interrupt on the sensor.
  it will print which pixels triggered the interrupt when one is received.

  Designed specifically to work with the Adafruit AMG88 breakout
  ----> http://www.adafruit.com/products/3538

  These sensors use I2C to communicate. The device's I2C address is 0x69

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing products
  from Adafruit!

  Written by Dean Miller for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ***************************************************************************/

#include <Wire.h>
#include <Adafruit_AMG88xx.h>

Adafruit_AMG88xx amg;

//INT pin from the sensor board goes to this pin on your microcontroller board
#define INT_PIN 3

//interrupt levels (in degrees C)
//any reading on any pixel above TEMP_INT_HIGH degrees C, or under TEMP_INT_LOW degrees C will trigger an interrupt
//30 degrees should trigger when you wave your hand in front of the sensor
#define TEMP_INT_HIGH 30
#define TEMP_INT_LOW 0

volatile bool intReceived = false;
uint8_t pixelInts[8];
/******* 
we can tell which pixels triggered the interrupt by reading the
bits in this array of bytes. Any bit that is a 1 means that pixel triggered

         bit 0  bit 1  bit 2  bit 3  bit 4  bit 5  bit 6  bit 7
byte 0 |  0      1      0      0      0      0      0      1
byte 1 |  0      0      0      0      0      0      0      0
byte 2 |  0      0      0      0      0      0      0      0
byte 3 |  0      0      0      1      0      0      0      0
byte 4 |  0      0      0      0      0      0      0      0
byte 5 |  0      0      0      0      0      0      0      0
byte 6 |  0      0      0      0      0      1      0      0
byte 7 |  0      0      0      0      0      0      0      0

*****/

void setup() {

  pinMode(INT_PIN, INPUT);
  
  Serial.begin(9600);
  Serial.println(F("AMG88xx interrupt test"));

  bool status;
  
  // default settings
  status = amg.begin();
  if (!status) {
      Serial.println("Could not find a valid AMG88xx sensor, check wiring!");
      while (1);
  }
  
  amg.setInterruptLevels(TEMP_INT_HIGH, TEMP_INT_LOW);

  //set to absolue value mode
  amg.setInterruptMode(AMG88xx_ABSOLUTE_VALUE);

  //enable interrupts
  amg.enableInterrupt();

  //attach to our Interrupt Service Routine (ISR)
  attachInterrupt(digitalPinToInterrupt(INT_PIN), AMG88xx_ISR, FALLING);

}

void loop() {
  
  if(intReceived){
    //get which pixels triggered
    amg.getInterrupt(pixelInts);

    Serial.println("**** interrupt received! ****");
    for(int i=0; i<8; i++){
      Serial.println(pixelInts[i], BIN);
    }
    Serial.println();

    //clear the interrupt so we can get the next one!
    amg.clearInterrupt();
    
    intReceived = false;
  }
}

void AMG88xx_ISR() {
  //keep your ISR short!
  //we don't really want to be reading from or writing to the sensor from inside here.
  intReceived = true;
}

Adding a snippet

  Serial.println("**** interrupt received! ****");
  for (int i = 0; i < 8; i++) {
    Serial.println(pixelInts[i], BIN);
  }
  Serial.println();

  uint8_t pattern[8] = {0b00110000, 0, 0, 0, 0, 0, 0, 0};
  if (memcmp(pixelInts, pattern, sizeof(pattern)) == 0)
  {
    //it's a match
  }

The real problem here is that you don’t tell us exactly what you want. You have a sensor that outputs the array of bytes, but what information do you want from that? Is it the position of the pixels equal to 1?

In this case, you can use the bitRead() function

for (numByte = 0; numByte < 8; numByte++)
  for (numBit = 0; numBit < 8; numBit++)
     if (bitRead(pixelInts[numByte],numBit)) {
        Serial.print (numByte);
        Serial.print ("\t");
        Serial.println (numBit);
        }