MicroPython with adafruit-circuitpython-pn532 / CircuitPython on ESP32
MicroPython with adafruit-circuitpython-pn532 / CircuitPython on ESP32
Hi all,
I want to use micropython with PN532. I found the adafruit-circuitpython-pn532 lib @ adafruit and found out that the current version of circuitpython does not run on ESP32 anymore. Now I have the following questions:
1) Is it somehow possible to patch and run the current version of CircuitPython on ESP32?
2) Is it possible to run the libraries from adafruit with MicroPython?
I want to use micropython with PN532. I found the adafruit-circuitpython-pn532 lib @ adafruit and found out that the current version of circuitpython does not run on ESP32 anymore. Now I have the following questions:
1) Is it somehow possible to patch and run the current version of CircuitPython on ESP32?
2) Is it possible to run the libraries from adafruit with MicroPython?
Re: MicroPython with adafruit-circuitpython-pn532 / CircuitPython on ESP32
Option 2) seems to be the easy way. Looking into the driver code, you just have to adapt the calls for GPIO and SPI, and maybe some delay calls (e.g. a busy_wait functions). I have ported adafruit libraries a few times, and it was not difficult.
Re: MicroPython with adafruit-circuitpython-pn532 / CircuitPython on ESP32
Hi, I've actually done this (option 2) but I forgot to post that to the drivers forum section.
Here is the repo: https://github.com/Carglglz/NFC_PN532_SPI
Here is the repo: https://github.com/Carglglz/NFC_PN532_SPI
Re: MicroPython with adafruit-circuitpython-pn532 / CircuitPython on ESP32
I just tried your code without luck:cgglzpy wrote: ↑Sun Oct 27, 2019 5:36 pmHi, I've actually done this (option 2) but I forgot to post that to the drivers forum section.
Here is the repo: https://github.com/Carglglz/NFC_PN532_SPI
>> import NFC_PN532 as nfc
>>> from machine import Pin, SPI
>>> spi_dev = SPI(1, baudrate=1000000)
>>> cs = Pin(5, Pin.OUT)
>>> cs.on()
>>> pn532 = nfc.PN532(spi_dev,cs)
>>> ic, ver, rev, support = pn532.get_firmware_version()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "NFC_PN532.py", line 294, in get_firmware_version
RuntimeError: Failed to detect the PN532
Do you know if it also work with Elechouse board also known as "PN532 NFC-RFID V3 NFC-Modul" cheap board that is available @ ebay for $5)?
Is it possible to configure the SPI Pins?
#define PN532_SCK (18)
#define PN532_MOSI (23)
#define PN532_SS (5)
#define PN532_MISO (19)
Re: MicroPython with adafruit-circuitpython-pn532 / CircuitPython on ESP32
RTFM helps
>>> import NFC_PN532 as nfc
>>> from machine import Pin, SPI
>>> spi_dev = SPI(2, baudrate=1000000, sck=Pin(18), mosi=Pin(23), miso=Pin(19))
>>> cs = Pin(5, Pin.OUT)
>>> cs.on()
>>> pn532 = nfc.PN532(spi_dev,cs)
>>> ic, ver, rev, support = pn532.get_firmware_version()
>>> print('Found PN532 with firmware version: {0}.{1}'.format(ver, rev))
Found PN532 with firmware version: 1.6
>>> import NFC_PN532 as nfc
>>> from machine import Pin, SPI
>>> spi_dev = SPI(2, baudrate=1000000, sck=Pin(18), mosi=Pin(23), miso=Pin(19))
>>> cs = Pin(5, Pin.OUT)
>>> cs.on()
>>> pn532 = nfc.PN532(spi_dev,cs)
>>> ic, ver, rev, support = pn532.get_firmware_version()
>>> print('Found PN532 with firmware version: {0}.{1}'.format(ver, rev))
Found PN532 with firmware version: 1.6
Re: MicroPython with adafruit-circuitpython-pn532 / CircuitPython on ESP32
You can assign the Pin as you like. See http://docs.micropython.org/en/latest/l ... hlight=spi
To match with the defines you referenced, it would for instance be:
To match with the defines you referenced, it would for instance be:
Code: Select all
spi_dev = SPI(2, baudrate=1000000, sck=Pin(18), mosi=Pin(23), miso=Pin(19))
cs = Pin(5, Pin.OUT)
Re: MicroPython with adafruit-circuitpython-pn532 / CircuitPython on ESP32
@rena2019 To be honest, the manual is confusing, as it mixes information for different boards, which not work on all boards.
Re: MicroPython with adafruit-circuitpython-pn532 / CircuitPython on ESP32
@roberthh thanks for the reply. The first command pn532.get_firmware_version() works now for me. See also my previous post.
I think I now have to modify some "delay calls" because the communication seems to be instable:
>>> print(pn532.read_passive_target(timeout=500))
None
>>> print(pn532.read_passive_target(timeout=500))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "NFC_PN532.py", line 320, in read_passive_target
File "NFC_PN532.py", line 316, in read_passive_target
File "NFC_PN532.py", line 280, in call_function
File "NFC_PN532.py", line 248, in _read_frame
RuntimeError: ('Response checksum did not match expected value: ', 36)
I think I now have to modify some "delay calls" because the communication seems to be instable:
>>> print(pn532.read_passive_target(timeout=500))
None
>>> print(pn532.read_passive_target(timeout=500))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "NFC_PN532.py", line 320, in read_passive_target
File "NFC_PN532.py", line 316, in read_passive_target
File "NFC_PN532.py", line 280, in call_function
File "NFC_PN532.py", line 248, in _read_frame
RuntimeError: ('Response checksum did not match expected value: ', 36)
Re: MicroPython with adafruit-circuitpython-pn532 / CircuitPython on ESP32
Hi, there is a 'debug' option
It may help you to 'fine-tuning' the time delays in the read/write methods...
And no, I've just tested the code with the Adafruit breakout board
Code: Select all
class PN532:
"""Driver for the PN532 connected over SPI. Pass in a hardware or bitbang
SPI device & chip select digitalInOut pin. Optional IRQ pin (not used),
reset pin and debugging output."""
def __init__(self, spi, cs_pin, irq=None, reset=None, debug=False):
And no, I've just tested the code with the Adafruit breakout board
Re: MicroPython with adafruit-circuitpython-pn532 / CircuitPython on ESP32
I'm pretty new to programming in general but is working on a solution to emulate different kinds of Mifare-tags to be read by external Mifare readers.
I have a Pycom MCU and from what I'm reading the PN532 should make it possible to emulate a Mifare Classic UID tag. Is this correct? Also I'm wondering which function I should call in the library and if you have any more information on how it works?
The idea is to send a pre-defined UID number to the Pycom and have it forward it through the PN532 to be read by an external reader.
I have a Pycom MCU and from what I'm reading the PN532 should make it possible to emulate a Mifare Classic UID tag. Is this correct? Also I'm wondering which function I should call in the library and if you have any more information on how it works?
The idea is to send a pre-defined UID number to the Pycom and have it forward it through the PN532 to be read by an external reader.