Skip to content

Commit 62cb5db

Browse files
authored
Merge pull request #18 from bofh69/cleanup
Cleanup
2 parents 6e63bc1 + ad02f02 commit 62cb5db

File tree

3 files changed

+53
-47
lines changed

3 files changed

+53
-47
lines changed

README.md

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ SPDX-FileCopyrightText: 2026 PN5180-tagomatic contributors
55
SPDX-License-Identifier: GPL-3.0-or-later
66
-->
77

8-
**This is a work in progress. Some things described here doesn't work yet,
9-
and bug reports are not welcome at this time.**
10-
118
USB based RFID reader with Python interface
129

1310
[![Python CI](https://github.com/bofh69/PN5180-tagomatic/workflows/Python%20CI/badge.svg)](https://github.com/bofh69/PN5180-tagomatic/actions)
@@ -22,10 +19,17 @@ Frontend module and a Raspberry Pi Pico (Zero).
2219

2320
## Features
2421

25-
- Python library for easy integration
26-
- Raspberry Pi Pico firmware for PN5180 NFC module
27-
- USB serial communication
28-
- Cross-platform support (Linux, Windows, macOS)
22+
- Python library for easy integration.
23+
- Uses USB serial communication to the reader.
24+
- Cross-platform support (Linux, Windows, macOS).
25+
- Finds and selects single ISO/IEC 14443 cards.
26+
- Uses NFC FORUM commands to read/write 14443-A cards' memories.
27+
- Can authenticate against Mifare classic cards to read their memories.
28+
- Finds ISO/IEC 15693 cards, uses 15693-3 commands to read/write their memories.
29+
30+
Multiple cards in the RFID field is currently not really supported,
31+
the hardware and arduino sketch supports all commands for it.
32+
2933

3034
## Installation
3135

@@ -69,21 +73,7 @@ with PN5180("/dev/ttyACM0") as reader:
6973

7074
### Example Program
7175

72-
An example program is provided in the `examples/` directory:
73-
74-
```bash
75-
# Run the basic example
76-
python examples/basic_example.py /dev/ttyACM0
77-
78-
# On Windows
79-
python examples/basic_example.py COM3
80-
```
81-
82-
The example demonstrates:
83-
- Opening a serial connection to the device
84-
- Creating a PN5180 reader instance
85-
- Calling the reset function via SimpleRPC
86-
- Proper resource cleanup using context managers
76+
A few simple example programs are in the `examples/` directory.
8777

8878
## Development
8979

@@ -96,13 +86,13 @@ cd PN5180-tagomatic
9686

9787
# Install development dependencies
9888
pip install -e .[dev]
89+
# or:
90+
make install-dev
9991
```
10092

10193
### Running tests
10294

103-
```bash
104-
pytest
105-
```
95+
`pytest` or `make test`
10696

10797
### Code quality checks
10898

@@ -135,4 +125,5 @@ Contributions are welcome! Please ensure that:
135125
## Acknowledgments
136126

137127
This project uses FastLED by Daniel Garcia et al.
138-
It also uses SimpleRPC by Jeroen F.J. Laros, Chris Flesher et al.
128+
129+
SimpleRPC by Jeroen F.J. Laros, Chris Flesher et al is also used.

sketch/README.md

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,50 @@ SPDX-License-Identifier: GPL-3.0-or-later
66
# PN5180 RFID Reader Firmware
77

88
This directory contains the Arduino sketch for the Raspberry Pi Pico
9-
firmware that interfaces with the PN5180 NFC module.
9+
firmware that interfaces with the NXP PN5180 NFC module.
1010

1111
## Hardware Requirements
1212

1313
- USB cable for connection to host computer
14-
- Raspberry Pi Pico (the pins will need to be modified) or Raspberry Pi Pico Zero
15-
- PN5180 NFC Frontend Module card
14+
- Raspberry Pi Pico (the configured pins will then need to be modified) or a Raspberry Pi Pico Zero
15+
- NXP PN5180 NFC Frontend Module card
1616

17-
My prototype board with horrible soldering:
17+
My terrible prototype board:
1818
![Board](board.jpg)
1919

2020
## Pin Connections
2121

2222
| PN5180 Pin | Raspberry Pi Pico Zero Pin |
2323
|------------|----------------------------|
24+
| MISO | GP0 (SPI0 RX) |
2425
| NSS | GP1 |
26+
| SCK | GP2 (SPI0 SCK) |
27+
| MOSI | GP3 (SPI0 TX) |
2528
| BUSY | GP4 |
2629
| RST | GP7 |
27-
| MOSI | GP3 (SPI0 TX) |
28-
| MISO | GP0 (SPI0 RX) |
29-
| SCK | GP2 (SPI0 SCK) |
3030
| +3.3V | 3.3V |
3131
| +5V | 5V |
3232
| GND | GND |
3333
| GPIO | - |
3434
| IRQ | GP6 |
3535
| AUX | - |
36-
| REQ | - |
36+
| REQ | (GP9) |
37+
38+
The SPI interface is configured to run at 2 Mbps.
39+
It might be too fast for some hardware (depending on the cables
40+
etc). It is configured in the source code. It's possible to run
41+
at lower speeds. I first ran it at 125000 bps.
42+
43+
The code doesn't use REQ yet and as seen from the photo,
44+
I've not even connected the pin. It is used for firmware updates
45+
of the PN5180. I've not implemented that, and I probably won't.
46+
3747

3848
## Building and Uploading
3949

4050
### Prerequisites
4151

42-
The firmware requires the PN5180, FastLED and SimpleRPC libraries.
52+
The firmware requires the FastLED and SimpleRPC libraries.
4353
Install them using one of these methods:
4454

4555
**Arduino IDE:**
@@ -50,7 +60,6 @@ Install them using one of these methods:
5060
```bash
5161
arduino-cli lib install simpleRPC
5262
arduino-cli lib install FastLED
53-
arduino-cli lib install PN5180
5463
```
5564

5665
### Using Arduino IDE
@@ -61,7 +70,7 @@ arduino-cli lib install PN5180
6170
- Search for "pico" and install "Arduino Mbed OS RP2040 Boards by Arduino" (version 4.4.1 was used).
6271
3. Install the libraries (see Prerequisites above)
6372
4. Press the select board pulldown: "Select Other Board and Port"
64-
5. Search for pico, choose "Raspberry Pi Pico Zero"
73+
5. Search for pico, choose "Raspberry Pi Pico"
6574
5. Select Port: Tools > Port > (your Pico's port)
6675
6. Upload the sketch (the arrow)
6776

@@ -71,26 +80,32 @@ This is untested...
7180

7281
```bash
7382
# Install board support
74-
arduino-cli core install rp2040:rp2040
83+
arduino-cli core install arduino:mbed_rp2040
7584

7685
# Install the libraries, see [Prerequisites]:
7786
arduino-cli lib install ...
7887

7988
# Compile
80-
arduino-cli compile --fqbn rp2040:rp2040:rpipico sketch/pn5180_reader
89+
arduino-cli compile --fqbn arduino:mbed_rp2040:pico sketch/pn5180_reader
8190

8291
# Upload (replace /dev/ttyACM0 with your port)
83-
arduino-cli upload -p /dev/ttyACM0 --fqbn rp2040:rp2040:rpipico sketch/pn5180_reader
92+
arduino-cli upload -p /dev/ttyACM0 --fqbn arduino:mbed_rp2040:pico sketch/pn5180_reader
8493
```
8594

8695
## Protocol
8796

88-
The firmware communicates with the host computer over USB serial at 115200 baud using the SimpleRPC protocol.
97+
The firmware communicates with the host computer over USB serial using the SimpleRPC protocol.
8998

9099
### Available Functions
91100

92-
See the code for their documentations
101+
See the code for their documentations or run:
102+
```sh
103+
simple_rpc list /dev/ttyACM0
104+
```
93105

94106
### SimpleRPC
95107

96-
SimpleRPC is a simple RPC (Remote Procedure Call) protocol for Arduino that allows Python programs to call Arduino functions over serial. The protocol is documented at: https://simplerpc.readthedocs.io/
108+
SimpleRPC is a simple RPC (Remote Procedure Call) protocol for Arduino
109+
that allows Python programs to call Arduino functions over serial.
110+
The API and protocol is documented at:
111+
[https://simplerpc.readthedocs.io/](https://simplerpc.readthedocs.io/)

src/pn5180_tagomatic/proxy.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,6 @@ def turn_on_crc(self) -> None:
595595
596596
Enables CRC calculation and verification for transmission and reception.
597597
"""
598-
599598
self.turn_on_rx_crc()
600599
self.turn_on_tx_crc()
601600

@@ -774,11 +773,12 @@ def send_and_receive_15693(
774773
data = self.read_received_data()
775774

776775
if len(data) and data[0] & 1:
777-
if len(data) < 2:
778-
data += b"\xff"
776+
error_code = 0xFF
777+
if len(data) >= 2:
778+
error_code = data[1]
779779
raise ISO15693Error(
780780
command=command,
781-
error_code=data[1],
781+
error_code=error_code,
782782
response_data=data,
783783
)
784784
return data

0 commit comments

Comments
 (0)