樹莓派B 使用PN532 V3

想起之前買了個PN532設(shè)備喇澡,然后就撿起來體驗一下

PN532 V3

注意一下左上角有個模式切換開關(guān):
我這里使用的是I2C模式佣蓉,于是把開關(guān)切換成了 1 0
樹莓派三代 B

這個是我的樹莓派
樹莓派Pin腳對照

我的接線如下:(BOARD編碼)

GND -> 6 地線
VCC ->4 電源
SDA/TX  -> 2 SDA.1
SCL/RX  ->3  SCL.1

接線完成之后中間PWD有個黃色指示燈會亮

  • 安裝樹莓派上面必要的庫

 sudo apt-get install libusb-dev libpcsclite-dev          //這是libnfc依賴的庫
 sudo apt-get install automake autoconf  

如果安裝libusb-dev和libpcsclite-dev報版本錯誤安裝失敗“ Unable to correct problems, you have held broken packages.”碘举,
可執(zhí)行命令:aptitude install libusb-dev 宛裕,然后依次輸n、y涛目、y 即可赞季。

  • 安裝nfc操作模塊

wget http://dl.bintray.com/nfc-tools/sources/libnfc-1.7.1.tar.bz2
tar -xf libnfc-1.7.1.tar.bz2
cd libnfc-1.7.1
./configure --prefix=/usr --sysconfdir=/etc
make
sudo make install
  • 安裝mfoc(破解key,讀出數(shù)據(jù)到文件)

git clone https://github.com/nfc-tools/mfoc.git
cd mfoc
automake
autoconf
autoreconf -is
./configure
make && sudo make install
  • 安裝mfuck(破解全加密數(shù)據(jù))

git clone https://github.com/nfc-tools/mfcuk.git
cd mfcuk
automake
autoconf
autoreconf -is
./configure
make && sudo make install
  • 修改配置文件

cd /etc
sudo mkdir nfc
sudo nano /etc/nfc/libnfc.conf

添加下面內(nèi)容

# Allow device auto-detection (default: true)
# Note: if this auto-detection is disabled, user has to manually set a device
# configuration using file or environment variable
allow_autoscan = true
 
# Allow intrusive auto-detection (default: false)
# Warning: intrusive auto-detection can seriously disturb other devices
# This option is not recommended, so user should prefer to add manually his/her device.
allow_intrusive_scan = false
 
# Set log level (default: error)
# Valid log levels are (in order of verbosity): 0 (none), 1 (error), 2 (info), 3 (debug)
# Note: if you compiled with --enable-debug option, the default log level is "debug"
log_level = 1
 
# Manually set default device (no default)
# To set a default device, users must set both name and connstring for their device
# Note: if autoscan is enabled, default device will be the first device available in device list.
device.name = "Itead_PN532_I2C"
device.connstring = "pn532_i2c:/dev/i2c-1"

如果你的設(shè)備沒有開啟I2C肃续,則開啟一下
執(zhí)行 sudo raspi-config 黍檩,在第5項里打開i2c

保存之后重啟一下

pi@raspberrypi:~/mfoc $ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- 24 -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --     

如果輸入命令i2cdetect -y 1 返回的全部都是 -- 則沒有讀取出來數(shù)據(jù)
通過nfc-list 命令可以查看相關(guān)的結(jié)果
如果是下面這樣的

 pi@raspberrypi:~/mfoc $ nfc-list
nfc-list uses libnfc 1.7.1
error   libnfc.bus.i2c  Error: wrote only -1 bytes (10 expected).
error   libnfc.driver.pn532_i2c Unable to transmit data. (TX)
pn53x_check_communication: Input / Output Error
error   libnfc.bus.i2c  Error: wrote only -1 bytes (10 expected).
error   libnfc.driver.pn532_i2c Unable to transmit data. (TX)
nfc-list: ERROR: Unable to open NFC device: pn532_i2c:/dev/i2c-1

可能是SDA SCL線插錯了始锚,或者最開始說的模式?jīng)]有調(diào)對刽酱,調(diào)整好重插一下PN532設(shè)備就可以了
調(diào)整好之后是這樣的

pi@raspberrypi:~/mfoc $ nfc-list
nfc-list uses libnfc 1.7.1
NFC device: pn532_i2c:/dev/i2c-1 opened

這個時候往PN532上面放一張IC卡 再次輸入命令

pi@raspberrypi:~/mfoc $ nfc-list
nfc-list uses libnfc 1.7.1
NFC device: pn532_i2c:/dev/i2c-1 opened
1 ISO14443A passive target(s) found:
ISO/IEC 14443A (106 kbps) target:
    ATQA (SENS_RES): 00  04  
       UID (NFCID1): 29  0f  82  73  
      SAK (SEL_RES): 08  

就能讀取到數(shù)據(jù)了

  • 讀取數(shù)據(jù)

mfoc -O output.mfd    // 讀出卡中的數(shù)據(jù)保存為文件output.mfd 

mfoc 是讀取數(shù)據(jù),如果有加密就自動破解瞧捌,如果全加密棵里,就沒法讀取,可用mfuck命令破解姐呐。

nfc-mfclassic w a  output.mfd output.mfd    //  寫入數(shù)據(jù)殿怜,w小寫,如果大寫是強寫0扇區(qū)

由于每張卡的0扇區(qū)信息(UID)不一樣曙砂,0扇區(qū)又不可寫头谜,不同的卡沒法互寫。但是可寫入0扇區(qū)可寫的UID卡鸠澈。

參考鏈接:
https://www.rabbittu.com/raspi-pn532/
https://www.cnblogs.com/panda-blog/p/9998446.html

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末乔夯,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子款侵,更是在濱河造成了極大的恐慌末荐,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,692評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件新锈,死亡現(xiàn)場離奇詭異甲脏,居然都是意外死亡,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,482評論 3 392
  • 文/潘曉璐 我一進店門块请,熙熙樓的掌柜王于貴愁眉苦臉地迎上來娜氏,“玉大人,你說我怎么就攤上這事墩新∶趁郑” “怎么了?”我有些...
    開封第一講書人閱讀 162,995評論 0 353
  • 文/不壞的土叔 我叫張陵海渊,是天一觀的道長绵疲。 經(jīng)常有香客問我,道長臣疑,這世上最難降的妖魔是什么盔憨? 我笑而不...
    開封第一講書人閱讀 58,223評論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮讯沈,結(jié)果婚禮上郁岩,老公的妹妹穿的比我還像新娘。我一直安慰自己缺狠,他們只是感情好问慎,可當我...
    茶點故事閱讀 67,245評論 6 388
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著挤茄,像睡著了一般如叼。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上驮樊,一...
    開封第一講書人閱讀 51,208評論 1 299
  • 那天,我揣著相機與錄音片酝,去河邊找鬼囚衔。 笑死,一個胖子當著我的面吹牛雕沿,可吹牛的內(nèi)容都是我干的练湿。 我是一名探鬼主播,決...
    沈念sama閱讀 40,091評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼审轮,長吁一口氣:“原來是場噩夢啊……” “哼肥哎!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起疾渣,我...
    開封第一講書人閱讀 38,929評論 0 274
  • 序言:老撾萬榮一對情侶失蹤篡诽,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后榴捡,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體杈女,經(jīng)...
    沈念sama閱讀 45,346評論 1 311
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,570評論 2 333
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了达椰。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片翰蠢。...
    茶點故事閱讀 39,739評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖啰劲,靈堂內(nèi)的尸體忽然破棺而出梁沧,到底是詐尸還是另有隱情,我是刑警寧澤蝇裤,帶...
    沈念sama閱讀 35,437評論 5 344
  • 正文 年R本政府宣布廷支,位于F島的核電站,受9級特大地震影響猖辫,放射性物質(zhì)發(fā)生泄漏酥泞。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,037評論 3 326
  • 文/蒙蒙 一啃憎、第九天 我趴在偏房一處隱蔽的房頂上張望芝囤。 院中可真熱鬧,春花似錦辛萍、人聲如沸悯姊。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,677評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽悯许。三九已至,卻和暖如春辉阶,著一層夾襖步出監(jiān)牢的瞬間先壕,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,833評論 1 269
  • 我被黑心中介騙來泰國打工谆甜, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留垃僚,地道東北人。 一個月前我還...
    沈念sama閱讀 47,760評論 2 369
  • 正文 我出身青樓规辱,卻偏偏與公主長得像谆棺,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子罕袋,可洞房花燭夜當晚...
    茶點故事閱讀 44,647評論 2 354

推薦閱讀更多精彩內(nèi)容