Cov txheej txheem:

App khw yooj yim Siv RFID RC-522 thiab Arduino Mega: 6 Kauj Ruam
App khw yooj yim Siv RFID RC-522 thiab Arduino Mega: 6 Kauj Ruam

Video: App khw yooj yim Siv RFID RC-522 thiab Arduino Mega: 6 Kauj Ruam

Video: App khw yooj yim Siv RFID RC-522 thiab Arduino Mega: 6 Kauj Ruam
Video: qhia siv lub app photomath keb lej tau yooj yim heev 2024, Kaum ib hlis
Anonim
App khw yooj yim Siv RFID RC-522 thiab Arduino Mega
App khw yooj yim Siv RFID RC-522 thiab Arduino Mega

Nws yog qhov zoo uas tau pom koj dua ntawm no ntawm kuv lwm qhov kev qhia, ntawm no kuv yuav pab koj los tsim daim ntawv thov khoom lag luam yooj yim siv RFID RC-522 thiab Arduino nrog Ua kom tsim tau yooj yim GUI.

Nco tseg: tsis txhob khiav Arduino tus saib xyuas thaum khiav cov cai vim hais tias chaw nres nkoj tsis sib haum yuav tshwm sim vim ob leeg yuav tsum siv tib lub chaw nres nkoj

Koj Xav Tau:

  1. Arduino Mega lossis Arduino Uno (Kuv siv Mega)
  2. RFID-RC522
  3. 7 txiv neej rau poj niam jumper xov hlau
  4. Qee daim npav ID (xaiv tau)
  5. RFID Lub Tsev Qiv Ntawv (Yuav tsum, Txuas Hauv Qab)
  6. Wamp neeg rau zaub mov
  7. Ua IDE 2.2.1 (tsis txhob siv ntau dua ntawd)
  8. BezierSQLib-0.2.0 tsev qiv ntawv rau kev ua (Rub tawm txuas hauv qab no)

Tom qab ntawv Rub tawm Hauv qab no RFID lub tsev qiv ntawv thiab ntxiv nws rau koj Arduino IDE los ntawm txhaj Sketch-> Xws li Tsev Kawm Ntawv-> Ntxiv. Zip Library hauv cov ntawv qhia zaub mov

Kauj Ruam 1: Teeb Arduino thiab RFID RC-522 (Kev Sib Txuas Lub Cev)

Teeb Arduino thiab RFID RC-522 (Kev Sib Txuas Lub Cev)
Teeb Arduino thiab RFID RC-522 (Kev Sib Txuas Lub Cev)

yooj yim txuas cov arduino nrog RFID-RC522 raws li qhia hauv cov duab saum toj no. Warning: muab tsuas yog 3.3V txwv tsis pub module yuav hlawv tawm

Pin Out rau Uno/Nano thiab Mega

RC522 MODULE Uno/Nano MEGASDA D10 D9 SCK D13 D52 MOSI D11 D51 MISO D12 D50 IRQ N/A N/A GND GND GND RST D9 D8 3.3V 3.3V 3.3V

Kauj ruam 2: Arduino Code.,

Luam cov cai hauv qab no rub nws rau koj Arduino

/*PINOUT: RC522 MODULE Uno/Nano MEGA SDA D10 D9 SCK D13 D52 MOSI D11 D51 MISO D12 D50 IRQ N/AN/A GND GND GND RST D9 D8 3.3V 3.3V 3.3V*//*suav nrog tus qauv Arduino SPI lub tsev qiv ntawv */ #suav nrog/ *Suav nrog RFID lub tsev qiv ntawv */ #suav nrog

/* Txheeb cais DIO siv rau SDA (SS) thiab RST (pib dua) pins. */

#define SDA_DIO 9 #define RESET_DIO 8

/ * Tsim ib qho piv txwv ntawm RFID lub tsev qiv ntawv */

RFID RC522 (SDA_DIO, RESET_DIO); int nyeem ntawv = 0;

void teeb tsa ()

{Serial.begin (9600); / * Pab kom SPI interface */ SPI.begin (); / * Pib ua tus nyeem ntawv RFID */ RC522.init (); }

void lub voj ()

{ / * Lub voj voos ib ntus * / byte i;

/* Puas tau pom daim npav? */

yog (RC522.isCard ()) { / * Yog li ntawd tau txais nws tus lej lej * / RC522.readCardSerial ();

/ * Tso cov lej tawm mus rau UART */ rau (i = 0; i <= 2; i ++) {Serial.print (RC522.serNum , DEC); //Serial.print(RC522.serNum, HEX); } Serial.print (","); Serial.print (nyeem ntawv ++); Serial.println (); } ncua (1000); }

Kauj Ruam 3: Teeb MySQL

Teeb MySQL
Teeb MySQL
  1. Nruab Wamp server rau MySQL thiab teeb tsa nws kom khaws cov ntaub ntawv (
  2. Khiav wamp serveropen MySQL console
  3. xaiv database
  4. Tom qab ntawd tsim lub rooj rau koj cov ntaub ntawv

tsim cov lus rfid (ID int (8), token int (1), Npe varchar (20), Tus nqi int (4));

Tam sim no saib qhov txuas no txhawm rau kawm paub yuav ua li cas kom tau txais koj li txiaj ntsig RFID lossis tom qab siv tus lej hauv qab no txhawm rau ntxig cov ntaub ntawv. Tsis txhob hnov qab hloov tus lej tus lej nrog koj tus lej cim npe RFID

ntxig rau hauv rfid qhov tseem ceeb (3756178, 1, 'Mem hluav', 20);

siv tus nqi token li 1 yog li ntawd tom qab nyeem tus lej cim thawj zaug nws yuav hloov pauv mus rau 2, tsis txhob siv 0 rau tus nqi token thaum nyeem daim npav uas tsis tau ntxig rau hauv DB nws yuav muab 0 tom qab ntawd tso nws ua Daim Ntawv Tsis Paub..

Kauj Ruam 4: Teeb Kev Ua Haujlwm IDE

Teeb Kev Ua Haujlwm IDE
Teeb Kev Ua Haujlwm IDE
  1. Rub tawm thiab Txhim Kho Cov Txheej Txheem IDE 2.2.1
  2. Tshem tawm cov ntawv ZIP saum toj no rau MyDocuments/Ua/Libraries
  3. Tam sim no qhib kev ua IDE thiab tshawb xyuas lub tsev qiv ntawv tau teeb tsa raug lossis tsis zoo li hauv cov duab saum toj no
  4. Tom qab ntawd Luam cov cai hauv qab no los ua thiab npe nws ntawm koj tus kheej

ntshuam de.bezier.data.sql.*; ntshuam ua tiav.serial.*; // ntshuam java.math. BigInteger;

// tsim 2005-05-10 los ntawm fjenett

// hloov tshiab fjenett 20080605

MySQL dbconnection;

Txoj hlua s = ""; int Qhov siab = 700; int Luas = 1200; ntev ID; koj token; tus nqi; int Tag nrho = 0;

Txoj hlua a = {"NULL", "NULL"};

int kawg = 10; // tus lej 10 yog ASCII rau kab ntawv pub zaub mov (kawg ntawm cov ntawv.println), tom qab ntawd peb yuav saib qhov no txhawm rau txhawm rau txhawm rau cais cov lus ib leeg zuj zus; // tshaj tawm txoj hlua tshiab hu ua 'serial'. Ib txoj hlua yog ntu ntu ntawm cov cim (hom ntaub ntawv paub zoo li "char") Serial chaw nres nkoj; Txoj hlua curr, ua ntej, Lub npe; PFont f;

void teeb tsa ()

{// loj (Dav, Qhov siab); loj (700, 500); f = createFont ("Arial", 24, tseeb); // qhov piv txwv no kwv yees tias koj tab tom khiav // mysql server hauv zos (ntawm "localhost"). // // hloov --username--, --password- nrog koj li mysql-account. // String user = "hauv paus"; Txoj hlua hla = ""; // lub npe ntawm lub database siv // String database = "IOT_Database"; // lub npe ntawm lub rooj uas yuav raug tsim String table = ""; // txuas rau database ntawm server "localhost" dbconnection = tshiab MySQL (qhov no, "localhost", database, tus neeg siv, dhau); port = Serial tshiab (qhov no, Serial.list () [0], 9600); // pib qhov khoom los ntawm kev xa chaw nres nkoj thiab tus nqi baud (yuav tsum sib xws ntawm Arduino) chaw nres nkoj.clear (); // ua haujlwm los ntawm cov tsev qiv ntawv uas cuam tshuam thawj zaug nyeem, thaum peb pib nyeem hauv nruab nrab ntawm txoj hlua los ntawm Arduino serial = port.readStringUntil (kawg); // muaj nuj nqi uas nyeem cov hlua los ntawm qhov chaw nres nkoj txuas mus txog thaum luam tawm thiab tom qab ntawv muab txoj hlua rau peb cov hlua sib txawv (hu ua 'ntu') serial = tsis muaj; } tsis muaj dab tsi kos () {keeb kwm yav dhau (255); textFont (f, 24); puv (0); text ("Tag Nrho Tus Nqi Rs:", 400, 400); ntawv nyeem (Tag nrho, 585, 400); cov ntaub ntawv (); thaum (port.available ()> 0) {// tsuav yog muaj cov ntaub ntawv los ntawm chaw nres nkoj txuas, nyeem nws thiab khaws nws cov lej = port.readStringUntil (kawg); } yog (serial! = tsis muaj) {prev = curr; cov = a [1]; a = phua (serial, ','); // ib qho array tshiab (hu ua 'a') uas khaws cov txiaj ntsig rau hauv cov cell sib cais (cais los ntawm tus lej cim tseg hauv koj li Arduino program) yog ((curr).equals (prev)) {//} else {// println ("curr ", kev); // println ("Ua ntej", ua ntej); muaj nuj nqi (); }}}

tsis muaj nuj nqi ()

{yog (dbconnection.connect ()) {// tam sim no nyeem nws rov qab // dbconnection.query ("SELECT * los ntawm rfid qhov twg ID ="+a [0]+""); thaum (dbconnection.next ()) {ID = dbconnection.getInt ("ID"); token = dbconnection.getInt ("token"); Tus nqi = dbconnection.getInt ("Tus nqi"); } yog (token == 0) {println ("Ok"); textFont (f, 54); sau (255, 0, 0, 160); ntawv nyeem ("Tsis paub yam khoom tau pom", 50, 300); ncua (2000); } lwm tus yog (token == 1) {Total = Total+Amount; dbconnection.query ("hloov tshiab rfid teeb token = 2 qhov twg ID ="+a [0]+""); println ("Ok"); textFont (f, 24); sau (255, 0, 0, 160); // text ("Yam khoom ntxiv", 10, 30); ncua (1000); } lwm tus yog (token == 2) {Total = Total-Amount; dbconnection.query ("hloov tshiab rfid teeb token = 1 qhov twg ID ="+a [0]+""); println ("OK"); textFont (f, 24); sau (255, 0, 0, 160); // text ("Yam khoom raug tshem tawm", 10, 30); ncua (1000); } lwm {} dbconnection.close (); } lwm { / kev sib txuas ua tsis tau tejyam! }}

void cov ntaub ntawv ()

{int txoj hauj lwm = 100; yog (dbconnection.connect ()) {dbconnection.query ("SELECT * los ntawm rfid qhov twg token = 2"); thaum (dbconnection.next ()) {Lub npe = dbconnection.getString ("Npe"); Tus nqi = dbconnection.getInt ("Tus nqi"); textFont (f, 24); sau (0, 0, 255, 160); ntawv (Npe, 10, txoj haujlwm); sau (0, 0, 0, 160); ntawv (Tus lej, 215, txoj haujlwm); txoj hauj lwm = txoj hauj lwm+30; }} dbconnection.close (); }

Kauj Ruam 5: Ua tiav Txoj Haujlwm

Ua tiav Txoj Haujlwm
Ua tiav Txoj Haujlwm
Ua tiav Txoj Haujlwm
Ua tiav Txoj Haujlwm
Ua tiav Txoj Haujlwm
Ua tiav Txoj Haujlwm
Ua tiav Txoj Haujlwm
Ua tiav Txoj Haujlwm

Khiav qhov kev zov me nyuam los ntawm txhaj lub pob khiav tsis kaw lub qhov rooj qhib qhov qhib yuav tsum tsis ua tiav thiab hauv qab cov lus nug kom pom cov ntaub ntawv khaws tseg hauv MySQL …

Kauj Ruam 6: Xaus

Kuv xav ua tsaug rau koj nyeem kuv cov lus qhia. Kuv yuav txaus siab yog tias koj pom nws muaj txiaj ntsig thiab poob qhov nyiam (nyiam) lossis nug kuv ib yam vim nws ua rau kuv mob siab ua cov lus qhia no. xav tias dawb nug cov lus nug uas koj xav paub …

Zoo Siab Coding Arduino…

Pom zoo: