30-06-2020, 15:33
Witam.
Mam problem z Arduino Mega do którego mam podłączony czytnik Rc522 i kartę sieciową ENC28J60.
Jeżeli kartę Rc522 mam podłączoną do Arduino krótkimi przewodami połączeniowymi ( krosówki do płytek stykowych ) całość działa mi bez problemu.
Niestety potrzebuję mieś czytnik Rc522 w odległości 3-4 metrów od Arduino. I tu mam problem ponieważ po zmianie przewodu na dłuższy ( 3 m ) efekt mam taki że czytnik działa ale karta sieciowa już nie. Przy pobieraniu adresu IP z DHCP dostaję 0.0.0.0. Ustawienie adresu statycznego też nie rozwiązuje problemu. Nie mogę znaleźć o co chodzi.
Może ktoś pomoże?
Kod programu mam taki:
Mam problem z Arduino Mega do którego mam podłączony czytnik Rc522 i kartę sieciową ENC28J60.
Jeżeli kartę Rc522 mam podłączoną do Arduino krótkimi przewodami połączeniowymi ( krosówki do płytek stykowych ) całość działa mi bez problemu.
Niestety potrzebuję mieś czytnik Rc522 w odległości 3-4 metrów od Arduino. I tu mam problem ponieważ po zmianie przewodu na dłuższy ( 3 m ) efekt mam taki że czytnik działa ale karta sieciowa już nie. Przy pobieraniu adresu IP z DHCP dostaję 0.0.0.0. Ustawienie adresu statycznego też nie rozwiązuje problemu. Nie mogę znaleźć o co chodzi.
Może ktoś pomoże?
Kod programu mam taki:
Kod:
#include <SPI.h>
#include <MFRC522.h>
#include <UIPEthernet.h>
// PIN Numbers : RESET + SDAs
#define RST_PIN 10
#define SS_1_PIN 9
int tagcount = 0;
bool access = false;
char str[10] = "";
EthernetClient client;
char server[] = "192.168.2.11";
byte mac[] = { 0x54, 0x34, 0x41, 0x30, 0x30, 0x34 };
static uint32_t timer;
int buzz = 2;
#define NR_OF_READERS 1
byte ssPins[] = {SS_1_PIN}; //, SS_2_PIN, SS_3_PIN, SS_4_PIN};
// Create an MFRC522 instance :
MFRC522 mfrc522[NR_OF_READERS];
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
pinMode(buzz, OUTPUT);
tone(buzz, 1000, 200);
/* looking for MFRC522 readers */
for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
tagcount ++;
mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN);
Serial.print(F("Czytnik "));
Serial.print(reader);
Serial.print(F(": "));
Serial.print(F("Status "));
Serial.print(mfrc522[1].TestADCReg);
Serial.print(F(" - "));
mfrc522[reader].PCD_DumpVersionToSerial();
mfrc522[reader].PCD_SetAntennaGain(mfrc522[reader].RxGain_max);
}
Ethernet.begin(mac);
Serial.print("IP Address : ");
Serial.println(Ethernet.localIP());
Serial.print("Subnet Mask : ");
Serial.println(Ethernet.subnetMask());
Serial.print("Default Gateway IP: ");
Serial.println(Ethernet.gatewayIP());
Serial.print("DNS Server IP : ");
Serial.println(Ethernet.dnsServerIP());
timer = -9999999; // start timing out right away
Serial.println();
tone(buzz, 1000, 200);
}
void loop() {
for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
// Looking for new cards
mfrc522[reader].PCD_Init();
delay(100);
if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()) {
Serial.print(F("Czytnik "));
Serial.print(reader);
Serial.print(F(": UID Karty:"));
dump_byte_array(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size);
UID_to_string(mfrc522[reader].uid.uidByte, 4, str); //Insert (byte array, length, char array for output)
if (client.connect(server, 80)) {
Serial.println("-> Connected");
// Make a HTTP request:
client.print( "GET /UpdateG2Y.php?");
client.print("value=");
client.print( str );
client.println( " HTTP/1.1");
client.print( "Host: " );
client.println(server);
client.println( "Connection: close" );
client.println();
client.println();
client.stop();
}
else {
// you didn't get a connection to the server:
Serial.println("--> connection failed/n");
}
tone(buzz, 10000, 200);
tagcount = 0;
Serial.println();
delay (1000);
return;
}
else
{
if (tagcount > 1) {
Serial.println("BRAK KARTY");
tagcount = 2;
if (client.connect(server, 80)) {
Serial.println("-> Connected");
// Make a HTTP request:
client.print( "GET /UpdateG2Y.php?");
client.print("value=");
client.print( "00000000" );
client.println( " HTTP/1.1");
client.print( "Host: " );
client.println(server);
client.println( "Connection: close" );
client.println();
client.println();
client.stop();
delay(1000);
}
else {
// you didn't get a connection to the server:
Serial.println("--> connection failed/n");
}
}
// mfrc522[reader].PCD_Reset();
}
tagcount ++;
Serial.println(tagcount);
} //for(uint8_t reader..
}
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 Initialize()
{
tagcount = 0;
access = false;
}
void UID_to_string(byte array[], unsigned int len, char buffer[])
{
for (unsigned int i = 0; i < len; i++)
{
byte nib1 = (array[i] >> 4) & 0x0F;
byte nib2 = (array[i] >> 0) & 0x0F;
buffer[i * 2 + 0] = nib1 < 0xA ? '0' + nib1 : 'A' + nib1 - 0xA;
buffer[i * 2 + 1] = nib2 < 0xA ? '0' + nib2 : 'A' + nib2 - 0xA;
}
buffer[len * 2] = '\0';
}