dwyl / smart-home-security-system

Smart Home Security System
GNU General Public License v2.0
4 stars 2 forks source link

How do we connect the PN532 NFC chip to the Raspberry Pi? #5

Closed th0mas closed 4 years ago

th0mas commented 4 years ago

We have several options to connect our PN532 development board to the Raspberry Pi:

We need to work out which one of these communication protocols to use and if there's any (meaningful) difference between them for our use case. The manufacturer seems to suggest SPI, but I can't find a concrete recommendation from them.

We also need to find an Elixir library that can communicate with the NFC chip and see how this would work.

th0mas commented 4 years ago

Adafruit seems to suggest that with the Raspberry Pi SPI is the way to go:

Screenshot 2020-07-06 at 09 50 33
th0mas commented 4 years ago

I (think) I've managed to connect the Raspberry Pi to the board using a wiki found here: http://wiki.sunfounder.cc/index.php?title=PN532_NFC_Module_for_Raspberry_Pi.

It has a simple table which tells you what pins on the pi to connect to the pins on the NFC board.

th0mas commented 4 years ago

Finding a maintained elixir library is proving to be difficult.

https://github.com/arjan/nerves_io_nfc no longer compiles and https://github.com/jmerriweather/nerves_io_pn532 seems to be lacking documentation

th0mas commented 4 years ago

@nelsonic How do you think we should get round this? I'm not feeling like rolling my own PN532 interface library - but it is always an option. I'll look at writing a NIF wrapper around libnfc but I feel this will also come with some heavy drawbacks.

I've also looked at some Rust libraries to use with Rustler but these seem to suffer the same drawbacks as the Native Elixir libraries

th0mas commented 4 years ago

I've looked through https://github.com/jmerriweather/nerves_io_pn532 and I think its our best option.

I'll try and write documentation and fix any bugs as I go.

This library also uses UART, but I think we'll just have to use it a low bandwidth (which should be fine) and hope.

Plan B is to implement Adafruit's library in Elixir https://github.com/adafruit/Adafruit_Python_PN532 which will take a while, so I want to avoid this.

th0mas commented 4 years ago

Got card recognition working over UART - sort of

Need to work out:

th0mas commented 4 years ago

Pi 0s seem to communicate over a different UART interface - ttyAMA0 so we need to account for this when deploying to Pi Zeros

th0mas commented 4 years ago

Wrote most of this down in 20fbe8d, closing this issue

nelsonic commented 4 years ago

Nice one @th0mas 🙌 thanks!