Seeeduino Xiao for RFID access control (RC522 reader)

Hi, did you manage to get the Rc522 working with the Xiao? I am trying but not getting any result.

I have this setup running here with no problems

Hi it is the Beaver here, I too have tried to use mt seeeduino XIAO )SAMD21) with a RF card reader, MF522,a 128x32 OLED, and D! as output. it sort of works but I an not a coder and sruggling to get the LED to remain on whilt the RFID card is present. and to only turn off 1 second after the card is removed. I plan to have a switch circuit ( using a relay to a contactor with appropriate circutry) to only supply powe if user is regestered as a user.

You probably need to use the XIAO Nrf52 version

image

It has NFC antenna connection on the bottom

thank you for prompt reply, I’m helping a maker space get up and running locally and thought this was innovative and cost efficient, The SAMD21 is doing what I want but the problem is the code, I tried circuit python, but it seems I should stay with Arduino IDE. as a basic start to get us running quickly. To stop everybody jumping on the Laser or the Lathe. I thought this was a smart move and within my budget. I got everything to work,Readed, 128x32 OLED and LED. just using the UID but the reader does not see the card is still there… it must see when th card is removed to shut down… and then shuts the LED with card on, after 2 seconds… it shts LED off. been struggling a ;ot as Code is not easy for me but I am trying. I was not raised in this coding world.Thank you for your support, and have a great day I am very new to a Forum this is my first attempt…

welcome… me and pjGlasso (monkey face) usually keep an eye on the forum among others so keep us up to date, if you want to share your code here or pm we can take a look at it… I am also an amiture programmrer… PS somewhere is a post that says you have to add some type of resistor or something to make the antenna work on the XIAO Nrf52… i will look and see if i can find it

PS post some pictures of your setup

FYI

Hi there,
Post the code you are using.
We can look, a picture of the circuit or setup would also speed the process up.
HTH
GL :slight_smile: PJ

1 Like

//this is rev 30 but problem with LED not remaining on during card present

#include <SPI.h>

#include <Wire.h>

#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>

#include <MFRC522.h>

// OLED display configuration

#define SCREEN_WIDTH 128 // OLED display width, in pixels

#define SCREEN_HEIGHT 32 // OLED display height, in pixels

#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// RFID reader configuration

#define SS_PIN 3

#define RST_PIN 2

MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance

// Pin configuration

const int whiteLED = 1;

const int cardAuthDelay = 2000; // 2 seconds delay after card removal

String authorisedCard = “61877DEE”; // Replace with your card ID

void setup() {

pinMode(whiteLED, OUTPUT);

digitalWrite(whiteLED, LOW);

Serial.begin(9600); // Initialize serial communications

SPI.begin(); // Init SPI bus

mfrc522.PCD_Init(); // Init MFRC522

delay(100);

// Initialize OLED display with the I2C address (0x3C is common)

if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {

Serial.println(F("SSD1306 allocation failed"));

for(;;);

}

display.display();

delay(2000);

display.clearDisplay();

display.setTextSize(1);

display.setTextColor(SSD1306_WHITE);

display.setCursor(0, 0);

display.print(“Scan your card”);

display.display();

}

void loop() {

// Look for new cards

if (!mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) {

delay(50);

return;

}

String cardID = “”;

for (byte i = 0; i < mfrc522.uid.size; i++) {

cardID += String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : "");

cardID += String(mfrc522.uid.uidByte[i], HEX);

}

cardID.toUpperCase();

Serial.println(cardID);

display.clearDisplay();

display.setCursor(0, 0);

if (cardID == authorisedCard) {

display.print("Authorised");

digitalWrite(whiteLED, HIGH);

display.display();

// Wait for the card to be removed

while (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {

  delay(50);

}

// Hold the LED on for an additional 2 seconds

//delay(cardAuthDelay); // theo commented out

digitalWrite(whiteLED, LOW);

} else {

display.print("Unauthorised");

display.setCursor(0, 10);

display.print("Speak to Theo");

display.display();

delay(2000);

}

display.clearDisplay();

display.setCursor(0, 0);

display.print(“Scan your card”);

display.display();

mfrc522.PICC_HaltA();

}

Hi I have a .jpg circuit, but not sure not to send this.I am new to forums this is my first attempt.

just cut and paste or screen print and paste into comments

consider cutting your code into sub-routines and call them as functions in your master code

write your code to iterrupt when new rf is detected, set led, process authentication… approve authentication… flash led and end authincation loop

Hi there,
first thing is you need to use the code tags above " </> "
paste it in there for it to look correct. Second whenever there’s a copy and paste from Internet examples the “xxx” quote marks are not ansi compatible, so errors will show up.
Here it is correctly posted.

//this is rev 30 but problem with LED not remaining on during card present

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <MFRC522.h>
// OLED display configuration
#define SCREEN_WIDTH 128  // OLED display width, in pixels
#define SCREEN_HEIGHT 32  // OLED display height, in pixels
#define OLED_RESET -1  // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// RFID reader configuration
#define SS_PIN 3
#define RST_PIN 2
MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance
// Pin configuration
const int whiteLED = 1;
const int cardAuthDelay = 2000;  // 2 seconds delay after card removal
String authorisedCard = "61877DEE";  // Replace with your card ID
void setup() {
  pinMode(whiteLED, OUTPUT);
  digitalWrite(whiteLED, LOW);
  Serial.begin(9600);  // Initialize serial communications
  SPI.begin();  // Init SPI bus
  mfrc522.PCD_Init();  // Init MFRC522
  delay(100);
  // Initialize OLED display with the I2C address (0x3C is common)
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;)
      ;
  }
  display.display();
  delay(2000);
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.print("Scan your card");
  display.display();
}

void loop() {
  // Look for new cards
  if (!mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) {
    delay(50);
    return;
  }
  String cardID = "";
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    cardID += String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : "");
    cardID += String(mfrc522.uid.uidByte[i], HEX);
 }
  cardID.toUpperCase();
  Serial.println(cardID);
  display.clearDisplay();
  display.setCursor(0, 0);
  if (cardID == authorisedCard) {
    display.print("Authorised");
    digitalWrite(whiteLED, HIGH);
    display.display();
    // Wait for the card to be removed
    while (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
      delay(50);
    }
    // Hold the LED on for an additional 2 seconds
    //delay(cardAuthDelay); // theo commented out
    digitalWrite(whiteLED, LOW);
  } else {
    display.print("Unauthorised");
    display.setCursor(0, 10);
    display.print("Speak to Theo");
    display.display();
    delay(2000);
  }
  display.clearDisplay();
  display.setCursor(0, 0);
  display.print("Scan your card");
  display.display();
  mfrc522.PICC_HaltA();
}

Now about the code;
You should use a FLAG of some sort for card present test case. Set the flag to be true when it’s “Authorized” and test for it in your main LOOP or add function that Lights the LED that test for it to be True or false.
Note the polarity of the LED pin LOW lights the LED?
How the Device(reader is connected must be correct if you are getting the card present true, and I would NOT combine the test of card UUID and printing it, Seperate those to have a cleaner logic.
Post the picture of the connection if possible.
HTH
GL :slight_smile: PJ
:v:

Hi PJ, this is quite daunting for me as I am umfamilliar with chatting on aForum, You had asked for my Circuit and I have a circuit drawn as a .PNG ( I used Paint to creat this) when I drag is into the area it responds and I see it, but there is no send button for me to send it, I am probabally doing something different to the way it works. Pleas be patent with me, your advice and input is really important to me but This coding enviroment is not something I have learnt and I do not know anybody in my area who shows pe the patients like you do. Perhaps you might let me know if my replys are the way you expect, I want to learn from you please.Regards

1 Like

Just drag and drop it into a message you are typing
then give it a few seconds and it should show up

then finish the message and hit reply

is your name theo?.. like theodore … that where the beaver came from?

Hi Christopher Yes, I am Theo, back in the 50s Theodore was leave it to Beaver so I was Theo.

I was trying to get a better understanding what and how forums work, and how I could use them, so seeeduino was my first attempt.

Attached is what it is I am trying to get to work, I live on a small pension and whilst I have a lot of patience, I never learnt coding My electronics always got me by till my retirement years.

I’m enjoying doing the groundwork on this project, it is a gift to our new Makerspace to get us up and running. But the code I find very hard to understand.

Thanks for your interest in me.

Regards

Theo

1 Like

hi sorry stillstruggling to get my .png of my circuit layout onto this forom, So i pressed reply then drag and dropped the .png and then reply button but then it reports “Sorry, you can’t embed media items in a post.”

its ok… are you in england? One thing about this forum is people are from all over the world so the time difference can really mess with you… especially on the weekends!

the forum may not allow you to post pictures yet becase you are new and may be a scammer I know it will not let me post video just keep on asking questions here and we will try to help… I know for me its hard to teach an old dog new tricks… I use alot of youtube… it seemes people are too lazy to write a good user manual… so we have to piece it together

Can the following project be implemented with XIAO?

Here they used a generic ESP8266. Can we use XIAO instead?