Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

RFID using pn532 in circuit python
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

RFID using pn532 in circuit python

by lerosser on Wed Sep 02, 2020 5:02 pm

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

lerosser
 
Posts: 4
Joined: Mon Jul 13, 2020 10:38 am

Re: RFID using pn532 in circuit python

by tannewt on Wed Sep 02, 2020 6:45 pm

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.

tannewt
 
Posts: 1784
Joined: Thu Oct 06, 2016 8:48 pm

Re: RFID using pn532 in circuit python

by lerosser on Thu Sep 03, 2020 11:50 am

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

lerosser
 
Posts: 4
Joined: Mon Jul 13, 2020 10:38 am

Re: RFID using pn532 in circuit python

by tannewt on Thu Sep 03, 2020 2:19 pm

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.

tannewt
 
Posts: 1784
Joined: Thu Oct 06, 2016 8:48 pm

Re: RFID using pn532 in circuit python

by lerosser on Thu Sep 10, 2020 2:38 pm

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 1 time

lerosser
 
Posts: 4
Joined: Mon Jul 13, 2020 10:38 am

Re: RFID using pn532 in circuit python

by tannewt on Thu Sep 10, 2020 2:51 pm

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.

tannewt
 
Posts: 1784
Joined: Thu Oct 06, 2016 8:48 pm

Re: RFID using pn532 in circuit python

by lerosser on Thu Sep 10, 2020 4:13 pm

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

lerosser
 
Posts: 4
Joined: Mon Jul 13, 2020 10:38 am

Re: RFID using pn532 in circuit python

by tannewt on Fri Sep 11, 2020 3:28 pm

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/

tannewt
 
Posts: 1784
Joined: Thu Oct 06, 2016 8:48 pm

Please be positive and constructive with your questions and comments.