Add to 2d array if not exists

I save all 12 value in the uint8_t singleTagEPCBytes[12]

singleTagEPCBytes [p] = ((uint8_t) nano.msg[31 + p]);
       
        if((p == tagEPCByteCount) && (counter > 0)) {
          find (singleTagEPCBytes, tagEPCBytes); }

nano.msg is a buffer. It is defined as: uint8_t msg[MAX_MSG_SIZE]. I try to find singleTagEPCBytes in the array tagEPCBytes with the following function.

int find(uint8_t *x[], uint8_t *y[][12])
{
    int i, j;

    for (i = 0; i < 3; i++) {
        for (j = 0; j < 12; j++) {
            if (x[j] != y[i][j]) break;
            if ( j == 11) {
                Serial.print("exists in row %d\n", i);
                return 0;
            }
        }
    }
    Serial.print("does not exists\n");
    return 1;
}

But I get the following error message

cannot convert 'uint8_t* {aka unsigned char*}' to 'uint8_t** {aka unsigned char**}' for argument '1' to 'int find(uint8_t**, uint8_t* (*)[12])'

           find (singleTagEPCBytes, tagEPCBytes); }

I tried this function successfully here GDB online Debugger | Code, Compile, Run, Debug online C, C++

I thought that with singleTagEPCBytes[p] = ((uint8_t) nano.msg[31 + p]); I saved the values from nano.msg as uint8_t.

  1. Who can explain why the find function does not work.
  2. What would be the best way to add a row in tagEPCBytes if singleTagEPCBytes was not found.

Another error I get is this

call of overloaded 'print(const char [18], int&)' is ambiguous

                 Serial.print("exists in row %d\n", i);
  1. Why is overloaded 'print(const char [18], int&)' ambiguous

Enclosed the full code

#include <SoftwareSerial.h> 
#include <stddef.h>

SoftwareSerial softSerial(2, 3); 

#include "SparkFun_UHF_RFID_Reader.h" 
RFID nano; 

#define BUZZER1 10

#define BUZZER2 9

boolean tagDetected; 
long lastSeen = 0; 
int counter = 0; 

void setup()
{
  Serial.begin(115200);

  pinMode(BUZZER1, OUTPUT);
  pinMode(BUZZER2, OUTPUT);

  digitalWrite(BUZZER2, LOW); 

  while (!Serial); 

  if (setupNano(38400) == false) 
  {
    Serial.println(F("Das Modul hat nicht reagiert. Bitte überprüfen Sie die Anschlüsse."));
    while (1); 
  }

  nano.setRegion(REGION_NORTHAMERICA); 

  
  nano.setReadPower(2700); 
  

  nano.startReading(); 

  Serial.println("Scannprozess läuft!");

  lowBeep(); 
  tagDetected = false;  
}

void loop()
{
  byte myEPC[12]; 
  byte myEPClength;
  byte responseType = 0;
  
  uint8_t tagEPCBytes[50][12] = {};
  uint8_t singleTagEPCBytes[12] = {};


  if (nano.check() == true) 
  {
    byte responseType = nano.parseResponse(); 

    if (responseType == RESPONSE_IS_TAGFOUND)
    {
      long timeStamp = nano.getTagTimestamp(); 
      byte tagEPCByteCount = nano.getTagEPCBytes(); 

      Serial.print(F("RFID-Tag detektiert: "));
      Serial.println(counter); 


      
      Serial.print(F("Bin-Daten["));
      for (byte p = 0 ; p < tagEPCByteCount ; p++)
      {
        tagEPCBytes[counter][p] = ((uint8_t) nano.msg[31 + p]);
        singleTagEPCBytes [p] = ((uint8_t) nano.msg[31 + p]);
        
        if(p == tagEPCByteCount) { 
          find (singleTagEPCBytes, tagEPCBytes); }
        
        Serial.print(nano.msg[31 + p]);
        if (p != 11) Serial.print(F(" "));
      }
      Serial.println(F("] "));

      if (tagDetected == false) 
      {
        tagDetected = true;
        
      }
      else if (millis() - lastSeen > 250) 
      {
        
      }
      lastSeen = millis();

      counter++;
    }
  }

  if (tagDetected == true && (millis() - lastSeen) > 1000)
  {
    Serial.println(F("Kein RFID-Tag gefunden..."));

    tagDetected = false;
    
  }

  
  if (Serial.available())
  {
    nano.stopReading(); 
    Serial.read(); 
    
    delay(1000);
    
    Serial.println("Array Ausgabe:\n");
    delay(333);
    int i, j;    
    for (i = 0; i < 50; i++) {
      for (j = 0; j < 12; j++) {
        Serial.print(tagEPCBytes[i][j]);
        Serial.print(" ");
        if (j == 11) {
          Serial.println(" ");
        }
      }
    }
    delay(333);
    Serial.println("Scannen angehalten. Drücken Sie die Taste, um fortzufahren.");

    while (!Serial.available());
    Serial.read(); 

    nano.startReading(); 
  }
}



boolean setupNano(long baudRate)
{
  nano.begin(softSerial); 

  

  
  
  softSerial.begin(baudRate); 
  while (!softSerial); 

  
  while (softSerial.available()) softSerial.read();

  nano.getVersion();

  if (nano.msg[0] == ERROR_WRONG_OPCODE_RESPONSE)
  {
    
    nano.stopReading();

    Serial.println(F("Modul liest kontinuierlich. Modul soll kontinuierlich lesen beenden...."));

    delay(1500);
  }
  else
  {
    
    softSerial.begin(115200); 

    nano.setBaud(baudRate); 

    softSerial.begin(baudRate); 
  }

  
  nano.getVersion();
  if (nano.msg[0] != ALL_GOOD) return (false); 

  
  nano.setTagProtocol(); 

  nano.setAntennaPort(); 

  return (true); 
}

void lowBeep()
{
  tone(BUZZER1, 130, 150); 
  
}

void highBeep()
{
  tone(BUZZER1, 2093, 150); 
  
}

int find(uint8_t *x[], uint8_t *y[][12])
{
    int i, j;

    for (i = 0; i < 3; i++) {
        for (j = 0; j < 12; j++) {
            if (x[j] != y[i][j]) break;
            if ( j == 11) {
                Serial.print("exists in row %d\n", i);
                return 0;
            }
        }
    }
    Serial.print("does not exists\n");
    return 1;
}

uint8_t *x[] is an array of pointers (i.e. uint8_t **x). Remove the asterisk. Idem for y.

Serial.print doesn't use format strings. You're confusing it with Serial.printf (which is not supported on AVR).

Pieter

PieterP:
uint8_t *x[] is an array of pointers (i.e. uint8_t **x). Remove the asterisk. Idem for y.

Serial.print doesn't use format strings. You're confusing it with Serial.printf (which is not supported on AVR).

Pieter

Thanks for the advice. I changed the source code as follows

#include <SoftwareSerial.h> 
#include <stddef.h>

SoftwareSerial softSerial(2, 3); 

#include "SparkFun_UHF_RFID_Reader.h" 
RFID nano; 

#define BUZZER1 10

#define BUZZER2 9

boolean tagDetected; 
long lastSeen = 0; 
int counter = 0; 

void setup()
{
  Serial.begin(115200);

  pinMode(BUZZER1, OUTPUT);
  pinMode(BUZZER2, OUTPUT);

  digitalWrite(BUZZER2, LOW); 

  while (!Serial); 

  if (setupNano(38400) == false) 
  {
    Serial.println(F("Das Modul hat nicht reagiert. Bitte überprüfen Sie die Anschlüsse."));
    while (1); 
  }

  nano.setRegion(REGION_NORTHAMERICA); 

  
  nano.setReadPower(2700); 
  

  nano.startReading(); 

  Serial.println("Scannprozess läuft!");

  lowBeep(); 
  tagDetected = false;  
}

void loop()
{
  byte myEPC[12]; 
  byte myEPClength;
  byte responseType = 0;
  
  uint8_t tagEPCBytes[50][12] = {};
  uint8_t singleTagEPCBytes[12] = {};


  if (nano.check() == true) 
  {
    byte responseType = nano.parseResponse(); 

    if (responseType == RESPONSE_IS_TAGFOUND)
    {
      long timeStamp = nano.getTagTimestamp(); 
      byte tagEPCByteCount = nano.getTagEPCBytes(); 

      Serial.print(F("RFID-Tag detektiert: "));
      Serial.println(counter); 


      
      Serial.print(F("Bin-Daten["));
      for (byte p = 0 ; p < tagEPCByteCount ; p++)
      {
        tagEPCBytes[counter][p] = ((uint8_t) nano.msg[31 + p]);
        singleTagEPCBytes [p] = ((uint8_t) nano.msg[31 + p]);
        
        if(p == tagEPCByteCount) { 
          find (singleTagEPCBytes, tagEPCBytes); }
        
        Serial.print(nano.msg[31 + p]);
        if (p != 11) Serial.print(F(" "));
      }
      Serial.println(F("] "));

      if (tagDetected == false) 
      {
        tagDetected = true;
        
      }
      else if (millis() - lastSeen > 250) 
      {
        
      }
      lastSeen = millis();

      counter++;
    }
  }

  if (tagDetected == true && (millis() - lastSeen) > 1000)
  {
    Serial.println(F("Kein RFID-Tag gefunden..."));

    tagDetected = false;
    
  }

  
  if (Serial.available())
  {
    nano.stopReading(); 
    Serial.read(); 
    
    delay(1000);
    
    Serial.println("Array Ausgabe:\n");
    delay(333);
    int i, j;    
    for (i = 0; i < 50; i++) {
      for (j = 0; j < 12; j++) {
        Serial.print(tagEPCBytes[i][j]);
        Serial.print(" ");
        if (j == 11) {
          Serial.println(" ");
        }
      }
    }
    delay(333);
    Serial.println("Scannen angehalten. Drücken Sie die Taste, um fortzufahren.");

    while (!Serial.available());
    Serial.read(); 

    nano.startReading(); 
  }
}



boolean setupNano(long baudRate)
{
  nano.begin(softSerial); 

  

  
  
  softSerial.begin(baudRate); 
  while (!softSerial); 

  
  while (softSerial.available()) softSerial.read();

  nano.getVersion();

  if (nano.msg[0] == ERROR_WRONG_OPCODE_RESPONSE)
  {
    
    nano.stopReading();

    Serial.println(F("Modul liest kontinuierlich. Modul soll kontinuierlich lesen beenden...."));

    delay(1500);
  }
  else
  {
    
    softSerial.begin(115200); 

    nano.setBaud(baudRate); 

    softSerial.begin(baudRate); 
  }

  
  nano.getVersion();
  if (nano.msg[0] != ALL_GOOD) return (false); 

  
  nano.setTagProtocol(); 

  nano.setAntennaPort(); 

  return (true); 
}

void lowBeep()
{
  tone(BUZZER1, 130, 150); 
  
}

void highBeep()
{
  tone(BUZZER1, 2093, 150); 
  
}

int find(uint8_t x[], uint8_t y[][12])
{
    int i, j;

    for (i = 0; i < 3; i++) {
        for (j = 0; j < 12; j++) {
            if (x[j] != y[i][j]) break;
            if ( j == 11) {
                Serial.print ("exists in row ");
                Serial.println (i);
                return 0;
            }
        }
    }
    Serial.println ("does not exists\n");
    return 1;
}

What would be the best way to add a row in tagEPCBytes if singleTagEPCBytes was not found?

You can't add new rows to an array. You can, however, fill up 'empty' rows.

                 Serial.print("exists in row %d\n", i);

Serial.print() doesn't work like printf(), and you can't give it multiple things to print.
"Ambiguous" isn't a very accurate as an error message - There's no matching function signature...

singleTagEPCBytes [p] = ((uint8_t) nano.msg[31 + p]);

You shouldn't need the cast in there (nano.msg is already uint8_t) If it complaining without the cast, you have something else wrong.

Here is the solution to my question, thanks to all those who helped me to find the solution.

the following source code shows that the values in uint8_t *a[12] are already contained in *b[4][12] and therefore no new row in *b[4][12] is added.
Working example: GDB online Debugger | Code, Compile, Run, Debug online C, C++

#include <stdio.h>
#include <stdint.h>


int main() {
    uint8_t *a[12] = {221, 0, 0, 23, 34, 10, 0, 113, 20, 112, 127, 223};
    uint8_t *b[4][12] = {{221, 0, 0, 23, 34, 10, 0, 113, 20, 112, 127, 223},
                        {222, 0, 0, 23, 34, 10, 13, 113, 20, 112, 127, 223},
                        {223, 0, 12, 23, 34, 10, 0, 113, 20, 112, 127, 223}};
    if(findArrayRow (a,b) == 0)
    {
        int j = findEmptyArrayRow (a,b);
        if( j > 0) addRowToArray(j,a,b);
    }
    displayNumbers(b);
}

int findArrayRow(uint8_t *x[], uint8_t *y[][12])
{
    int i, j;

    for (i = 0; i < 4; i++) {
        for (j = 0; j < 12; j++) {
            if (x[j] != y[i][j]) break;
            if ( j == 11) {
                printf("exists in row %d\n", i);
                return 1;
            }
        }
    }
    printf("does not exists\n");
    return 0;
}

int findEmptyArrayRow(uint8_t *x[], uint8_t *y[][12])
{
    int i, j;

    for (i = 0; i < 4; i++) {
        for (j = 0; j < 12; j++) {
            if (y[i][j] != 0) break;
            if ( j == 11) {
                printf("Empty row is %d\n", i);
                return i;
            }
        }
    }
    printf("does not exists\n");
}

void addRowToArray(int d, uint8_t *x[], uint8_t *y[][12])
{
    int j;
    for (j = 0; j < 12; j++)
        {
            y[d][j] = x[j];
        }
}

void displayNumbers(uint8_t *num[][12])
{
    int i, j;
    printf("Displaying:\n");
    for (i = 0; i < 4; i++)
    {
        for (j = 0; j < 12; j++)
        {
            printf("%d ", num[i][j]);
        }
        printf("\n");
    }
}

below code shows that a new Tag is found.

the following source code shows that the values in uint8_t *a[12] are NOT contained in *b[4][12] and thus a new line in *b[4][12] is added
Working example: GDB online Debugger | Code, Compile, Run, Debug online C, C++

#include <stdio.h>
#include <stdint.h>


int main() {
    uint8_t *a[12] = {226, 0, 0, 23, 34, 10, 0, 113, 20, 112, 127, 224};
    uint8_t *b[5][12] = {{226, 0, 0, 23, 34, 10, 0, 113, 20, 112, 127, 223},
                        {226, 0, 0, 23, 34, 10, 0, 55, 20, 112, 127, 158},
                        {226, 0, 0, 23, 34, 10, 0, 57, 20, 112, 127, 159},
                        {226, 0, 0, 23, 34, 10, 0, 81, 20, 112, 127, 189}};
    if(findArrayRow (a,b) == 0)
    {
        int j = findEmptyArrayRow (a,b);
        if( j > 0) addRowToArray(j,a,b);
    }
    displayNumbers(b);
}

int findArrayRow(uint8_t *x[], uint8_t *y[][12])
{
    int i, j;

    for (i = 0; i < 5; i++) {
        for (j = 0; j < 12; j++) {
            if (x[j] != y[i][j]) break;
            if ( j == 11) {
                printf("exists in row %d\n", i);
                return 1;
            }
        }
    }
    printf("does not exists\n");
    return 0;
}

int findEmptyArrayRow(uint8_t *x[], uint8_t *y[][12])
{
    int i, j;

    for (i = 0; i < 5; i++) {
        for (j = 0; j < 12; j++) {
            if (y[i][j] != 0) break;
            if ( j == 11) {
                printf("Empty row is %d\n", i);
                return i;
            }
        }
    }
    printf("does not exists\n");
}

void addRowToArray(int d, uint8_t *x[], uint8_t *y[][12])
{
    int j;
    for (j = 0; j < 12; j++)
        {
            y[d][j] = x[j];
        }
}

void displayNumbers(uint8_t *num[][12])
{
    int i, j;
    printf("Displaying:\n");
    for (i = 0; i < 5; i++)
    {
        for (j = 0; j < 12; j++)
        {
            printf("%d ", num[i][j]);
        }
        printf("\n");
    }
}