RFID using pn532 in circuit python

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
lerosser
 
Posts: 5
Joined: Mon Jul 13, 2020 10:38 am

RFID using pn532 in circuit python

Post by lerosser »

Hello,

I have been trying to implement the pn532 module in circuit python using a Feather M0 express board designed for circuit python. I am getting a "memory error: memory allocation failed, ....". I am using the PN532 library, which is all .py files. I understand that .mpy take up less memory and might solve my problem. I can't seem to find the .mpy versions, and it seems rather complicated to try and generate them. Can someone point me to a source for these files?

thanks

Leigh

User avatar
tannewt
 
Posts: 3304
Joined: Thu Oct 06, 2016 8:48 pm

Re: RFID using pn532 in circuit python

Post by tannewt »

Hi Leigh, the mpy versions should be available in the bundle: https://github.com/adafruit/Adafruit_Ci ... ses/latest

If that still has the problem, could you please post your complete code.py here in CODE tags? That way we can suggest improvements.

User avatar
lerosser
 
Posts: 5
Joined: Mon Jul 13, 2020 10:38 am

Re: RFID using pn532 in circuit python

Post by lerosser »

Excellent, thanks so much for the prompt reply. The code is now running for the pn532_simpletest.py example file.

I was wondering if you could point me to any example circuitpython files that use an RIFD tag to trigger the play back of sound files? I want to have maybe five unique sound files and corresponding rfid tags that trigger them. Will be using the PN532 breakoutboard, a Feather M0 express and a Audio FX sound board.

thanks for any assistance you can offer.

Regards,
Leigh

User avatar
tannewt
 
Posts: 3304
Joined: Thu Oct 06, 2016 8:48 pm

Re: RFID using pn532 in circuit python

Post by tannewt »

Unfortunately I don't know of an example that does that. I'd suggest by getting the Audio FX sound board going and then combining that code with the PN532 example.

User avatar
lerosser
 
Posts: 5
Joined: Mon Jul 13, 2020 10:38 am

Re: RFID using pn532 in circuit python

Post by lerosser »

Hello,

So have attempted to cobble together some example code to do what I want. Which is ultimately to read an RFID card and play an associated sound file. My sample code (attacted) listens for a card, reads a specific block, and checks if the data in that block is equal or not equal to a set value. It works, sort of. I get a "equal" or "not equal" to print, but then I get an error code.

Traceback (most recent call last):
File "main.py", line 26, in <module>
File "adafruit_pu532/adafruit_pn532.py", line 507, in ntag2xx_read_block
TypeError: 'NoneType' object is not subscriptable

Can anyone give me some insight on what is failing? Ultimately I will have more conditional statement to compare the block data to one of five specific IDs, and then I will play the associated sound file.

Sorry, I am not a programmer, any help would be much appreciated.
Thanks
Leigh
Attachments
main.py
(982 Bytes) Downloaded 2 times

User avatar
tannewt
 
Posts: 3304
Joined: Thu Oct 06, 2016 8:48 pm

Re: RFID using pn532 in circuit python

Post by tannewt »

Hi Leigh,
This looks like a bug in the library. It isn't handling the case where the tag isn't read correctly. The bug is here: https://github.com/adafruit/Adafruit_Ci ... 32.py#L500

I think you can call `mifare_classic_read_block(6)` directly yourself and handle if it returns None. Here is where None is returned: https://github.com/adafruit/Adafruit_Ci ... 32.py#L456

You are programming, so you are a programmer. :-) We all have more to learn.

User avatar
lerosser
 
Posts: 5
Joined: Mon Jul 13, 2020 10:38 am

Re: RFID using pn532 in circuit python

Post by lerosser »

Hello,

I am not sure if I understand. Are you saying to use the mifare_classic_read_block function instead of ntag2xx_read_block? Also I am not sure what you mean by "handle if it returns None"?

thanks

On another topic, are there programmers on this forum who offer their services for hire? I enjoy learning, but I don't enjoy banging my head against the wall ;)

Leigh

User avatar
tannewt
 
Posts: 3304
Joined: Thu Oct 06, 2016 8:48 pm

Re: RFID using pn532 in circuit python

Post by tannewt »

lerosser wrote:I am not sure if I understand. Are you saying to use the mifare_classic_read_block function instead of ntag2xx_read_block? Also I am not sure what you mean by "handle if it returns None"?
Yup! I mean you'll want to check the return value of mifare_classic_read_block before reading a portion of it.
lerosser wrote: On another topic, are there programmers on this forum who offer their services for hire? I enjoy learning, but I don't enjoy banging my head against the wall ;)

Leigh
Take a look at the jobs board: https://jobs.adafruit.com/

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”