Closed xetum closed 7 years ago
Hi,
Looks like your pin connection is correct.
Can you tell me what the exception message is?
Oops, I found you had put it in the title.
As I didn't put debug mode in the code, please use the following code to mokeypatch and see what's wrong with the communication.
class MFRC522
alias_method :old_communicate_with_picc, :communicate_with_picc
private
def communicate_with_picc(command, send_data, framing_bit = 0)
status, received_data, valid_bits = old_communicate_with_picc(command, send_data, framing_bit)
p "Status: #{status}"
p "Received_data: #{received_data}"
p "Valid_bits: #{valid_bits}"
return status, received_data, valid_bits
end
end
pi@raspberrypi:~ $ sudo ruby rfid/rc522/mifare.rb "Status: status_ok" "Received_data: []" "Valid_bits: 0" true"Status: status_ok" "Received_data: []" "Valid_bits: 0" /var/lib/gems/2.1.0/gems/mfrc522-1.0.5/lib/mfrc522.rb:301:in `block (2 levels) in picc_select': Received empty UID data (UnexpectedDataError)
from /var/lib/gems/2.1.0/gems/mfrc522-1.0.5/lib/mfrc522.rb:254:in times' from /var/lib/gems/2.1.0/gems/mfrc522-1.0.5/lib/mfrc522.rb:254:in
block in picc_select'
from /var/lib/gems/2.1.0/gems/mfrc522-1.0.5/lib/mfrc522.rb:246:in each' from /var/lib/gems/2.1.0/gems/mfrc522-1.0.5/lib/mfrc522.rb:246:in
picc_select'
from rfid/rc522/mifare.rb:19:in `
It's a little bit weird because REQA should have returned data from PICC, but it didn't. Seems everything returned is missing.
Can you try Ruby 2.3? I didn't test my code under Ruby 2.1, not sure if it works.
Well, ruby2.3 isn't in standard repo in raspbian (only 2.1). Nonetheless I'll try. Perhaps you know the best way to install it, together with gem2.3?
You can use rvm or rbenv as version manager to install it, or just compile from source code. Gem comes with Ruby by default, you don't have to worry about how to get it.
The same happens... (2.3.4)
"Status: status_ok"
"Received_data: []"
"Valid_bits: 0"
true"Status: status_ok"
"Received_data: []"
"Valid_bits: 0"
/usr/local/lib/ruby/gems/2.3.0/gems/mfrc522-1.0.5/lib/mfrc522.rb:301:in block (2 levels) in picc_select': Received empty UID data (UnexpectedDataError) from /usr/local/lib/ruby/gems/2.3.0/gems/mfrc522-1.0.5/lib/mfrc522.rb:254:in
times'
from /usr/local/lib/ruby/gems/2.3.0/gems/mfrc522-1.0.5/lib/mfrc522.rb:254:in block in picc_select' from /usr/local/lib/ruby/gems/2.3.0/gems/mfrc522-1.0.5/lib/mfrc522.rb:246:in
each'
from /usr/local/lib/ruby/gems/2.3.0/gems/mfrc522-1.0.5/lib/mfrc522.rb:246:in picc_select' from rfid/rc522/mifare.rb:19:in
Something more that I can try?
The last thing we can try is inspecting the SPI communication.
class MFRC522
alias_method :old_read_spi, :read_spi
alias_method :old_write_spi, :write_spi
private
def read_spi(reg)
data = old_read_spi(reg)
p "Read_SPI: addr=0x#{reg.to_s(16).rjust(2,'0').upcase} data=#{data}"
data
end
def write_spi(reg, values)
p "Write_SPI: addr=0x#{reg.to_s(16).rjust(2,'0').upcase} data=#{values}"
old_write_spi(reg, values)
end
end
"Write_SPI: addr=0x01 data=15"
"Write_SPI: addr=0x2A data=135"
"Write_SPI: addr=0x2B data=255"
"Write_SPI: addr=0x15 data=64"
"Write_SPI: addr=0x11 data=61"
"Read_SPI: addr=0x0E data=208"
"Write_SPI: addr=0x0E data=80"
"Write_SPI: addr=0x12 data=0"
"Read_SPI: addr=0x12 data=0"
"Write_SPI: addr=0x13 data=0"
"Read_SPI: addr=0x13 data=0"
"Write_SPI: addr=0x2C data=1"
"Write_SPI: addr=0x2D data=0"
"Read_SPI: addr=0x2C data=0"
"Read_SPI: addr=0x2D data=0"
"Read_SPI: addr=0x14 data=192"
"Write_SPI: addr=0x14 data=195"
"Read_SPI: addr=0x0E data=16"
"Write_SPI: addr=0x0E data=16"
"Write_SPI: addr=0x12 data=0"
"Read_SPI: addr=0x12 data=0"
"Write_SPI: addr=0x13 data=0"
"Read_SPI: addr=0x13 data=0"
"Write_SPI: addr=0x2C data=1"
"Write_SPI: addr=0x2D data=0"
"Read_SPI: addr=0x2C data=0"
"Read_SPI: addr=0x2D data=0"
"Write_SPI: addr=0x01 data=0"
"Write_SPI: addr=0x04 data=127"
"Read_SPI: addr=0x0A data=0"
"Write_SPI: addr=0x0A data=128"
"Write_SPI: addr=0x09 data=38"
"Write_SPI: addr=0x0D data=7"
"Write_SPI: addr=0x01 data=12"
"Read_SPI: addr=0x0D data=3"
"Write_SPI: addr=0x0D data=131"
"Read_SPI: addr=0x04 data=34"
"Read_SPI: addr=0x06 data=0"
"Read_SPI: addr=0x0A data=0"
"Read_SPI: addr=0x0C data=8"
"Status: status_ok"
"Received_data: []"
"Valid_bits: 0"
true"Read_SPI: addr=0x0E data=16"
"Write_SPI: addr=0x0E data=16"
"Write_SPI: addr=0x12 data=0"
"Read_SPI: addr=0x12 data=0"
"Write_SPI: addr=0x13 data=0"
"Read_SPI: addr=0x13 data=0"
"Write_SPI: addr=0x2C data=1"
"Write_SPI: addr=0x2D data=0"
"Read_SPI: addr=0x2C data=0"
"Read_SPI: addr=0x2D data=0"
"Write_SPI: addr=0x01 data=0"
"Write_SPI: addr=0x04 data=127"
"Read_SPI: addr=0x0A data=0"
"Write_SPI: addr=0x0A data=128"
"Write_SPI: addr=0x09 data=[147, 32]"
"Write_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x01 data=12"
"Read_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x0D data=128"
"Read_SPI: addr=0x04 data=2"
"Read_SPI: addr=0x04 data=34"
"Read_SPI: addr=0x06 data=0"
"Read_SPI: addr=0x0A data=0"
"Read_SPI: addr=0x0C data=8"
"Status: status_ok"
"Received_data: []"
"Valid_bits: 0"
/usr/local/lib/ruby/gems/2.3.0/gems/mfrc522-1.0.5/lib/mfrc522.rb:301:in block (2 levels) in picc_select': Received empty UID data (UnexpectedDataError) from /usr/local/lib/ruby/gems/2.3.0/gems/mfrc522-1.0.5/lib/mfrc522.rb:254:in
times'
from /usr/local/lib/ruby/gems/2.3.0/gems/mfrc522-1.0.5/lib/mfrc522.rb:254:in block in picc_select' from /usr/local/lib/ruby/gems/2.3.0/gems/mfrc522-1.0.5/lib/mfrc522.rb:246:in
each'
from /usr/local/lib/ruby/gems/2.3.0/gems/mfrc522-1.0.5/lib/mfrc522.rb:246:in picc_select' from rfid/rc522/mifare.rb:35:in
ComIrqReg changes during transceiving indicates that SPI communication and MFRC522's command IRQ are fine.
"Read_SPI: addr=0x04 data=2"
"Read_SPI: addr=0x04 data=34"
However, FIFO level reported by the module is 0, means nothing is in the FIFO buffer.
"Read_SPI: addr=0x0A data=0"
I can't see anything wrong with your setup. Maybe you can try initialize with a slower SPI clock:
r = MFRC522.new(nrstpd = 24, chip = 0, spd = 100000, timer = 256)
When using pi-rc522 all works well: pi@raspberrypi:~ $ python rfid/rc522/UtilExample.py
Detected Card read UID: 197,204,53,138 which is the 32bit UID in little endian format.
UtilExample.py code:
#!/usr/bin/env python
import signal
import time
import RPi.GPIO as GPIO
from pirc522 import RFID
GPIO.setwarnings(False)
rdr = RFID()
util = rdr.util()
#Set util debug to true - it will print what's going on
#util.debug = True
#Wait for tag
rdr.wait_for_tag()
#print('detected')
#Request tag
(error, data) = rdr.request()
if not error:
print("\nDetected")
(error, uid) = rdr.anticoll()
if not error:
# Print UID
print("Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3]))
`
If I initalize with r = MFRC522.new(nrstpd = 24, chip = 0, spd = 100000, timer = 256)
I get
pi@raspberrypi:~ $ sudo /usr/local/bin/ruby rfid/rc522/mifare.rb
"Write_SPI: addr=0x01 data=15"
/usr/local/lib/ruby/gems/2.3.0/gems/pi_piper-2.0.0/lib/pi_piper/spi.rb:80:in `spi_clock': no implicit conversion from nil to integer (TypeError)
from /usr/local/lib/ruby/gems/2.3.0/gems/pi_piper-2.0.0/lib/pi_piper/spi.rb:80:in `clock'
from /usr/local/lib/ruby/gems/2.3.0/gems/mfrc522-1.0.5/lib/mfrc522.rb:510:in `block in write_spi'
from /usr/local/lib/ruby/gems/2.3.0/gems/pi_piper-2.0.0/lib/pi_piper/spi.rb:40:in `begin'
from /usr/local/lib/ruby/gems/2.3.0/gems/mfrc522-1.0.5/lib/mfrc522.rb:507:in `write_spi'
from rfid/rc522/mifare.rb:29:in `write_spi'
from /usr/local/lib/ruby/gems/2.3.0/gems/mfrc522-1.0.5/lib/mfrc522.rb:126:in `soft_reset'
from /usr/local/lib/ruby/gems/2.3.0/gems/mfrc522-1.0.5/lib/mfrc522.rb:117:in `initialize'
from rfid/rc522/mifare.rb:32:in `new'
from rfid/rc522/mifare.rb:32:in `<main>'
Maybe you can compare SPI communications between these two programs to see what's the difference.
My bad. Pi_Piper has constants for SPI clock. Try 125000 instead.
Now it works!!! Thanks for your excellent technical support!
"Valid_bits: 0"
"Write_SPI: addr=0x01 data=0"
"Write_SPI: addr=0x04 data=127"
"Read_SPI: addr=0x0A data=0"
"Write_SPI: addr=0x0A data=128"
"Write_SPI: addr=0x09 data=[147, 32]"
"Write_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x01 data=12"
"Read_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x0D data=128"
"Read_SPI: addr=0x04 data=100"
"Read_SPI: addr=0x06 data=0"
"Read_SPI: addr=0x0A data=5"
"Read_SPI: addr=0x09 data=197"
"Read_SPI: addr=0x09 data=204"
"Read_SPI: addr=0x09 data=53"
"Read_SPI: addr=0x09 data=138"
"Read_SPI: addr=0x09 data=182"
"Read_SPI: addr=0x0C data=16"
"Status: status_ok"
"Received_data: [197, 204, 53, 138, 182]"
"Valid_bits: 0"
/usr/local/lib/ruby/gems/2.3.0/gems/mfrc522-1.0.5/lib/mfrc522.rb:350:in `block in picc_select': Keep receiving incomplete UID until timeout (UnexpectedDataError)
from /usr/local/lib/ruby/gems/2.3.0/gems/mfrc522-1.0.5/lib/mfrc522.rb:246:in `each'
from /usr/local/lib/ruby/gems/2.3.0/gems/mfrc522-1.0.5/lib/mfrc522.rb:246:in `picc_select'
from rfid/rc522/mifare.rb:36:in `<main>'
Received data is correct
Default 8Mhz is the fastest SPI clock MFRC522 can support, I'll lower it in future release.
Besides, the "Keep receiving incomplete UID until timeout" added in version 1.0.5 actually was not tested in real device setup. I made it only with my brain. lol Hope you can help me find out if there were bugs.
One thing that I cannot understand is that python library uses
def __init__(self, bus=0, device=0, speed=1000000, pin_rst=22,
pin_ce=0, pin_irq=18, pin_mode=GPIO.BOARD):
perhaps it works because it uses IRQ pin? Regards
Nope. The python library uses IRQ because it utilizes event handler on GPIO to find out whether MFRC522 has finished work or not.
My implementation uses SPI to read MFRC522's IRQ status. If MFRC522 finished its work, the value read from it will tell.
The main reason I think is your RC522 module doesn't support 8Mhz SPI clock, which is the max value documented. And the python library only uses 1Mhz clock.
picc_select
writes correct "Received_data: [197, 204, 53, 138, 182]" 16 times until "Keep receiving incomplete UID until timeout" is raised. Is this a bug? Do I need to use an older version than 1.0.5?
I think so.
Can you add this to /usr/local/lib/ruby/gems/2.3.0/gems/mfrc522-1.0.5/lib/mfrc522.rb
at line 265 and see how it is going?
p buffer
p dirty_buffer
pi@raspberrypi:~ $ sudo /usr/local/bin/ruby rfid/rc522/mifare.rb
"Write_SPI: addr=0x01 data=15"
"Write_SPI: addr=0x2A data=135"
"Write_SPI: addr=0x2B data=255"
"Write_SPI: addr=0x15 data=64"
"Write_SPI: addr=0x11 data=61"
"Read_SPI: addr=0x0E data=160"
"Write_SPI: addr=0x0E data=32"
"Write_SPI: addr=0x12 data=0"
"Read_SPI: addr=0x12 data=0"
"Write_SPI: addr=0x13 data=0"
"Read_SPI: addr=0x13 data=0"
"Write_SPI: addr=0x2C data=1"
"Write_SPI: addr=0x2D data=0"
"Read_SPI: addr=0x2C data=1"
"Read_SPI: addr=0x2D data=0"
"Read_SPI: addr=0x14 data=128"
"Write_SPI: addr=0x14 data=131"
"Read_SPI: addr=0x0E data=32"
"Write_SPI: addr=0x0E data=32"
"Write_SPI: addr=0x12 data=0"
"Read_SPI: addr=0x12 data=0"
"Write_SPI: addr=0x13 data=0"
"Read_SPI: addr=0x13 data=0"
"Write_SPI: addr=0x2C data=1"
"Write_SPI: addr=0x2D data=0"
"Read_SPI: addr=0x2C data=1"
"Read_SPI: addr=0x2D data=0"
"Write_SPI: addr=0x01 data=0"
"Write_SPI: addr=0x04 data=127"
"Read_SPI: addr=0x0A data=0"
"Write_SPI: addr=0x0A data=128"
"Write_SPI: addr=0x09 data=38"
"Write_SPI: addr=0x0D data=7"
"Write_SPI: addr=0x01 data=12"
"Read_SPI: addr=0x0D data=7"
"Write_SPI: addr=0x0D data=135"
"Read_SPI: addr=0x04 data=100"
"Read_SPI: addr=0x06 data=0"
"Read_SPI: addr=0x0A data=2"
"Read_SPI: addr=0x09 data=4"
"Read_SPI: addr=0x09 data=0"
"Read_SPI: addr=0x0C data=16"
"Status: status_ok"
"Received_data: [4, 0]"
"Valid_bits: 0"
true"Read_SPI: addr=0x0E data=32"
"Write_SPI: addr=0x0E data=32"
"Write_SPI: addr=0x12 data=0"
"Read_SPI: addr=0x12 data=0"
"Write_SPI: addr=0x13 data=0"
"Read_SPI: addr=0x13 data=0"
"Write_SPI: addr=0x2C data=1"
"Write_SPI: addr=0x2D data=0"
"Read_SPI: addr=0x2C data=1"
"Read_SPI: addr=0x2D data=0"
"Write_SPI: addr=0x01 data=0"
"Write_SPI: addr=0x04 data=127"
"Read_SPI: addr=0x0A data=0"
"Write_SPI: addr=0x0A data=128"
"Write_SPI: addr=0x09 data=[147, 32]"
"Write_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x01 data=12"
"Read_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x0D data=128"
"Read_SPI: addr=0x04 data=100"
"Read_SPI: addr=0x06 data=0"
"Read_SPI: addr=0x0A data=5"
"Read_SPI: addr=0x09 data=197"
"Read_SPI: addr=0x09 data=204"
"Read_SPI: addr=0x09 data=53"
"Read_SPI: addr=0x09 data=138"
"Read_SPI: addr=0x09 data=182"
"Read_SPI: addr=0x0C data=16"
"Status: status_ok"
"Received_data: [197, 204, 53, 138, 182]"
"Valid_bits: 0"
[147, 32, 197, 204, 53, 138, 182]
true
"Write_SPI: addr=0x01 data=0"
"Write_SPI: addr=0x04 data=127"
"Read_SPI: addr=0x0A data=0"
"Write_SPI: addr=0x0A data=128"
"Write_SPI: addr=0x09 data=[147, 32]"
"Write_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x01 data=12"
"Read_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x0D data=128"
"Read_SPI: addr=0x04 data=100"
"Read_SPI: addr=0x06 data=0"
"Read_SPI: addr=0x0A data=5"
"Read_SPI: addr=0x09 data=197"
"Read_SPI: addr=0x09 data=204"
"Read_SPI: addr=0x09 data=53"
"Read_SPI: addr=0x09 data=138"
"Read_SPI: addr=0x09 data=182"
"Read_SPI: addr=0x0C data=16"
"Status: status_ok"
"Received_data: [197, 204, 53, 138, 182]"
"Valid_bits: 0"
[147, 32, 197, 204, 53, 138, 182]
true
"Write_SPI: addr=0x01 data=0"
"Write_SPI: addr=0x04 data=127"
"Read_SPI: addr=0x0A data=0"
"Write_SPI: addr=0x0A data=128"
"Write_SPI: addr=0x09 data=[147, 32]"
"Write_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x01 data=12"
"Read_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x0D data=128"
"Read_SPI: addr=0x04 data=100"
"Read_SPI: addr=0x06 data=0"
"Read_SPI: addr=0x0A data=5"
"Read_SPI: addr=0x09 data=197"
"Read_SPI: addr=0x09 data=204"
"Read_SPI: addr=0x09 data=53"
"Read_SPI: addr=0x09 data=138"
"Read_SPI: addr=0x09 data=182"
"Read_SPI: addr=0x0C data=16"
"Status: status_ok"
"Received_data: [197, 204, 53, 138, 182]"
"Valid_bits: 0"
[147, 32, 197, 204, 53, 138, 182]
true
"Write_SPI: addr=0x01 data=0"
"Write_SPI: addr=0x04 data=127"
"Read_SPI: addr=0x0A data=0"
"Write_SPI: addr=0x0A data=128"
"Write_SPI: addr=0x09 data=[147, 32]"
"Write_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x01 data=12"
"Read_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x0D data=128"
"Read_SPI: addr=0x04 data=100"
"Read_SPI: addr=0x06 data=0"
"Read_SPI: addr=0x0A data=5"
"Read_SPI: addr=0x09 data=197"
"Read_SPI: addr=0x09 data=204"
"Read_SPI: addr=0x09 data=53"
"Read_SPI: addr=0x09 data=138"
"Read_SPI: addr=0x09 data=182"
"Read_SPI: addr=0x0C data=16"
"Status: status_ok"
"Received_data: [197, 204, 53, 138, 182]"
"Valid_bits: 0"
[147, 32, 197, 204, 53, 138, 182]
true
"Write_SPI: addr=0x01 data=0"
"Write_SPI: addr=0x04 data=127"
"Read_SPI: addr=0x0A data=0"
"Write_SPI: addr=0x0A data=128"
"Write_SPI: addr=0x09 data=[147, 32]"
"Write_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x01 data=12"
"Read_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x0D data=128"
"Read_SPI: addr=0x04 data=100"
"Read_SPI: addr=0x06 data=0"
"Read_SPI: addr=0x0A data=5"
"Read_SPI: addr=0x09 data=197"
"Read_SPI: addr=0x09 data=204"
"Read_SPI: addr=0x09 data=53"
"Read_SPI: addr=0x09 data=138"
"Read_SPI: addr=0x09 data=182"
"Read_SPI: addr=0x0C data=16"
"Status: status_ok"
"Received_data: [197, 204, 53, 138, 182]"
"Valid_bits: 0"
[147, 32, 197, 204, 53, 138, 182]
true
"Write_SPI: addr=0x01 data=0"
"Write_SPI: addr=0x04 data=127"
"Read_SPI: addr=0x0A data=0"
"Write_SPI: addr=0x0A data=128"
"Write_SPI: addr=0x09 data=[147, 32]"
"Write_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x01 data=12"
"Read_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x0D data=128"
"Read_SPI: addr=0x04 data=100"
"Read_SPI: addr=0x06 data=0"
"Read_SPI: addr=0x0A data=5"
"Read_SPI: addr=0x09 data=197"
"Read_SPI: addr=0x09 data=204"
"Read_SPI: addr=0x09 data=53"
"Read_SPI: addr=0x09 data=138"
"Read_SPI: addr=0x09 data=182"
"Read_SPI: addr=0x0C data=16"
"Status: status_ok"
"Received_data: [197, 204, 53, 138, 182]"
"Valid_bits: 0"
[147, 32, 197, 204, 53, 138, 182]
true
"Write_SPI: addr=0x01 data=0"
"Write_SPI: addr=0x04 data=127"
"Read_SPI: addr=0x0A data=0"
"Write_SPI: addr=0x0A data=128"
"Write_SPI: addr=0x09 data=[147, 32]"
"Write_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x01 data=12"
"Read_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x0D data=128"
"Read_SPI: addr=0x04 data=100"
"Read_SPI: addr=0x06 data=0"
"Read_SPI: addr=0x0A data=5"
"Read_SPI: addr=0x09 data=197"
"Read_SPI: addr=0x09 data=204"
"Read_SPI: addr=0x09 data=53"
"Read_SPI: addr=0x09 data=138"
"Read_SPI: addr=0x09 data=182"
"Read_SPI: addr=0x0C data=16"
"Status: status_ok"
"Received_data: [197, 204, 53, 138, 182]"
"Valid_bits: 0"
[147, 32, 197, 204, 53, 138, 182]
true
"Write_SPI: addr=0x01 data=0"
"Write_SPI: addr=0x04 data=127"
"Read_SPI: addr=0x0A data=0"
"Write_SPI: addr=0x0A data=128"
"Write_SPI: addr=0x09 data=[147, 32]"
"Write_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x01 data=12"
"Read_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x0D data=128"
"Read_SPI: addr=0x04 data=100"
"Read_SPI: addr=0x06 data=0"
"Read_SPI: addr=0x0A data=5"
"Read_SPI: addr=0x09 data=197"
"Read_SPI: addr=0x09 data=204"
"Read_SPI: addr=0x09 data=53"
"Read_SPI: addr=0x09 data=138"
"Read_SPI: addr=0x09 data=182"
"Read_SPI: addr=0x0C data=16"
"Status: status_ok"
"Received_data: [197, 204, 53, 138, 182]"
"Valid_bits: 0"
[147, 32, 197, 204, 53, 138, 182]
true
"Write_SPI: addr=0x01 data=0"
"Write_SPI: addr=0x04 data=127"
"Read_SPI: addr=0x0A data=0"
"Write_SPI: addr=0x0A data=128"
"Write_SPI: addr=0x09 data=[147, 32]"
"Write_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x01 data=12"
"Read_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x0D data=128"
"Read_SPI: addr=0x04 data=100"
"Read_SPI: addr=0x06 data=0"
"Read_SPI: addr=0x0A data=5"
"Read_SPI: addr=0x09 data=197"
"Read_SPI: addr=0x09 data=204"
"Read_SPI: addr=0x09 data=53"
"Read_SPI: addr=0x09 data=138"
"Read_SPI: addr=0x09 data=182"
"Read_SPI: addr=0x0C data=16"
"Status: status_ok"
"Received_data: [197, 204, 53, 138, 182]"
"Valid_bits: 0"
[147, 32, 197, 204, 53, 138, 182]
true
"Write_SPI: addr=0x01 data=0"
"Write_SPI: addr=0x04 data=127"
"Read_SPI: addr=0x0A data=0"
"Write_SPI: addr=0x0A data=128"
"Write_SPI: addr=0x09 data=[147, 32]"
"Write_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x01 data=12"
"Read_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x0D data=128"
"Read_SPI: addr=0x04 data=100"
"Read_SPI: addr=0x06 data=0"
"Read_SPI: addr=0x0A data=5"
"Read_SPI: addr=0x09 data=197"
"Read_SPI: addr=0x09 data=204"
"Read_SPI: addr=0x09 data=53"
"Read_SPI: addr=0x09 data=138"
"Read_SPI: addr=0x09 data=182"
"Read_SPI: addr=0x0C data=16"
"Status: status_ok"
"Received_data: [197, 204, 53, 138, 182]"
"Valid_bits: 0"
[147, 32, 197, 204, 53, 138, 182]
true
"Write_SPI: addr=0x01 data=0"
"Write_SPI: addr=0x04 data=127"
"Read_SPI: addr=0x0A data=0"
"Write_SPI: addr=0x0A data=128"
"Write_SPI: addr=0x09 data=[147, 32]"
"Write_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x01 data=12"
"Read_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x0D data=128"
"Read_SPI: addr=0x04 data=100"
"Read_SPI: addr=0x06 data=0"
"Read_SPI: addr=0x0A data=5"
"Read_SPI: addr=0x09 data=197"
"Read_SPI: addr=0x09 data=204"
"Read_SPI: addr=0x09 data=53"
"Read_SPI: addr=0x09 data=138"
"Read_SPI: addr=0x09 data=182"
"Read_SPI: addr=0x0C data=16"
"Status: status_ok"
"Received_data: [197, 204, 53, 138, 182]"
"Valid_bits: 0"
[147, 32, 197, 204, 53, 138, 182]
true
"Write_SPI: addr=0x01 data=0"
"Write_SPI: addr=0x04 data=127"
"Read_SPI: addr=0x0A data=0"
"Write_SPI: addr=0x0A data=128"
"Write_SPI: addr=0x09 data=[147, 32]"
"Write_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x01 data=12"
"Read_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x0D data=128"
"Read_SPI: addr=0x04 data=100"
"Read_SPI: addr=0x06 data=0"
"Read_SPI: addr=0x0A data=5"
"Read_SPI: addr=0x09 data=197"
"Read_SPI: addr=0x09 data=204"
"Read_SPI: addr=0x09 data=53"
"Read_SPI: addr=0x09 data=138"
"Read_SPI: addr=0x09 data=182"
"Read_SPI: addr=0x0C data=16"
"Status: status_ok"
"Received_data: [197, 204, 53, 138, 182]"
"Valid_bits: 0"
[147, 32, 197, 204, 53, 138, 182]
true
"Write_SPI: addr=0x01 data=0"
"Write_SPI: addr=0x04 data=127"
"Read_SPI: addr=0x0A data=0"
"Write_SPI: addr=0x0A data=128"
"Write_SPI: addr=0x09 data=[147, 32]"
"Write_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x01 data=12"
"Read_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x0D data=128"
"Read_SPI: addr=0x04 data=100"
"Read_SPI: addr=0x06 data=0"
"Read_SPI: addr=0x0A data=5"
"Read_SPI: addr=0x09 data=197"
"Read_SPI: addr=0x09 data=204"
"Read_SPI: addr=0x09 data=53"
"Read_SPI: addr=0x09 data=138"
"Read_SPI: addr=0x09 data=182"
"Read_SPI: addr=0x0C data=16"
"Status: status_ok"
"Received_data: [197, 204, 53, 138, 182]"
"Valid_bits: 0"
[147, 32, 197, 204, 53, 138, 182]
true
"Write_SPI: addr=0x01 data=0"
"Write_SPI: addr=0x04 data=127"
"Read_SPI: addr=0x0A data=0"
"Write_SPI: addr=0x0A data=128"
"Write_SPI: addr=0x09 data=[147, 32]"
"Write_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x01 data=12"
"Read_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x0D data=128"
"Read_SPI: addr=0x04 data=100"
"Read_SPI: addr=0x06 data=0"
"Read_SPI: addr=0x0A data=5"
"Read_SPI: addr=0x09 data=197"
"Read_SPI: addr=0x09 data=204"
"Read_SPI: addr=0x09 data=53"
"Read_SPI: addr=0x09 data=138"
"Read_SPI: addr=0x09 data=182"
"Read_SPI: addr=0x0C data=16"
"Status: status_ok"
"Received_data: [197, 204, 53, 138, 182]"
"Valid_bits: 0"
[147, 32, 197, 204, 53, 138, 182]
true
"Write_SPI: addr=0x01 data=0"
"Write_SPI: addr=0x04 data=127"
"Read_SPI: addr=0x0A data=0"
"Write_SPI: addr=0x0A data=128"
"Write_SPI: addr=0x09 data=[147, 32]"
"Write_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x01 data=12"
"Read_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x0D data=128"
"Read_SPI: addr=0x04 data=100"
"Read_SPI: addr=0x06 data=0"
"Read_SPI: addr=0x0A data=5"
"Read_SPI: addr=0x09 data=197"
"Read_SPI: addr=0x09 data=204"
"Read_SPI: addr=0x09 data=53"
"Read_SPI: addr=0x09 data=138"
"Read_SPI: addr=0x09 data=182"
"Read_SPI: addr=0x0C data=16"
"Status: status_ok"
"Received_data: [197, 204, 53, 138, 182]"
"Valid_bits: 0"
[147, 32, 197, 204, 53, 138, 182]
true
"Write_SPI: addr=0x01 data=0"
"Write_SPI: addr=0x04 data=127"
"Read_SPI: addr=0x0A data=0"
"Write_SPI: addr=0x0A data=128"
"Write_SPI: addr=0x09 data=[147, 32]"
"Write_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x01 data=12"
"Read_SPI: addr=0x0D data=0"
"Write_SPI: addr=0x0D data=128"
"Read_SPI: addr=0x04 data=100"
"Read_SPI: addr=0x06 data=0"
"Read_SPI: addr=0x0A data=5"
"Read_SPI: addr=0x09 data=197"
"Read_SPI: addr=0x09 data=204"
"Read_SPI: addr=0x09 data=53"
"Read_SPI: addr=0x09 data=138"
"Read_SPI: addr=0x09 data=182"
"Read_SPI: addr=0x0C data=16"
"Status: status_ok"
"Received_data: [197, 204, 53, 138, 182]"
"Valid_bits: 0"
[147, 32, 197, 204, 53, 138, 182]
true
/usr/local/lib/ruby/gems/2.3.0/gems/mfrc522-1.0.5/lib/mfrc522.rb:351:in block in picc_select': Keep receiving incomplete UID until timeout (UnexpectedDataError) from /usr/local/lib/ruby/gems/2.3.0/gems/mfrc522-1.0.5/lib/mfrc522.rb:246:in
each'
from /usr/local/lib/ruby/gems/2.3.0/gems/mfrc522-1.0.5/lib/mfrc522.rb:246:in picc_select' from rfid/rc522/mifare.rb:38:in
buffer -> [147, 32, 197, 204, 53, 138, 182] dirty_buffer -> true ...sixteen times
I've made a fix to this situation, you can download https://raw.githubusercontent.com/atitan/MFRC522_Ruby/master/lib/mfrc522.rb
and replace the file at /usr/local/lib/ruby/gems/2.3.0/gems/mfrc522-1.0.5/lib/mfrc522.rb
.
Besides, the anti-collision algorithm is also improved. You can try using two or three RFID tags at the same time to test it.
it works, thanks!
version 1.0.6 released.
Hello, my connections are: MFRC522 physical RPI3 pin sda 24 sck 23 mosi 19 miso 21 irq not connected gnd 6 rst 18 3.3V 1
and my test script:
require 'mfrc522' r = MFRC522.new print(r.picc_request(MFRC522::PICC_REQA)) # returns true uid, sak = r.picc_select # always raises UnexpectedDataError
However, it works well with pi-rc522 (python), changing connections irq 18 rst 22