• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
UNO + ETHERNET + RC522
#1
Witam
Proszę o radę ponieważ chce podłączyć  UNO + ETHERNET w5100[font=Arial, Helvetica, sans-senif, SimSun, 宋体] [/font]+ RC522 
i mój problem jest chyba w tym że w5100 i RC522 kożystają z tych samych pinów. Proszę o pomoc z rozwiązaniem tego problemu pozdrawiam
 
Odpowiedź
#2
kod poprosimy bo wróżenie z fusów kiepsko wychodzi
Ważne aby robić co się lubi albo lubić co się robi .
Arduino UNO, TINY, PRO MINI
Pomoc nagradzamy punktami reputacji Wink
 
Odpowiedź
#3
Kod:
#include <SPI.h>
#include <Ethernet.h>
#include <MFRC522.h>

#define RST_PIN         1          // Configurable, see typical pin layout above
#define SS_PIN          2         // Configurable, see typical pin layout above

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

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 0 , 177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
 // Open serial communications and wait for port to open:
 Serial.begin(9600);
 while (!Serial) {
   ; // wait for serial port to connect. Needed for native USB port only
 }


 // start the Ethernet connection and the server:
 Ethernet.begin(mac, ip);
 server.begin();
 Serial.print("server is at ");
 Serial.println(Ethernet.localIP());
 SPI.begin();            // Init SPI bus
    mfrc522.PCD_Init();        // Init MFRC522
    mfrc522.PCD_DumpVersionToSerial();    // Show details of PCD - MFRC522 Card Reader details
    Serial.println(F("Scan PICC to see UID, type, and data blocks..."));
}
 
}


void loop() {
 // listen for incoming clients
 EthernetClient client = server.available();
 if (client) {
   Serial.println("new client");
   // an http request ends with a blank line
   boolean currentLineIsBlank = true;
   while (client.connected()) {
     if (client.available()) {
       char c = client.read();
       Serial.write(c);
       // if you've gotten to the end of the line (received a newline
       // character) and the line is blank, the http request has ended,
       // so you can send a reply
       if (c == '\n' && currentLineIsBlank) {
         // send a standard http response header
         client.println("HTTP/1.1 200 OK");
         client.println("Content-Type: text/html");
         client.println("Connection: close");  // the connection will be closed after completion of the response
         client.println("Refresh: 5");  // refresh the page automatically every 5 sec
         client.println();
         client.println("<!DOCTYPE HTML>");
         client.println("<html>");
         // output the value of each analog input pin
         for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
           int sensorReading = analogRead(analogChannel);
           client.print("analog input ");
           client.print(analogChannel);
           client.print(" is ");
           client.print(sensorReading);
           client.println("<br />");
         }
         client.println("</html>");
         break;
       }
       if (c == '\n') {
         // you're starting a new line
         currentLineIsBlank = true;
       } else if (c != '\r') {
         // you've gotten a character on the current line
         currentLineIsBlank = false;
       }
     }
   }
   // give the web browser time to receive the data
   delay(1);
   // close the connection:
   client.stop();
   Serial.println("client disconnected");
   Ethernet.maintain();
 }
 {
    // Look for new cards
    if ( ! mfrc522.PICC_IsNewCardPresent()) {
        return;
    }

    // Select one of the cards
    if ( ! mfrc522.PICC_ReadCardSerial()) {
        return;
    }

    // Dump debug info about the card; PICC_HaltA() is automatically called
    mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}
}
 
Odpowiedź
#4
Ja mam świadomość że to są bzdury Sad dopiero zaczynam. przepraszam.
 
Odpowiedź
#5
chodzi mi że
* Ethernet shield attached to pins 10, 11, 12, 13
* MFRC522 9,10,11,12,13
i jak zmienić żeby z tych samych pinów nie korzystało Wink
 
Odpowiedź
#6
Witam
Rzeczywiście oba moduły korzystają ze SPI. Za pomocą tego protokołu można wymusić współpracę wielu modułów zarówno równoległą (za pomocą mulitplksera) lub szeregową (kolejne modułu sygnały MOSI i MISO przekazują pomiędzy sobą). Niestety nie mam wiedzy jak to się zachowuje przy zastosowaniu różnych modułów (jednakowa prędkość komunikacji jest tutaj kluczowa). Raczej trudno będzie zsynchronizować dwa różne moduły. 
Nie mam także żadnego doświadczenia w tym temacie. 
Każde z urządzeń pracujące w trybie SLAVE ma dodatkowy pin SS którym master (tu nasze UNO) może sterować.
Wystarczy podawać odpowiednio stan niski lub wysoki aby pobudzać do pracy. Można w ten sposób komunikować się z każdym z osobna w danym czasie. Praca jednoczesna się nie uda. 

Może będą Ci pomocne te linki:
 https://learn.sparkfun.com/tutorials/ser...erface-spi
https://www.circuitsathome.com/mcu/runni...no-spi-bus
Jak wynika z opisu jest to wykonalne.
Pozdrawiam
 
Odpowiedź
#7
Dzięki za odpowiedź Wink może ktoś ma pomysł jak to może działąć bo mam to na zaliczenie, może dwa arduino?
 
Odpowiedź
#8
(22-01-2016, 22:31)awachowski napisał(a): Dzięki za odpowiedź Wink może ktoś ma pomysł jak to może działąć bo mam to na zaliczenie, może dwa arduino?

Poczytaj w datasheeet każdego z modułów - zidentyfikuj pin sterujący , potem zarządzaj nimi za pomocą UNO... jeśli uda się to zsynchronizować ( w sensie osobna konfiguracja dla każdego modułu) to raczej dasz radę na jednym UNO. Trzeba kombinować.
Jasne że każdy chciałby mieć Mercedesa w cenie Malucha :-)  
Pozdrawiam
 
Odpowiedź
#9
Dzięki Wink
 
Odpowiedź
#10
Hej ktoś by mi mógł pomóc z kodem? chciałem żeby UID pokazywał się na stronie

Kod:
#include <SPI.h>
#include <Ethernet.h>
#include <MFRC522.h>

#define RST_PIN   6     // Configurable, see typical pin layout above
#define SS_PIN    7    // Configurable, see typical pin layout above

MFRC522 mfrc522(SS_PIN, RST_PIN);
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 0, 177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
#define NEW_UID {0xDE, 0xAD, 0xBE, 0xEF}
MFRC522::MIFARE_Key key;

void setup() {
 // Open serial communications and wait for port to open:
 Serial.begin(9600);
 while (!Serial){
 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;
 }
}
   ; // wait for serial port to connect. Needed for native USB port only



 // start the Ethernet connection and the server:
 Ethernet.begin(mac, ip);
 server.begin();
 Serial.print("server is at ");
 Serial.println(Ethernet.localIP());
   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],  DEC);
 }
 Serial.println();
}


void loop() {
 // listen for incoming clients
 EthernetClient client = server.available();
 if (client) {
   Serial.println("new client");
   // an http request ends with a blank line
   boolean currentLineIsBlank = true;
   while (client.connected()) {
     if (client.available()) {
       char c = client.read();
       Serial.write(c);
       // if you've gotten to the end of the line (received a newline
       // character) and the line is blank, the http request has ended,
       // so you can send a reply
       if (c == '\n' && currentLineIsBlank) {
         // send a standard http response header
         client.println("HTTP/1.1 200 OK");
         client.println("Content-Type: text/html");
         client.println("Connection: close");  // the connection will be closed after completion of the response
         client.println("Refresh: 5");  // refresh the page automatically every 5 sec
         client.println();
         client.println("<!DOCTYPE HTML>");
         client.println("<html>");
         // output the value of each analog input pin
 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);


         client.println("</html>");
         break;
       }
       if (c == '\n') {
         // you're starting a new line
         currentLineIsBlank = true;
       } else if (c != '\r') {
         // you've gotten a character on the current line
         currentLineIsBlank = false;
       }
     }
   }
   // give the web browser time to receive the data
   delay(1);
   // close the connection:
   client.stop();
   Serial.println("client disconnected");
   Ethernet.maintain();
 }
}
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości