mfdogalindo / PN532-HSU

PN532 HSU (UART) library for Python
MIT License
32 stars 17 forks source link

GPIO configuration #1

Open ryanjdillon opened 6 years ago

ryanjdillon commented 6 years ago

Does this depend upon a particular pin configuration?

According to a diagram I found for the RasberryPi 3 I am using, it seems like the following would be right

GPIO 8 > Tx (SDA) GPIO 10 > Rx (SCL)

Thanks!!!

mfdogalindo commented 6 years ago

No my friend, On RPi GPIO 10 is RX0 -> Connect to Tx(SDA), GPIO 8 (TX0) -> Rx(SCL). Maybe you need a need a shift level adapter if you use PN532 with 5V because RPi works with 3.3V logic levels.

Regards,

Manuel

img_8548r

image

ryanjdillon commented 6 years ago

Thanks for the feedback! I'll report back here once I get things working :)

ryanjdillon commented 6 years ago

With the following I can confirm that the serial device ttyAMA0 (alias serial0) is enabled:

dmesg | grep ttyAMA0

Now I don't get an error when trying to open the port, but things hang when trying to send the SAM_CONFIGURATION command. I've tried wiring the PN532 TX to RasPi GPIO 10 and RX to GPIO8, as well as the other way around, and it still hangs.

Any ideas?

Just for reference, I have the following PN532 device: https://goo.gl/q5okUF

ryanjdillon commented 6 years ago

In looking into the SAM_CONFIGURATION values (which seem correct; though perhaps the timeout should be 0xFF as suggested here , it now seems like it is hanging on the call_function() method.

SaikCaskey commented 6 years ago

I don't know if you got sorted, but when I used the pins suggested by others, it wouldn't work. I'm able to use UART and this pin configuration on my Rpi3 B:

(numbers as appear on board here: https://pinout.xyz/)

You also need to disable Bluetooth (on pi3) as it uses a slot you would otherwise use for this (sorry can't find the thing that told me to do it, but it seemed to be common advice)

ryanjdillon commented 6 years ago

I have things hooked up on

Which I imagine should be the same. I'll have time to get back to this later today or next week, and I'll let you know any details once I figure things out. Thanks a ton for the help!

ryanjdillon commented 6 years ago

So I tried the other pin layout (bluetooth disabled), and I am connected as I was before.

As things were hanging on sending the SAM_configuration command, I manually constructed the frame to write to the device and sent it via an instance of the Serial class, rather than the PN532 class, so I could get the response, then I call the next line that would be called in _ack_wait where it is hanging...

ser.write(frame)
rx_info = ''
rx_info += ser.read(ser.inWaiting())

Which yields an empty string, thus it continually looping through with ack=False.

It SEEMS like I'm communicating ok with the device when I send the wakeup command:

msg = '\x55\x55\x00\x00\x00'
hex(ser.write(msg))

Which yields '0x5', so it seems like my TX/RX is setup OK? Could it be that the data/frame aren't being constructed correctly?

Any ideas? Thanks!!!

ryanjdillon commented 6 years ago

Well... I have mysteriously fixed things.

After installing libnfc and unsuccessfully trying the ncf-poll command as described in this Adafruit tutorial: https://learn.adafruit.com/adafruit-nfc-rfid-on-raspberry-pi/testing-it-out

I unplugged and re-plugged the Tx/Rx connections on the PN532, and then it started working. My solder connections seems solid, so it must have been a crappy connection with the supplied cable from my PN532.

Thanks for all of the help everybody!

SaikCaskey commented 6 years ago

Sometimes you need to cycle the power on the PN532 I find that when I crash out of a python program (etc.) without closing the connection that I need to restart the board.

Also, you weren't doing ncf-poll right? it's *nfc-poll :P

mfdogalindo commented 6 years ago

Hello friends,

I regret not being able to help you soon, at this moment I do not have a PN532 to evaluate your problems. I suggest using a level adapter for UART, this library is evaluated with a Linux hardware with 5V logic level and RPi uses 3.3V levels.

image

ryanjdillon commented 6 years ago

Yes nfc-poll @SaikCaskey ;) and thanks for the suggestion @mfdogalindo! Things are now working well for me at the moments, so I think this one can be closed (at least for my sake).