Go Down

Topic: Two mfrc522 And Ethernet Shield Connection Error (Read 104 times) previous topic - next topic

acoolcoder

Hello all,

I made same research about SPI devices. It could be mutual PINS that RFID and Ethernet Shield using together.

I tried possible solutions so far. Ethernet Shield obtains IP address. But couldn't connect to server to send data.

Ps: If i remove mfrc522 devices. Ethernet shield connected to server so it works well.

RST PIN 9
SS PIN 2
SS PIN 5

I changed SS pins by various 3,6,7,8 but cannot connect.

Code: [Select]
#include <Ethernet.h>
#include <SPI.h>
#include <MFRC522.h>


#define NR_OF_READERS   2
#define RST_PIN         9
#define SS_1_PIN        2
#define SS_2_PIN        5
int WARNING = 3;

/* NETWORK */

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x2A, 0x8D };
byte ip[] = { 192, 168, 1, 177 };
byte gw[] = {192, 168, 1, 1};
byte subnet[] = { 255, 255, 255, 0 };
byte server[] = { 192, 168, 1, 100  }; // Server IP

EthernetClient client;



int data = 1022;

/* NETWORK */

byte ssPins[] = {SS_1_PIN, SS_2_PIN};
MFRC522 mfrc522[NR_OF_READERS];

void setup()
{
  Serial.begin(9600);
  SPI.begin();
  pinMode(4, OUTPUT);
  digitalWrite(4, HIGH);

  pinMode(SS_1_PIN, OUTPUT);
  digitalWrite(SS_1_PIN, HIGH);
  pinMode(SS_2_PIN, OUTPUT);
  digitalWrite(SS_2_PIN, HIGH);
  pinMode(10, OUTPUT);
  digitalWrite(10, LOW);
  //
 
  pinMode(WARNING, OUTPUT);
  //



  Ethernet.begin(mac, ip, gw, gw, subnet);
  //SPI.usingInterrupt(10);
  Serial.println(Ethernet.localIP());
  //
  for (uint8_t reader = 0; reader < NR_OF_READERS; reader++)
  {
    mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN);
    mfrc522[reader].PCD_DumpVersionToSerial();
  }
}

void loop()
{

  for (uint8_t reader = 0; reader < NR_OF_READERS; reader++)
  {

    if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial())
    {

      Serial.print("Kart Basan Personel:");


      dump_byte_array(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size);
      Serial.println("");
      tone(WARNING, 400, 300);

      mfrc522[reader].PICC_HaltA();
      mfrc522[reader].PCD_StopCrypto1();
      //
      senddata();
    }
  }
}


void dump_byte_array(byte * buffer, byte bufferSize) {
  for (byte i = 0; i < bufferSize; i++) {
    Serial.print(buffer[i] < 0x10 ? " 0" : " ");
    Serial.print(buffer[i], HEX);
  }
}


void senddata()
{
  Serial.println("ATE :)");
  delay(1000);

  if (client.connect(server, 80))
  {
    Serial.println("Connected");
    client.print("GET /test.php?data=");
    client.print(data);
    client.println("HTTP/1.1");
    client.println("Host: 192.168.1.100");
    client.println("Connection: close");
    client.println();
    Serial.println();
    while (client.connected())
    {
      while (client.available())
      {
        Serial.write(client.read());
      }
    }
  }

  else
  {
    Serial.println("Connection unsuccesful");
  }

  client.stop();
  while (client.status() != 0)
  {
    delay(5);
  }
}

pylon

What version of the libraries (Ethernet, MFRC522) are you using? If the don't have the SPI transaction handling it won't work. The current version of the two libraries have that feature so it might work if you update your libraries.

acoolcoder

Hi thank you for reply,

I'm using two MFRC522 and one ethernet shield (w5100).

pylon

I asked for the version of the libraries not the hardware. Older versions of the libraries don't save the SPI parameters correctly but if you use a current version of the two libraries it should run without the problems you mentioned.

If you go into the library manager in your IDE and search for the library it should show you the installed version. For Ethernet version 2.0.0 is current (at the moment) while MFRC522 has currently version 1.4.4.

Go Up