mattjlewis / diozero

Java Device I/O library that is portable across Single Board Computers and microcontrollers. Tested with Raspberry Pi, Odroid C2, BeagleBone Black, Next Thing CHIP, Asus Tinker Board and Arduinos / Pico. Supports GPIO, I2C, SPI as well as Serial communication. Also known to work with Udoo Quad.
https://www.diozero.com
MIT License
263 stars 59 forks source link

MFRC522, setAntennaGain(..) has no effect #71

Closed lglowania closed 3 years ago

lglowania commented 3 years ago

I'm trying to increase the reading-range of my MFRC522. By using MFRC522.getPiccType(sak); i determined my picc is a MIFARE_1K. The data sheet (https://www.mouser.com/datasheet/2/302/MF1S503x-89574.pdf) says:

Operating distance up to 100 mm depending on antenna geometry and reader configuration

So i assume the antenna gain setting is available in general. But using mfrc522.setAntennaGain(..) seems to do nothing, the reading-range remains at ~20mm, no matter what AntennaGain-enum is passed. And mfrc522.getAntennaGain() returns always null.

Do you have a hint? Thank you.

mattjlewis commented 3 years ago

There is a simple bug when retrieving the antenna gain - the value is contained in bits 4:6 and I am not doing a bit shift in the AntennaGain.forValue method. I will push 1.2.3 tonight that includes this fix - this will at least allow you to verify that the config register is being updated correctly. Reading this it would appear that the antenna gain has to be set before turning on the antenna (and possibly some other configuration) - I have included another change that allows the gain to be specified in the constructor. It would be great if you could test this as I don't have one wired up right now.

mattjlewis commented 3 years ago

Please test with 1.2.3 and let me know if it fixes the issue.

lglowania commented 3 years ago

Yes, getAntennaGain() now returns the expected result.

mattjlewis commented 3 years ago

Excellent, thank you. Did it make a difference in range?

lglowania commented 3 years ago

Sorry for the late response. I had no time to investigate further. In my experiments it did not make any difference in range, but when i used mfrc522.setAntennaGain(AntennaGain.DB_48) i frequently received read errors when placing the transponder. I don't remember exactly the error-output. It was something like read error on 0x01. I will comment my insights here in the future.