Array im setup daten zuweisen

Hallo zusammen,

Viel Ahnung habe ich noch nicht - wie ihr gleich lesen werdet.
ich möchte ein Array, in diesem Fall "erlaubteKarten[]" von einer SD-Karte befüllen.
Ich bekomme es aber nicht hin, dieses Array im "Void Setup" einzurichten.

Kann mir da jemand einen Tipp geben??

#include <SoftwareSerial.h>

long erlaubteKarten[] = { 1011520, 222793, 4255477 };
byte erlaubteKartenCount = 3;


const int rfid_irq = 0;
const int rfid_tx_pin = 2;
// RX wird nicht benoetigt
const int rfid_rx_pin = 3;


int zaehler = 0;

SoftwareSerial rfid(rfid_tx_pin, rfid_rx_pin);

// Indicates that a reading is now ready for processing
volatile bool ready = false;

uint8_t buffer[14];
uint8_t* buffer_at;
uint8_t* buffer_end = buffer + sizeof(buffer);




void setup() {
 
 Serial.begin(9600);
 rfid.begin(9600);  // muss fest fuer das Modul auf 9600 stehen
 Serial.println("Starte RFID-Reader RDM6300 ");
 pinMode(rfid_tx_pin, INPUT);  // Oeffnet die serielle Verbindung zum RDM6300 Modul
 Serial.println("OK");
 attachInterrupt(rfid_irq, rfid_read, HIGH);
}



void loop() {
 if ( ready )  {
   long chip_nummer = 0;
   ++buffer_at;
   uint8_t checksum = rfid_get_next();
   int i = 4;
   while (i--)   {
     uint8_t value = rfid_get_next();
     chip_nummer <<= 8;
     chip_nummer |= value;
   }   //  ENDE while (i--) 



   zaehler++;

   if (PruefeKartenberechtigung(chip_nummer) == true  ) {
     zaehler++;
     if (zaehler >= 2) {    //  Chip Wert nach mehr als 2 IRQ sicher erkannt
       Serial.print(chip_nummer);
       Serial.println(F(" [BERECHTIGT]"));
       long chip_nummer = 0;
       zaehler = 0;
     }
   } else {
     if (zaehler >= 2) {   //  Chip Wert nach mehr als 2 IRQ sicher erkannt
       Serial.print(chip_nummer);
       Serial.println(F(" [NICHT BERECHTIGT]"));
       long chip_nummer = 0;
       zaehler = 0;
     }
   }

   ready = false;


 }   // ENDE  if ( ready )

}   // ENDE  void loop(void)




boolean PruefeKartenberechtigung(long KartenUUID) {
 boolean ready = false;

 for (int i = 0; i < erlaubteKartenCount; i++) {
   if (erlaubteKarten[i] == KartenUUID) {
     ready = true;
   }
 }
 return ready;
}





// Convert the next two chars in the stream into a byte and
// return that
uint8_t rfid_get_next(void)
{
 // sscanf needs a 2-byte space to put the chip_nummer but we
 // only need one byte.
 uint16_t chip_nummer;

 // Working space to assemble each byte
 static char byte_chars[3];

 // Pull out one byte from this position in the stream
 snprintf(byte_chars, 3, "%c%c", buffer_at[0], buffer_at[1]);
 sscanf(byte_chars, "%x", &chip_nummer);
 buffer_at += 2;

 return static_cast<uint8_t>(chip_nummer);
}






void rfid_read() {

 if ( ! ready  )   {



   // Read characters into the buffer until it is full
   buffer_at = buffer;

   while ( buffer_at < buffer_end )
     *buffer_at++ = rfid.read();

   // Reset buffer pointer so it's easy to read out
   buffer_at = buffer;

   // Signal that the buffer has data ready
   ready = true;
 }

}

https://github.com/greiman/SdFat/tree/master/SdFat/examples/ReadCsvArray

The source code probably did not have italics in it.

Please use English on this forum! I want to help but I do not know German.
If you must post in German, use the German forum.

To post code and/or error messages:

  1. Use CTRL-T in the Arduino IDE to autoformat your complete code.
  2. Paste the complete autoformatted code between code tags (the </> button)
    so that we can easily see and deal with your code.
  3. Paste the complete error message between code tags (the </> button)
    so that we can easily see and deal with your messages.
  4. If you already posted without code tags, you may add the code tags by
    editing your post. Do not change your existing posts in any other way.
    You may make additional posts as needed.

Before posting again, you should read the three locked topics at the top of the Programming Questions forum, and any links to which these posts point.

If your project involves wiring, please provide a schematic and/or a wiring diagram and/or a clear photograph of the wiring.

Good Luck!

Torsten_OL:
Kann mir da jemand einen Tipp geben??

Bevor Du einem statischen Array Dateninhalte zuweisen kannst, müßtest Du erstmal die Größe des Arrays festlegen. Also für maximal 256 Karten zum Beispiel ein Array mit 256 Elementen;

long erlaubteKarten[256];

Dann wäre aber gleich schon mal das erste von zwei Kilobytes RAM-Speicher eines UNO belegt.

Wieviele Kartennummern möchtest Du denn insgesamt verwalten?

Bei 4 Bytes pro Kartennummer 'long' würden auf eine 4GB SD-Karte bis zu eine Milliarde(!) Kartennummern passsen. Ist es realistisch, dass Du so viele Kartennummern brauchst? Oder ist 256 Kartennummern realistischer als eine Milliarde Kartennummern?

Torsten_OL:

long erlaubteKarten[] = { 1011520, 222793, 4255477 };

byte erlaubteKartenCount = 3;

Ich würde das so ändern:

const byte erlaubteKartenCount = 3;
long erlaubteKarten[erlaubteKartenCount] = { 1011520, 222793, 4255477 };

Für das Lesen von einer SD Karte dürfen dann nur erlaubteKartenCount IDs gelesen und gespeichert werden. Soll die Anzahl variabel sein, muß das Array ggf. größer dimensioniert werden, und die Anzahl der tatsächlich gültigen IDs muß ebenfalls von der Karte geladen werden.