gassajor000 / pn532pi

Python interface for ndef communication using PN532 chip on raspberry pi
36 stars 18 forks source link

[BUG] - Allow adjusting SPI bus speed to fix buggy pn532 modules #17

Closed ebradbury closed 5 months ago

ebradbury commented 6 months ago

What happened?

Many people appear to be struggling to get the pn532 module to work over SPI (myself included). I'm using the elechous pn532 v3 with a rpi 5. I was only able to get it to work by decreasing the SPI bus speed in a rather hacky way.

The solution for me was adding nfc._interface._spi.max_speed_hz = 100000 after nfc.begin(). Otherwise the device would never connect.

Hope that helps someone. Maybe we can make 100kz the default speed or provide an option to adjust the speed in the constructor?

Reproducibility

Always (100% of runs)

Steps to Reproduce

  1. Connect elechous pn532 v3 module to rpi 5 SPI
  2. Run SPI example
  3. See that device is not detected

Code to reproduce

# Use examples/iso14443a_uid.py

Host Controller

Raspberry Pi 5

Python Version

3.11.2

Interface Mode

SPI

Power Supply

Pi 3.3v or 5v

Additional Context

No response

gassajor000 commented 5 months ago

Yes that does seem to be an oversight in the original arduino library. I'll can push a patch to specify a bus speed. 100 KHz seems like a pretty significant speed reduction though. Have you tried anything between 1 and 5 MHz?

gassajor000 commented 5 months ago

Haven't heard anything back so I am just going to lower the default speed to 4 MHz.

ebradbury commented 5 months ago

Thanks for adjusting this!