atitan / MFRC522_Ruby

MFRC522 RFID Reader Library for Raspberry Pi
MIT License
18 stars 2 forks source link

How to troubleshoot timeout error? #5

Open jamoore5 opened 4 years ago

jamoore5 commented 4 years ago

Not sure if this project is still active, stuck how to troubleshoot timeout error.

Setup is working with python code and setup

I did figure out to update nrstpd to 25 based on above setup.

Error I am seeing when running

require 'mfrc522'
require 'securerandom'

r = MFRC522.new(25)

begin
  r.picc_request(MFRC522::PICC_REQA)
  uid, sak = r.picc_select
  puts "uid: #{uid}"
rescue CommunicationError => e
  abort "Error communicating PICC: #{e.message}"
end

Error communicating PICC: status_picc_timeout

atitan commented 4 years ago

After instance initialization, the reset pin you selected (BCM25) should be in HIGH OUT, and the voltage should be detectable using a multimeter.

I suggest that you read MFRC522 version first, to ensure the SPI communication is fine.

r = MFRC522.new(25)
puts r.send(:read_spi, 0x37)

To see what the library send and receive to/from MFRC522, set the ENV variable DEBUG=1, it'll print the content in STDOUT.

jamoore5 commented 4 years ago

Thanks for the response

require 'mfrc522'
r = MFRC522.new(25)
puts r.send(:read_spi, 0x37) # 146

What is read_spi? The above command work with the rst pin unplugged. edit: looked at the code I see it says 0x37 => shows the software version

atitan commented 4 years ago

The read_spi, which is the communication wrapper in the library, is currently a private method, send is needed to access it.

Looks like your configuration is working with rst unplugged. Let me know if your had other problems.

jamoore5 commented 4 years ago

Looks like your configuration is working with rst unplugged.

Sorry if I was unclear, I was just commenting that the check for version works with both the rst pin plugged in or unplugged.

atitan commented 4 years ago

That's strange. According to datasheet, NRSTPD is the pin control whether MFRC522 is powered on or off.

jamoore5 commented 4 years ago

This is the configuration I am using

The grey cable does not seem to affect the puts r.send(:read_spi, 0x37) statement The purple and red are controlling the power.

jamoore5 commented 4 years ago

I have confirmed 3v in the rst pin when it is on.

python code works so it must be a configuration issue.

atitan commented 4 years ago

If your r.send(:read_spi, 0x37) works, then set environment variable DEBUG=1 and run the following:

r = MFRC522.new(25)
puts r.send(:communicate_with_picc, MFRC522::PCD_Transceive, MFRC522::PICC_WUPA, 0x07)

This will send wake up command to RFID card to power it up. You'll receive confirmation from the card in normal cases.

Plus, be sure to remove/place RFID card between each test, this will reset the card activation state.

atitan commented 3 years ago

@jamoore5 I've increased the overall stability by rewritten the SPI communication part of the library. If you would like to try, enable SPI linux driver and use mfrc522 3.0.0.