Mehrere Module an Arduino Nano gleichzeitig anschließen

Einen Level shifter von 5 auf 3,3V.
Grüße Uwe

Also habe es ausprobiert und den RST mit 3.3V verbunden, das geht leider nicht.

Sobald der SD reader angeschlossen ist, funktioniert der rfid reader nicht mehr. Stecke ich die Kabel vom sd reader aus geht der rfid reader wieder. Die sd karte geht allerdings, auch wenn der rfid reader dranhängt

wäre das hier die Lösung?

https://funduinoshop.com/elektronische-module/wireless-iot/rfid-nfc/pn532-nfc-rfid-v3-modul-fuer-arduino-und-co.

scheint ja auch i2c und UART anzusprechen.

Nimm einen pn532 den kannste auch per i2c oder sofware spi verbinden, das funktioniert an einem nano, uno oder mega einwandfrei. Nur an einem esp32 macht ein pn532 an i2c probleme.

Wenn ich dann mehrere Module (RFID, SD, RTC) dranhänge, ist dann UART oder i2c besser?

Also eine sd Karte mit i2c kenne ich nicht, da bleibt dir nur spi. Rtc und rfid können dann aber beide an i2c.

Okay super, ja der SPI ist ja dann frei für die SD Karte.
Gibt es irgendwelche vor oder Nachteile von UART / I2C?

Uart ist langsamer und irgendwo habe ich mal gelesen das bestimmte sachen / karten beim pn532 an uart nicht funktionieren.

Habs gefunden "In the case of High-Speed UART mode, the chip was only able to read data with 4 bytes. The module fails in reading 7 bytes of data from NFC Cards." Nachzulesen hier Link

Vielen Dank, dann warte ich, dass der neue RFID reader ankommt und teste es so :smiley:

Den wahrscheinlichsten Grund dafür hatte ich dir schon genannt, also nochmal:

Ob du so einen hast, kann ich nur aus der Symptomatik ableiten,
einen Link zu deinem Adapter habe ich nicht gefunden, oder übersehen.

3.3V SPI Geräte an einem 5V Arduino benötigen Level-Shifter.
Leider hat der auf den üblichen SD Adaptern verbaute Shifter das Problem MISO nicht freizugeben.

Abhilfe könnte ein kompatibler SD Adapter oder eine Änderung an dem vorhandenen bringen,
neben der 5V 3.3V Umsetzung für den RFID Leser.

Alternativ könntest du einen 3.3V Arduino und eine SD Halterung ohne Level-Shifter benutzen,
da alle Module dann 3.3V benutzen brauchst du keine Level-Shifter.

Okay, ich hatte es auf die generelle Funktion des SD Reader bezogen. Der ist von Catalex, ist auch schon älter. Da ich so viel positives über den Pn532 gelesen habe, probiere ich es mit dem, falls das nicht geht werde ich einen anderen SD reader bestellen. Vielen Dank :slight_smile:

#include <SPI.h>
#include <MFRC522.h>
#include <SD.h>

#define RST_PIN         9           // Configurable, see typical pin layout above
#define SS_PIN          6          // Configurable, see typical pin layout above
#define SD_CS_PIN          10          // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.

MFRC522::MIFARE_Key key;

File Textdatei;
int lesen = 1; 
/**
 * Initialize.
 */
void setup() {

  if (!SD.begin(10)) {                                     // Wenn die SD-Karte nicht (!SD.begin) gefunden werden kann, ...
    Serial.println("Initialisierung fehlgeschlagen!");    // ... soll eine Fehlermeldung ausgegeben werden. ....
    // return;
  }
  
  digitalWrite(SD_CS_PIN, LOW);   
  digitalWrite(SS_PIN, HIGH);   

    Serial.begin(9600); // Initialize serial communications with the PC
    while (!Serial);    // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
    digitalWrite(SD_CS_PIN, HIGH);   
  digitalWrite(SS_PIN, LOW);   
    SPI.begin();        // Init SPI bus
    mfrc522.PCD_Init(); // Init MFRC522 card
   
   
    // Prepare the key (used both as key A and as key B)
    // using FFFFFFFFFFFFh which is the default at chip delivery from the factory
    for (byte i = 0; i < 6; i++) {
        key.keyByte[i] = 0xFF;
    }

    Serial.println(F("Scan a MIFARE Classic PICC to demonstrate read and write."));
    Serial.print(F("Using key (for A and B):"));
    dump_byte_array(key.keyByte, MFRC522::MF_KEY_SIZE);
    Serial.println();

    Serial.println(F("BEWARE: Data will be written to the PICC, in sector #1"));
}

/**
 * Main loop.
 */

DAS funktioniert bei mir. Ist der Code-Teil bis zum VOID LOOP.

Gruß

Pucki

Warum Schreibst Du ewig Groß dort wo man nicht Sollte? Man kann das auch anders Betonen, man sollte im Forum (im Keinem) nicht Brüllen.

Ich habe jetzt alles angeschlossen und er läuft super, aktuell über UART, da die Pins frei sind.
Kennt sich jemand aus mit dem Auslesen von Textdatein, die auf nfc stickern geschrieben werden?

Habe da nur diesen code gefunden:

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_PN532.h>

// If using the breakout or shield with I2C, define just the pins connected
// to the IRQ and reset lines.  Use the values below (2, 3) for the shield!
#define PN532_IRQ   (2)
#define PN532_RESET (3)  // Not connected by default on the NFC Shield

// Use this line for a breakout or shield with an I2C connection:
Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);

//** snippet of code below added to force the serial to print text from the NFC tag
// on one line. Modification of the PrintHexChar function **

#define PN532DEBUGPRINT Serial
#define result String // string that will be output in the Serial window

char newChar = "";

String result = "";

void printHexCharAsOneLine(const byte *data, const uint32_t numBytes) {
  uint32_t szPos;
  for (szPos = 0; szPos < numBytes; szPos++) {
    if (data[szPos] <= 0x1F)
      PN532DEBUGPRINT.print(F(""));
    else if (data[szPos] == 0XFE)
      PN532DEBUGPRINT.print(F(""));
    else {
      PN532DEBUGPRINT.print((char)data[szPos]);
      newChar = ((char)data[szPos]); //makes the character into a variable
      result += newChar; //adds that character to the result string
      
    }
  }
}



void setup(void) {
  Serial.begin(115200);
  while (!Serial) delay(10); // for Leonardo/Micro/Zero

  Serial.println("Hello!");

  nfc.begin();

  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1); // halt
  }
  // Got ok data, print it out!
  Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
  Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
  Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
 
  // configure board to read RFID tags
  nfc.SAMConfig();
 
  Serial.println("Waiting for an ISO14443A Card ...");
}

void loop(void) {
  uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
  uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
   
  // Wait for an NTAG203 card.  When one is found 'uid' will be populated with
  // the UID, and uidLength will indicate the size of the UUID (normally 7)
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
 
  if (success) {
    // Display some basic information about the card
    Serial.println("Found an ISO14443A card");
    Serial.print("  UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
    Serial.print("  UID Value: ");
    nfc.PrintHex(uid, uidLength);
    Serial.println("");
   
    if (uidLength == 7)
    {
      uint8_t data[32];
     
      // We probably have an NTAG2xx card (though it could be Ultralight as well)
      Serial.println("Seems to be an NTAG2xx tag (7 byte UID)");      

      for (uint8_t i = 7; i < 42; i++) // starting serial output at Page 7 and stop reading at Page 42
      {
        success = nfc.ntag2xx_ReadPage(i, data);

        // Display the results, depending on 'success'
        if (success)
        {
          // Dump the page data
          printHexCharAsOneLine(data,4);
        }
        else
        {
          Serial.println("Unable to read the requested page!");
        }
      }

        Serial.println ();
        Serial.println("beep boop the result is: " + result);
        result = "";  // resets the string to empty
    }
    else
    {
      Serial.println("This doesn't seem to be an NTAG203 tag (UUID length != 7 bytes)!");
    }
        
   
    // Wait a bit before trying again
    Serial.println("\n\nSend a character to scan another tag!");
    Serial.flush();
    while (!Serial.available());
    while (Serial.available()) {
    Serial.read();
    }
    Serial.flush();   
  }
}
Bei mir kommt folgende Fehlermeldung: 

Hello!

12:24:35.977 -> Didn't find PN53x board

Ich habe es auch per i2c probiert mit folgendem code:

#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>
PN532_I2C pn532_i2c(Wire);
NfcAdapter nfc = NfcAdapter(pn532_i2c);
String tagId = "None";
byte nuidPICC[4];
 
void setup(void) 
{
 Serial.begin(115200);
 Serial.println("System initialized");
 nfc.begin();
}
 
void loop() 
{
 readNFC();
}
 
void readNFC() 
{
 if (nfc.tagPresent())
 {
   NfcTag tag = nfc.read();
   tag.print();
   tagId = tag.getUidString();
 }
 delay(5000);
}

Leider passiert außer system initaliezed nichts.

Liegt es dann an den Kabeln/Anschlüssen? ist an A4 und A5 angeschlossen

Da fehlt dann die Info, wie du es angeschlossen hast.
Soweit ist A4 und A5 richtig.
Und du musst das Ergebnis ja auch am seriellen Monitor anzeigen.

Er war tatsächlich richtig angeschlossen, nur der schalter für i2c war nicht umgelegt. Vielen Dank für alle Hilfe :smiley:

Gibt es nicht wirklich.

Ausgelesen werde die RFID-Chips in Blöcken.

Die Anzahl und Größe der Blöcke werden durch den Chip und auch seine Bauart bestimmt.

In der Demo des PN532 stehen einige Blockbeschreibungen drin.
WICHTIG. Beginne IMMER mit den Schreiben ab Block 4.
Ich habe mal in einen kleinen Block geschrieben und den Chip war so Schrott, das ihn nicht einmal mein Handy erkannt, und auch nicht formatiert hat.

Ich habe auf mein Android-Handy die NFC-Tools (Icon = oranger Hintergrund, mit Handy in der Mitte und 2 Wellen zu jeder Seite). Nehme einfach ein Chip, beschreibe ihn mit dem Handy und schaue welche Codes, der für was schreibt.)

Bei meinem Projekt brauchte ich sowas nicht. Da habe ich einfach in den 4. Block die Infos geschrieben, die ich wollte. Und gut ist.

Gruß

Pucki

Okay ja das habe ich noch auf dem Schirm. Habe das auslesen mit dem Beispiel hinbekommen :smiley: