I am using CircuitPython on a Raspberry Pi Pico (powered via USB) connected to a PN532 via SPI, trying to get the PN532 to return its firmware version, but getting "RuntimeError: Failed to detect the PN532".
I've installed the adafruit_PN532 library folder in the CIRCUITPY: lib folder
I've connected the PN532 to the Raspberry Pi Pico as follows:
SCK - GP18
MISO - GP16
MOSI - GP19
SS - GP17
VCC - 3.3(OUT)
GND - physical pin 38
I'm using the following code:
1 import board
2 import busio
3 from digitalio import DigitalInOut
4 from adafruit_pn532.spi import PN532_SPI
5
6 spi = busio.SPI(board.GP18, MOSI=board.GP19, MISO=board.GP16)
7 cs_pin = DigitalInOut(board.GP17)
8 pn532 = PN532_SPI(spi, cs_pin, debug=False)
9
10 ic, ver, rev, support = pn532.firmware_version
11 print("Found PN532 with firmware version: {0}.{1}".format(ver, rev))
The Serial window outputs the following:
Traceback (most recent call last):
File "code.py", line 8, in <module>
File "/lib/adafruit_pn532/spi.py", line 51, in __init__
File "/lib/adafruit_pn532/adafruit_pn532.py", line 161, in __init__
File "/lib/adafruit_pn532/adafruit_pn532.py", line 342, in firmware_version
RuntimeError: Failed to detect the PN532
Any ideas as to what could be causing this failure?
Thanks for your help!
Matthew
RuntimeError: Failed to detect the PN532
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- mikeysklar
- Posts: 14182
- Joined: Mon Aug 01, 2016 8:10 pm
Re: RuntimeError: Failed to detect the PN532
You have the right pins selected on the Pico. Does it make a difference if you add the clock argument as the Pico guide suggets? You also have other SPI0 ports you could try:
If this doesn't make a difference post a photo of your wiring / soldering between the Pico and the PN532.
Code: Select all
spi = busio.SPI(clock=board.GP18, MOSI=board.GP19, MISO=board.GP16)
Code: Select all
spi = busio.SPI(clock=board.GP2, MOSI=board.GP3, MISO=board.GP4)
- Machu
- Posts: 2
- Joined: Wed Nov 16, 2022 7:57 pm
Re: RuntimeError: Failed to detect the PN532
Thank you for your help. I think there may have been a poor solder connection between the header pins and the PN532. I soldered header pins to a second PN532 I had, tried it using the same code, and everything worked. Need to improve my soldering!
Please be positive and constructive with your questions and comments.