Sei sulla pagina 1di 13

MEMBACA DATA SERIAL DARI RFID 13.

56MHz + ARDUINO MENGGUNAKAN VB 6 DI WINDOWS 10

Mengapa VB6? Karena itu saja yang saya bisa.

Berikut tahapannya :

SETTING ARDUINO

Setting RFID dan Arduino seperti gambar dibawah ini


Download dan install library MRF522 dari Miguel Balboa pada alamat ini :

https://github.com/miguelbalboa/rfid

Tampilan awal serial monitor :

Buka file example DumpInfo :


/*
* ------------------------------------------------------------------------------------------
--------------------------
* Example sketch/program showing how to read data from a PICC to serial.
* ------------------------------------------------------------------------------------------
--------------------------
* This is a MFRC522 library example; for further details and other examples see:
https://github.com/miguelbalboa/rfid
*
* Example sketch/program showing how to read data from a PICC (that is: a RFID Tag or Card)
using a MFRC522 based RFID
* Reader on the Arduino SPI interface.
*
* When the Arduino and the MFRC522 module are connected (see the pin layout below), load
this sketch into Arduino IDE
* then verify/compile and upload it. To see the output: use Tools, Serial Monitor of the IDE
(hit Ctrl+Shft+M). When
* you present a PICC (that is: a RFID Tag or Card) at reading distance of the MFRC522
Reader/PCD, the serial output
* will show the ID/UID, type and any data blocks it can read. Note: you may see "Timeout in
communication" messages
* when removing the PICC from reading distance too early.
*
* If your reader supports it, this sketch/program will read all the PICCs presented (that
is: multiple tag reading).
* So if you stack two or more PICCs on top of each other and present them to the reader, it
will first output all
* details of the first and then the next PICC. Note that this may take some time as all data
blocks are dumped, so
* keep the PICCs at reading distance until complete.
*
* @license Released into the public domain.
*
* Typical pin layout used:
* -----------------------------------------------------------------------------------------
* MFRC522 Arduino Arduino Arduino Arduino Arduino
* Reader/PCD Uno/101 Mega Nano v3 Leonardo/Micro Pro Micro
* Signal Pin Pin Pin Pin Pin Pin
* -----------------------------------------------------------------------------------------
* RST/Reset RST 9 5 D9 RESET/ICSP-5 RST
* SPI SS SDA(SS) 10 53 D10 10 10
* SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
*/

#include <SPI.h>
#include <MFRC522.h>

constexpr uint8_t RST_PIN = 9; // Configurable, see typical pin layout above


constexpr uint8_t SS_PIN = 10; // Configurable, see typical pin layout above

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

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
mfrc522.PCD_Init(); // Init MFRC522
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader
details
//Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}

void loop() {
// 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));
}

Rubah baris berikut untuk menghilangkan tulisan "Scan PICC to see UID, SAK, type, and data blocks..." :

Sebelum :
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));

Menjadi :
//Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));

Untuk menghilangkan versi MFR522, buka MFRC522.cpp.

Cari dan ubah fungsi “MFRC522::PCD_DumpVersionToSerial()”


Sebelum :
void MFRC522::PCD_DumpVersionToSerial() {
// Get the MFRC522 firmware version
byte v = PCD_ReadRegister(VersionReg);
Serial.print(F("Firmware Version: 0x"));
Serial.print(v, HEX);
// Lookup which version
switch(v) {
case 0x88: Serial.println(F(" = (clone)")); break;
case 0x90: Serial.println(F(" = v0.0")); break;
case 0x91: Serial.println(F(" = v1.0")); break;
case 0x92: Serial.println(F(" = v2.0")); break;
default: Serial.println(F(" = (unknown)"));
}
// When 0x00 or 0xFF is returned, communication probably failed
if ((v == 0x00) || (v == 0xFF))
Serial.println(F("WARNING: Communication failure, is the MFRC522 properly
connected?"));
} // End PCD_DumpVersionToSerial()

Sesudah :
void MFRC522::PCD_DumpVersionToSerial() {
// Get the MFRC522 firmware version
//--byte v = PCD_ReadRegister(VersionReg);
//--Serial.print(F("Firmware Version: 0x"));
//--Serial.print(v, HEX);
// Lookup which version
//--switch(v) {
//-- case 0x88: Serial.println(F(" = (clone)")); break;
//-- case 0x90: Serial.println(F(" = v0.0")); break;
//-- case 0x91: Serial.println(F(" = v1.0")); break;
//-- case 0x92: Serial.println(F(" = v2.0")); break;
//-- default: Serial.println(F(" = (unknown)"));
//--}
// When 0x00 or 0xFF is returned, communication probably failed
//--if ((v == 0x00) || (v == 0xFF))
//-- Serial.println(F("WARNING: Communication failure, is the MFRC522 properly
connected?"));
} // End PCD_DumpVersionToSerial()
Hasil scan kartu RFID :

Dalam skenario ini, kita hanya akan menampilkan tulisan yang hanya dalam kotak merah saja.

Kita akan menghilangkan tulisan “Card UID :”. Masih dalam file MFRC522.cpp.

Cari fungsi “MFRC522::PICC_DumpDetailsToSerial”

Sebelum :
Serial.print(F("Card UID:"));

Sesudah :
//Serial.print(F("Card UID:"));

Sekarang kita akan menghilangkan “Card SAK” & “PICC type”. Masih dalam file MFRC522.cpp.

Cari fungsi “MFRC522::PICC_DumpDetailsToSerial”

Sebelum :
//Serial.println();

// SAK
//Serial.print(F("Card SAK: "));
//if(uid->sak < 0x10)
// Serial.print(F("0"));
//Serial.println(uid->sak, HEX);

// (suggested) PICC type


//PICC_Type piccType = PICC_GetType(uid->sak);
//Serial.print(F("PICC type: "));
//Serial.println(PICC_GetTypeName(piccType));
Sesudah:
Serial.println();

// SAK
Serial.print(F("Card SAK: "));
if(uid->sak < 0x10)
Serial.print(F("0"));
Serial.println(uid->sak, HEX);

// (suggested) PICC type


PICC_Type piccType = PICC_GetType(uid->sak);
Serial.print(F("PICC type: "));
Serial.println(PICC_GetTypeName(piccType));

Sekarang kita akan menghilangkan Sector Block. Masih dalam file MFRC522.cpp.

Cari fungsi “MFRC522::PICC_DumpToSerial”

Sebelum :
// Dump contents

PICC_Type piccType = PICC_GetType(uid->sak);


switch (piccType) {
case PICC_TYPE_MIFARE_MINI:
case PICC_TYPE_MIFARE_1K:
case PICC_TYPE_MIFARE_4K:
// All keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}
PICC_DumpMifareClassicToSerial(uid, piccType, &key);
break;

case PICC_TYPE_MIFARE_UL:
PICC_DumpMifareUltralightToSerial();
break;

case PICC_TYPE_ISO_14443_4:
case PICC_TYPE_MIFARE_DESFIRE:
case PICC_TYPE_ISO_18092:
case PICC_TYPE_MIFARE_PLUS:
case PICC_TYPE_TNP3XXX:
Serial.println(F("Dumping memory contents not implemented for that PICC
type."));
break;
case PICC_TYPE_UNKNOWN:
case PICC_TYPE_NOT_COMPLETE:
default:
break; // No memory dump here
}

Sesudah :
// Dump contents

//PICC_Type piccType = PICC_GetType(uid->sak);


//switch (piccType) {
// case PICC_TYPE_MIFARE_MINI:
// case PICC_TYPE_MIFARE_1K:
// case PICC_TYPE_MIFARE_4K:
// // All keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
// for (byte i = 0; i < 6; i++) {
// key.keyByte[i] = 0xFF;
// }
// PICC_DumpMifareClassicToSerial(uid, piccType, &key);
// break;
//
// case PICC_TYPE_MIFARE_UL:
// PICC_DumpMifareUltralightToSerial();
// break;
//
// case PICC_TYPE_ISO_14443_4:
// case PICC_TYPE_MIFARE_DESFIRE:
// case PICC_TYPE_ISO_18092:
// case PICC_TYPE_MIFARE_PLUS:
// case PICC_TYPE_TNP3XXX:
// Serial.println(F("Dumping memory contents not implemented for that PICC
type."));
// break;

// case PICC_TYPE_UNKNOWN:
// case PICC_TYPE_NOT_COMPLETE:
// default:
// break; // No memory dump here
//}

BUAT APLIKASI VB DI WINDOWS

Buka PHPMYADMIN pada XAMPP. Buat Database database_karyawan. Lalu buat table data_karyawan.

-- phpMyAdmin SQL Dump


-- version 4.7.4
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Jan 25, 2018 at 07:23 AM
-- Server version: 10.1.30-MariaDB
-- PHP Version: 7.2.1

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";


SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `database_karyawan`
--

-- --------------------------------------------------------

--
-- Table structure for table `data_karyawan`
--

CREATE TABLE `data_karyawan` (


`uid` varchar(15) NOT NULL,
`nama` varchar(50) NOT NULL,
`jabatan` varchar(50) NOT NULL,
`status` int(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `data_karyawan`
--

INSERT INTO `data_karyawan` (`uid`, `nama`, `jabatan`, `status`) VALUES


(' 8A F7 BD 79', 'YOPI ARDINAL', 'CREATIVE', 0),
(' 7A 5D A5 B3', 'FULLAN BIN FULLAN', 'ADMIN FINANCE', 1),
(' 8A F2 E4 B6', 'BUDY SETYAWATI', 'MENTERI DALAM NEGERI', 1);
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;


/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

Download dan Install MySQL ODBC Connector dari link :


https://dev.mysql.com/downloads/connector/odbc/

Buat ODBC data source. Buka ODBC Data Source Administrator. Klik Add..
Pilih MySQL ODBC 5.3 ANSI DRIVER, Klik Finish

Masukkan data seperti dibawah ini :


Buka VB6. Buat sebuah project. Buka Reference. Contreng Microsoft ActiveX Data Object.
Buat sebuah Form.

Masukkan code :

Dim db As Connection
Dim rs As Recordset

Sub koneksi()
Set db = New Connection
db.CursorLocation = adUseClient
db.Open "database_karyawan"
End Sub

Private Sub cmdConnect_Click()

If MSComm1.PortOpen = False Then


MSComm1.CommPort = Int(Text1.Text)
MSComm1.RThreshold = 14
MSComm1.InputLen = 14
MSComm1.Settings = Text2.Text & ",N,8,1"
MSComm1.PortOpen = True
cmdConnect.Enabled = False
cmdDisconnect.Enabled = True
Timer1.Enabled = True
End If

List1.Clear

End Sub

Private Sub cmdDisconnect_Click()


If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
Timer1.Enabled = False
cmdConnect.Enabled = True
cmdDisconnect.Enabled = False

End Sub

Private Sub DataGrid1_Click()


Text4.Text = DataGrid1.Columns(0).Text
Text5.Text = DataGrid1.Columns(1).Text
Text6.Text = DataGrid1.Columns(2).Text
End Sub

Private Sub Form_Click()


List1.Clear
End Sub

Private Sub Form_Load()

koneksi
Set rs = New Recordset
rs.Open "select * from data_karyawan", db, adOpenDynamic, adLockOptimistic
Set DataGrid1.DataSource = rs
DataGrid1.Refresh

End Sub

Private Sub List1_Click()


Call caridata
End Sub

Private Sub MSComm1_OnComm()


Dim data As String
If MSComm1.CommEvent = comEvReceive Then
data = MSComm1.Input
Text3.Text = data
If Len(Text3.Text) > 0 Then
List1.AddItem Text3.Text
List1.ListIndex = List1.ListCount - 1

End If

End If
End Sub

Private Sub Text3_Change()


Call caridata
End Sub

Private Sub Timer1_Timer()


MSComm1_OnComm
End Sub

Private Sub caridata()


Set rs = New ADODB.Recordset
If rs.State = adStateOpen Then
rs.Close
Set rs = New ADODB.Recordset
End If

rs.CursorLocation = adUseClient
stringcari = Replace(List1.Text, vbNewLine, "")
rs.Open "update data_karyawan set status=1 where uid = '" & stringcari & "'", db,
adOpenDynamic, adLockOptimistic

rs.Open "select * from data_karyawan where uid = '" & stringcari & "'", db, adOpenDynamic,
adLockOptimistic
Set DataGrid1.DataSource = rs
DataGrid1.Refresh
End Sub

Potrebbero piacerti anche