Skip to content

Instantly share code, notes, and snippets.

@beyazitkolemen
Created February 2, 2020 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beyazitkolemen/00db9a1364f8bec27c9642fd51f30025 to your computer and use it in GitHub Desktop.
Save beyazitkolemen/00db9a1364f8bec27c9642fd51f30025 to your computer and use it in GitHub Desktop.
Save Multi RFID Reader data, read-delete eeprom data over serial
/*
Multi RFID Reader - EEPROM Temporary Save Data
ArtF4
*/
#include "EEPROM.h"
String incoming = ""; // for incoming serial string data
String key = ""; // for incoming serial string data
// the current address in the EEPROM (i.e. which byte
// we're going to write to next)
int address = 100;
int baslangic = 0;
int bitis = 0;
char data1;
char data2;
String newtag;
String newtag2;
void setup()
{
Serial.begin(115200);
Serial2.begin(9600, SERIAL_8N1, 22, 4);
Serial1.begin(9600, SERIAL_8N1, 23, 5);
if (!EEPROM.begin(1000)) {
Serial.println("Failed to initialise EEPROM");
Serial.println("Restarting...");
delay(1000);
ESP.restart();
}
Serial.println("sistembasladi");
}
void loop()
{
newtag = "";
newtag2 = "";
while (Serial2.available() > 0) {
for (int z = 0 ; z < 14 ; z++) // read the rest of the tag
{
data1 = Serial2.read();
newtag += data1;
}
String msg = newtag.substring(5, 11);
long decimal_answer = strtol(msg.c_str(), NULL, 16);
//Serial.println(msg);
//Serial.println(decimal_answer);
iniskayit(decimal_answer);
delay(500);
Serial2.flush();
}
while (Serial1.available() > 0) {
for (int g = 0 ; g < 14 ; g++) // read the rest of the tag
{
data2 = Serial1.read();
newtag2 += data2;
}
String msg2 = newtag2.substring(5, 11);
long decimal_answer2 = strtol(msg2.c_str(), NULL, 16);
//Serial.println(msg2);
//Serial.println(decimal_answer2);
biniskayit(decimal_answer2);
delay(500);
Serial1.flush();
}
if (Serial.available() > 0) {
incoming = Serial.readString();
if (incoming == "bosalt") {
bosalt();
}
if (incoming == "binen") {
binen();
}
if (incoming == "inen") {
inen();
}
}
}
void biniskayit(unsigned long rfid) {
int tip1 = 100;
// Serial.println("Rfid ye yazılıyor binis");
while ( tip1 <= 200) // eğer a değeri 50 küçük ise while çalışsın.
{
//Serial.println(baslangic);
//Serial.println(rfid);
if (EEPROM.readULong(tip1) == rfid)
{
// Serial.println("binis zaten var");
delay(50);
break;
}
//Add one to each cell in the EEPROM
if (EEPROM.readULong(tip1) == 0)
{
EEPROM.writeULong(tip1, rfid);
EEPROM.commit();
//Serial.println("binis olarak yazildi yoktu");
// buzzer kodu
delay(50);
break;
}
tip1 += sizeof(unsigned long);
}
}
void iniskayit(unsigned long rfid) {
int tip2 = 200;
// Serial.println("Rfid ye yazılıyor inis");
while ( tip2 <= 300) // eğer a değeri 50 küçük ise while çalışsın.
{
//Serial.println(baslangic);
//Serial.println(rfid);
if (EEPROM.readULong(tip2) == rfid)
{
// Serial.println("zaten var");
delay(50);
break;
}
//Add one to each cell in the EEPROM
if (EEPROM.readULong(tip2) == 0)
{
EEPROM.writeULong(tip2, rfid);
EEPROM.commit();
delay(50);
break;
// buzzer kodu
}
tip2 += sizeof(unsigned long);
}
}
void binen() {
key = "binen";
int tip1 = 100;
while ( tip1 <= 200)
{
//Add one to each cell in the EEPROM
if (EEPROM.readULong(tip1))
{
key += "," + String(EEPROM.readULong(tip1));
}
else
{
// Serial.println("okuma bitti");
break;
}
tip1 += sizeof(unsigned long);
}
Serial.println(key);
}
void inen() {
key = "inen";
int tip2 = 200;
while ( tip2 <= 300)
{
if (EEPROM.readULong(tip2))
{
key += "," + String(EEPROM.readULong(tip2));
}
else
{
// Serial.println("okuma bitti");
break;
}
tip2 += sizeof(unsigned long);
}
Serial.println(key);
}
void bosalt() {
int a = 100;
while ( a <= 300) // eğer a değeri 50 küçük ise while çalışsın.
{
if (EEPROM.readULong(a) != 0)
{
EEPROM.writeULong(a, 0);
EEPROM.commit();
// Serial.println("silindi");
delay(30);
}
a += sizeof(unsigned long);
}
Serial.println("ok");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment