Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use with RFID #4

Open
trkmml opened this issue Sep 10, 2017 · 0 comments
Open

use with RFID #4

trkmml opened this issue Sep 10, 2017 · 0 comments

Comments

@trkmml
Copy link

trkmml commented Sep 10, 2017

Hi,
first I am sorry for my English.

thank you for the library. I use your library in my RFID Door Lock system.

when i read first RFID Card, i can transmit card holder name to receiver
but second and next read, i cant transmit anything,
is this conflict problem?
i use send procedure for transmitting

thansk for help
here is my code

RECEIVER
`#include <PinChangeInterruptHandler.h>
#include <RFReceiver.h>

// Listen on digital pin 2
RFReceiver receiver(8);

void setup() {
Serial.begin(9600);
receiver.begin();
}

void loop() {
char msg[MAX_PACKAGE_SIZE];
byte senderId = 0;
byte packageId = 0;
byte len = receiver.recvPackage((byte *)msg, &senderId, &packageId);

Serial.print("Message: ");

Serial.println(msg);
}`

TRANSMITTER

`enum {INIT_LCD, SCAN_TAG, KEY_IN_PASSWORD} state = INIT_LCD;
//#include <Streaming.h>
// define for nfc
#include <SPI.h>
#include <MFRC522.h>
#include "pitches.h"
#define NOT_FOUND -1
//#define Role 8
#define RST_PIN 9
#define SS_PIN 10
#define Yesil 15
#define Kirmizi 14
#define buton 16
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
char* ourCode = "4422";
int currentPosition = 0;
#define NR_KNOWN_CARDS 14
#define CARD_SIZE 4
int acildi=0;
#include <RFTransmitter.h>
#define NODE_ID 1
#define OUTPUT_PIN 7
int melody[] = {
NOTE_E6, NOTE_E4
};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
2 , 4
};
// init paralle arrays
byte knownCards[NR_KNOWN_CARDS][CARD_SIZE] = {
{0xDE, 0x60, 0x92, 0xAB},
{0x40, 0xB8, 0x55, 0x7A},
{0x40, 0x7B, 0x57, 0x7A},
{0x10, 0xA5, 0x50, 0x7A},
{0x50, 0x06, 0x56, 0x7A},
{0xE0, 0xA5, 0x52, 0x7A},
{0x50, 0x82, 0x5C, 0x7A},
{0x94, 0x2F, 0x64, 0xB8},
{0xC4, 0x8B, 0xBA, 0xA7},
{0x44, 0x60, 0x6A, 0xB8},
{0xBB, 0x46, 0x8D, 0xC9},
{0x0F, 0x9B, 0x8E, 0xC9},
{0x89, 0xD5, 0x8C, 0xC9},
{0xD2, 0x11, 0x8E, 0xC9},

};

char name[NR_KNOWN_CARDS][14] = {
"ASDASD",
"ASDASD",
"ZXCZXC",
"FGHFGH",
"TYUTRYU",
"BNMBNM",
"ERTERT",
"QWQWERQWE",
"NMÖN",
"UIOUIO",
"SDFGDFG",
"657856",
"DFGDF",
"DGDFG"
};

char password[NR_KNOWN_CARDS][5] = {
"3434",
"8888"
};

int n; // current tag index

// define for keypad
#include <Keypad.h>

const byte ROWS = 1;
const byte COLS = 4;
bool sifreGirisi=false;
int buton_deger = 0;
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'1','2','3','4'}
};
byte rowPins[ROWS] = {2};
byte colPins[COLS] = {5,6,3,4};

int count = 0;
char keys[5];
unsigned long time;

Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

// define for lcd
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F, 16, 2);

// define for led
//#include <DigitalToggle.h>

void setup() {
// setup nfc
Serial.begin(9600);
while (!Serial);
SPI.begin();
mfrc522.PCD_Init();
pinMode(Kirmizi, OUTPUT);
pinMode(Yesil, OUTPUT);
// setup keypad (assumed serial began)
keys[4] = 0;
pinMode(buton,INPUT);
// setup lcd
lcd.begin();

// setup led
// pinMode(Role, OUTPUT);

}

void loop() {
if (!sifreGirisi)
{
buton_deger = digitalRead(buton);
//Serial.print(buton_deger);
if (buton_deger > 0)
{
sifreGirisi=true;
lcd.clear();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Sifreli Giris");
lcd.setCursor(0,1);
lcd.print("Sifre : ");
return;
}
init_lcd();
scan_new_card();
key_in_password();
}
else
{

int l;
char key = customKeypad.getKey();
// Serial.print(key);
if (int(key) != 0) {

lcd.setCursor(12,1);
lcd.print("    ");
lcd.setCursor(12,1);

for (l=0; l<=currentPosition; ++l)
{
  lcd.print("*");
}

if (key == ourCode[currentPosition])
  {
    ++currentPosition;
    if (currentPosition == 4)
    {
      unlockDoor();
      currentPosition = 0;
    }
  } else {
    invalidCode();
    currentPosition = 0;
  }

}
}
}
void invalidCode()
{
// servo.write(SERVO_CLOSED_ANGLE);
digitalWrite(Kirmizi, HIGH);
//digitalWrite(servo, HIGH);
//digitalWrite(servo, LOW);
clearScreen();
lcd.setCursor(0,0);
lcd.print("Giris Engellendi");
lcd.setCursor(0,1);
lcd.print("Yanlis Sifre");
digitalWrite(Kirmizi, LOW);
state = INIT_LCD;
sifreGirisi=false;
send("Yanlis Sifre");//göndereceğimiz mesaj
delay(2000);
}

void unlockDoor()
{
digitalWrite(Yesil, HIGH);
clearScreen();
lcd.setCursor(0,0);
lcd.print("Giris Basarili");
lcd.setCursor(0,1);
lcd.print("Hosgeldiniz");

//add any code to unlock the door here
// digitalWrite(Role, HIGH);
// servo.write(SERVO_OPEN_ANGLE);
digitalWrite(Yesil, LOW);
state = INIT_LCD;
sifreGirisi=false;
send("Sifreli Giris");//göndereceğimiz mesaj
delay(2000);
//digitalWrite(Role, LOW);
}

void displayCodeEntryScreen()
{
clearScreen();
lcd.setCursor(0,0);
lcd.print("Sifre Girisi");
}

void clearScreen()
{
lcd.clear();
}
void scan_new_card() {
if (state != SCAN_TAG) {
return;
}
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
mfrc522.PICC_HaltA();
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
Serial.print(F(" ("));
Serial.print(mfrc522.uid.size, DEC);
Serial.println(F(")"));
n = indexOf(mfrc522.uid.uidByte, mfrc522.uid.size);
lcd.backlight();
if ( n != NOT_FOUND) {
Serial.println(name[n]);
show_user(name[n]);
time = millis();
Serial.println(time);
state = KEY_IN_PASSWORD;
} else {
user_not_found();
state = INIT_LCD;
}
}

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);
}
}

int indexOf(byte *buffer, byte bufferSize) {
if (CARD_SIZE == bufferSize) {
for (byte i = 0; i < NR_KNOWN_CARDS; i++) {
byte j;
for (j = 0; j < CARD_SIZE; j++) {
if (buffer[j] != knownCards[i][j]) break;
}

  if (j == CARD_SIZE) return i;
}

}

return NOT_FOUND;
}

void key_in_password() {
if (state != KEY_IN_PASSWORD) {
return;
}
if (millis() - time > 1000) { // exceed 10 seconds ?
state = INIT_LCD;
}

}

void init_lcd() {
if (state != INIT_LCD) {
return;
}
lcd.clear();
lcd.noBacklight();
lcd.setCursor(0,0);
lcd.print("Hosgeldiniz :)");
lcd.setCursor(0,1);
lcd.print("Kartinizi Okutunuz");
state = SCAN_TAG;
}

void user_not_found() {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Bulunamadi!");
digitalWrite(Kirmizi , HIGH);
lcd.backlight();
delay(2000);
digitalWrite(Kirmizi , LOW);
lcd.noBacklight();
send("Tanimsiz Kart");//göndereceğimiz mesaj
}

void show_user(char name[10]) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Merhaba ");
lcd.print(name);
lcd.setCursor(0,1);
lcd.print("Hosgeldin :)");
lcd.backlight();
digitalWrite(Yesil , HIGH);
//digitalWrite(Role, HIGH);
delay(2000);
digitalWrite(Yesil , LOW);
// digitalWrite(Role, LOW);
lcd.noBacklight();
send(name);//göndereceğimiz mesaj

// state = INIT_LCD;

}

void toggle_led() {
// digitalToggle(ledPin);
}
void send (char *message) /mesajı ulaştırmak için
loop kodu send fonksiyonunu çağırır ve bu da mesajın ulaştırılması
için bekler.
/
{
RFTransmitter transmitter(OUTPUT_PIN, NODE_ID);
transmitter.send((byte *)message, strlen(message) + 1);
// vw_set_ptt_inverted(true);
// vw_set_tx_pin(7);// edit okoman: bu parametre programda yoktu sonradan eklendi
// vw_setup(300); /2sn?de bir çalıştırmak için (edit okoman: yaklaşık veri trahasfer hızıdır hatalı açıklama yapılmış)virtualwire?ı başlatır./
// vw_send((uint8_t *)message, sizeof(message));
// vw_wait_tx(); // mesaj gidene kadar bekle.
// Serial.println(strlen(message));
//message=(char *)"";
//delay(200);
//software_Reset();
}

void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
{
asm volatile (" jmp 0");
}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant