Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Teensy + Ethernet + 3 RFID

  1. #1
    Member
    Join Date
    Nov 2014
    Location
    Italy
    Posts
    34

    Teensy + Ethernet + 3 RFID

    Hi!
    I'm working on a project that use a Teesny 3.2, 3 RFID MFRC522 and the WIZ820io module with the adaptor (waiting for the WIZ850io module to test).
    I need to read the value from the three RFID and comunicate if each one is reading the correct one or another one.
    The communication is in Modbus, ad I'm using the following library:
    Modbus
    MFRC522

    My code is the following (hiding that is not useful):
    Code:
    #include <SPI.h>
    #include <Ethernet.h>
    #include <MFRC522.h>
    #include <Mudbus.h>
     
    #define SENNUM  3 //total amount of sensors
    
    uint8_t mac[] = {0x04, 0xE9, 0xE5, 0x06, 0xE1, 0x28}; 
    uint8_t ip[] = {10, 0, 0, 108};                           //The ip is fixed
    
    //Modbus Registers Offsets (0-9999)
    const int SENSORS[SENNUM] = {1, 2};
    
    int sensStatus[SENNUM] = {0, 0, 0};
    
    //Used Pins
    const int sensPins[SENNUM] = {14, 15, 16}; // // SS pins, Configurable
    
    //ModbusIP object
    Mudbus Mb;
    
    // game spec initializations
    constexpr uint8_t RST_PIN = 17;          // Configurable, see typical pin layout above
    
    MFRC522 mfrc522[SENNUM];  // Create mfrc522b instances
    
    const int nOfTAG = 8; //TAGs
    String currentTAG[SENNUM];
    String correctTAG[nOfTAG] = {"01836014245", "01357614245", "01674912245", "02154412245", "01349135218", "0141176138218", "07792135218", "077119144218"};
    
    void setup() {
      // reset for Ethernet Shield
      pinMode(9, OUTPUT);
      digitalWrite(9, LOW); // reset the WIZ820io
      delay(1000);
      digitalWrite(9, HIGH); // release the WIZ820io
    
      pinMode(10, OUTPUT);
      digitalWrite(10, HIGH);
      pinMode(14, OUTPUT);
      digitalWrite(14, HIGH);
      pinMode(15, OUTPUT);
      digitalWrite(15, HIGH);
      pinMode(16, OUTPUT);
      digitalWrite(16, HIGH);
    
      Ethernet.begin(mac, ip);
      delay(5000);
      // disable w5100 SPI
    
      Serial.print("server is at ");
      Serial.println(Ethernet.localIP());
    
      //RFID initializzation 
      for (uint8_t i = 0; i < SENNUM; i++) {
        mfrc522[i].PCD_Init(sensPins[i], RST_PIN);   // Init mfrc522a
        Serial.println("game");
        mfrc522[i].PCD_DumpVersionToSerial();  // Show details of PCD - mfrc522a Card Reader details
        Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
      }
    }
    
    void loop() {
      Mb.Run();
      gameUpdate();
    }
    
    void gameUpdate() {
      // Look for new cards
      for (uint8_t i = 0; i < SENNUM; i++) {
        mfrc522[i].PCD_Init();
        String readRFID = 0;
        if ( mfrc522[i].PICC_IsNewCardPresent() && mfrc522[i].PICC_ReadCardSerial()) {
          for (int b = 0 ; b < mfrc522[i].uid.size; b++) readRFID.concat(mfrc522[i].uid.uidByte[b]);
        }
        if (readRFID != currentTAG[i]) {
          currentTAG[i] = readRFID;
        }
        //Halt PICC
        mfrc522[i].PICC_HaltA();
        // Stop encryption on PCD
        mfrc522[i].PCD_StopCrypto1();
      }
    
      for (uint8_t i = 0; i < SENNUM; i++) {
        boolean found = false;
        // controllo dei valori dei tag sui due lettori RFID
        for (uint8_t y = 0; y < nOfTAG / 2; y++) {
          if (currentTAG[i].equals(correctTAG[y + (i * nOfTAG / 2)])) found = true;
        }
        if (found) {
          sensStatus[i] = HIGH;
          if (!i) {
            Serial.print("Correct TAG-A ");
            Serial.println(currentTAG[i]);
          }
          else {
            Serial.print("Correct TAG-B ");
            Serial.println(currentTAG[i]);
          }
        } else  {
          if (currentTAG[i] != "0") {
            sensStatus[i] = 2;
            if (!i) {
              Serial.print("TAG-A ");
              Serial.println(currentTAG[i]);
            }
            else {
              Serial.print("TAG-B ");
              Serial.println(currentTAG[i]);
            }
          } else sensStatus[i] = LOW;
        }
        Mb.R[SENSORS[i]] = sensStatus[i];
      }
    }
    The circuit is this one:
    Click image for larger version. 

Name:	Cattura.JPG 
Views:	4 
Size:	107.0 KB 
ID:	16953
    The length of the cables (Ethernet CAT 5) is approximatively 50cm each
    I tried this configuration with a Teensy LC and jumper cable and it is all working.

    Then I moved it with the other cable in the final room and I have ip problem. The Ethernet library show me my ip as 0.0.0.0
    If I disconnect The teensy from the circuit it takes the correct ip.
    If I connect one RFID only it takes the correct ip.
    When I connect the second RFID initially it takes the correct ip but sometimes the device change it in 10.0.0.80 or 10.0.0.160 (i use this code in the loop to control it)
    Code:
    Serial.print("server is at ");
    Serial.println(Ethernet.localIP());
    One strange thing is that If I connect two RFID and connect only the cable of the third, without the device, I have the same problem (0.0.0.0 ip)

    can it be an SPI problem (some conflict between the Ethernet module and the RFID modules)?

    Must I add the pull-up resistor on the CS pins? i tried with 10k with no results
    Must I reduce the clock frequency of the SPI? how?

    looking at this link I do not understand how to integrate the Step 3: USB SPI Transactions in Software, in my software.
    also I bought some 74HC4051 to use it as suggested here but I'm not sure the problem is the RFID, must I connect also the ethernet module to the multiplexer?

    Any suggestion is appreciated!

    Thanks

  2. #2
    Member
    Join Date
    Nov 2014
    Location
    Italy
    Posts
    34
    Hi,
    I tried with the WIZ850io module and reducing the cable length with some results but the same problem.
    Now the device tekes the correct IP but after the initialization of the RFID it change it to 10.0.2.160.
    I tied also to invert the setup of RFIDs and Ethernet with no results.
    Can someone halp me to understand where is my problem?
    thanks!

  3. #3
    Member
    Join Date
    Nov 2014
    Location
    Italy
    Posts
    34
    The only way to make it work is using 10cm long jumper....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •