RFID <MFRC522.h> won't work with new ARDUINO UNO WiFi REV2

I followed a basic example for the RFID module on a ARDUINO UNO REV3 and it works great. But when I try to connect it to the new ARDUINO UNO WiFi REV2 it won't work. Is the SPI connection different on the new one?

Thanks in advance!

PeeJeeDC's picture:

Post a link to where you got the MFVC522 library from. Please use the chain links icon on the forum toolbar to make it clickable. Or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.

What exactly do you mean by "it won't work"? Is there an error while compiling the sketch, or does it compile but then not work as expected?

In the code we use the MFRC522 by GithubCommunity. MFRC522

With "it won't work", I mean that if you scan the RFID tag it won't show the UID in the serial monitor. This worked for the ARDUINO UNO REV3.

See the example code:

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

#define RST_PIN   9    // Configurable, see typical pin layout above
#define SS_PIN    10    // Configurable, see typical pin layout above

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

/* Set your new UID here! */
#define NEW_UID {0xDE, 0xAD, 0xBE, 0xEF}

MFRC522::MIFARE_Key key;

void setup() {
  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)
  SPI.begin();         // Init SPI bus
  mfrc522.PCD_Init();  // Init MFRC522 card
  Serial.println(F("Warning: this example overwrites the UID of your UID changeable card, use with care!"));
  
  // Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
  for (byte i = 0; i < 6; i++) {
    key.keyByte[i] = 0xFF;
  }
}

// Setting the UID can be as simple as this:
//void loop() {
//  byte newUid[] = NEW_UID;
//  if ( mfrc522.MIFARE_SetUid(newUid, (byte)4, true) ) {
//    Serial.println("Wrote new UID to card.");
//  }
//  delay(1000);
//}

// But of course this is a more proper approach
void loop() {
  
  // Look for new cards, and select one if present
  if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
    delay(50);
    return;
  }
  
  // Now a card is selected. The UID and SAK is in mfrc522.uid.
  
  // Dump UID
  Serial.print(F("Card UID:"));
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
  } 
  Serial.println();

  // Dump PICC type
//  MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
//  Serial.print(F("PICC type: "));
//  Serial.print(mfrc522.PICC_GetTypeName(piccType));
//  Serial.print(F(" (SAK "));
//  Serial.print(mfrc522.uid.sak);
//  Serial.print(")\r\n");
//  if (  piccType != MFRC522::PICC_TYPE_MIFARE_MINI 
//    &&  piccType != MFRC522::PICC_TYPE_MIFARE_1K
//    &&  piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
//    Serial.println(F("This sample only works with MIFARE Classic cards."));
//    return;
//  }
  
  // Set new UID
  byte newUid[] = NEW_UID;
  if ( mfrc522.MIFARE_SetUid(newUid, (byte)4, true) ) {
    Serial.println(F("Wrote new UID to card."));
  }
  
  // Halt PICC and re-select it so DumpToSerial doesn't get confused
  mfrc522.PICC_HaltA();
  if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
    return;
  }
  
  // Dump the new memory contents
  Serial.println(F("New UID and contents:"));
  mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
  
  delay(2000);
}

I'm having the same problem unfortunately. It runs fine on the Arduino Uno but not on the Uno Wifi REV2.

i have the same problem with this board(rev 2 wifi). But, in my case, i have found a solution and it seems to work. In the right part of both boards, there are 6 pins (ISCP). The fist one (at the top and left) is MISO. Down MISO is SCK, and next to SCK (right) is MOSI. Try to connect this pins to the MFRC522. You can choose the pins you want to the SDA and RST in the program.

1 Like

Karma added. The reason for that ICSP header is to have a universal SPI connection at the same place for all boards with the Uno's (or Mega's) form factor. It's the same for the I2C; only the 328P carries those signals on A4/A5.

willypere:
...In the right part of both boards, there are 6 pins (ISCP). The fist one (at the top and left) is MISO. Down MISO is SCK, and next to SCK (right) is MOSI. Try to connect this pins to the MFRC522. You can choose the pins you want to the SDA and RST in the program.

I don't understand, should I make connections on the Uno Wifi Rev2 board as per the Uno? I have a regular Uno connected to thr RC-522 now, I would just transfer the wires to the same pins on the Uno Wifi Rev2. But then what should I do with the pins mentioned in the quote?

One of the significant differences between the Uno and the Uno WiFi Rev2 is that the Uno has the SPI bus pins broken out on pins 11-13 as well as on the 2x3 pin ICSP header. On the Uno WiFi Rev2, the SPI bus is only broken out on the 2x3 ICSP header. This means that if you had the MFRD522 connected to pins 11-13 on your Uno and you tried to use the same wiring on your Uno WiFi Ref2, it won't work.

Here's the pinout of the ICSP header:

Pin one is marked on your Uno WiFi Rev2 by a white dot on the silkscreen of the PCB next to the corner of the header.

1 Like

Hey pert,

today I had the same issue. Many thanks for your support. It was an easy fix afterwards.
I'd wish these details were exposed a bit better. Anyhow, that makes one learn more.

Cheers J

Hi all

I am trying to use the SparkFun SSD1320 OLED library

together with an Arduino Uno WifiRev2.

The sketch/library works fine on an Arduino Uno, but not on the Uno WifiRev2 (Blink and other sketches have worked, so I guess the set-up was generally successful).

My guess is that it has also to do with the different pins that are used by the WifiRev2 and, in particular, ICSP-3 instead of Arduino UNO Pin 13 and ICSP-4 instead of Arduino UNO Pin 11. But what I don't get from the earlier posts is how I have to write the code so that these other pins (i.e. ICSP-4 and 3) are used.

The SSD1320 OLED library also uses the SPI.h library. The latter contains some definitions at the beginning which I tried to change (basically replaced "13" by "ICSP-3 and "11" by "ICSP-4"), but to no avail as it only would allow me to insert numbers).

Sketch:

/*
  Control a SSD1320 based flexible OLED display
  By: Nathan Seidle
  SparkFun Electronics
  Date: November 21st, 2017
  License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).

  To connect the display to an Arduino:
  (Arduino pin) = (Display pin)
  Pin 13 = SCLK on display carrier
  11 = SDIN
  10 = !CS
  9 = !RES

  The display is 160 pixels long and 32 pixels wide
  Each 4-bit nibble is the 4-bit grayscale for that pixel
  Therefore each byte of data written to the display paints two sequential pixels
  Loops that write to the display should be 80 iterations wide and 32 iterations tall
*/

#include <SSD1320_OLED.h>


//Initialize the display with the follow pin connections
SSD1320 flexibleOLED(10, 9); //10 = CS, 9 = RES


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

  flexibleOLED.begin(160, 32); //Display is 160 wide, 32 high
}

void loop()
{
  TextExample1();
  TextExample2();
}

void TextExample1()
{
  printTitle("GRAB HIM BY THE FUCK", 0);
}

void TextExample2()
{
  printTitle("KISS HIM", 0);
}

// Center and print a small title
// This function is quick and dirty. Only works for titles one line long.
void printTitle(String title, int font)
{
  int middleX = flexibleOLED.getDisplayWidth() / 2;
  int middleY = flexibleOLED.getDisplayHeight() / 2;

  flexibleOLED.begin(160, 32); //Display is 160 wide, 32 high
  
  flexibleOLED.clearDisplay();
  flexibleOLED.invert(1); //invert black and white
  flexibleOLED.setFontType(font);

  // Set the cursor in the middle of the screen
  flexibleOLED.setCursor(middleX - (flexibleOLED.getFontWidth() * (title.length() / 2)),
                 middleY - (flexibleOLED.getFontHeight() / 2));

  // Print the title:
  flexibleOLED.print(title);
  flexibleOLED.display();

  flexibleOLED.command(ACTIVATESCROLL);
  flexibleOLED.command(LEFTHORIZONTALSCROLL);
  delay(10000);

}

Spi.h

/*
  This is a basic driver for the SSD1320 OLED driver IC. It can initialize the display
  and do simple commands like setPixels, drawCharacters, and other simple commands.

  We can't use SPI library out of the box because the display
  requires 9-bit data in 3-wire SPI mode.
  So we bit-bang the first bit then use SPI hardware to send remaining 8 bits
*/

#include <Arduino.h>
#include <SPI.h>

#define SCLK_PIN_DEFAULT 13
#define SDOUT_PIN_DEFAULT 11
#define CS_PIN_DEFAULT 10
#define RST_PIN_DEFAULT 8

(...)

Any help would be greatly appreciated.