Raspberry Pi 3 B+ With PN532

해초의 꿈·2025년 2월 22일

Overview

  • Raspberry Pi 3 B+에서 Raspberry Pi OS Lite(64-bit)를 사용
  • PN532를 이용한 NFC RFID 보드를 연동
  • NFC TAG 인지하는 MP3 플레이어 구현
  • 구동에 필요한 라이브러리 및 파이썬 설치
  • 기본적인 전력 소비량과 디스크 사용량을 측정
    • 전력 소비량은 USB 전력 측정기로 간단히 확인
    • 디스크 사용량은 df 명령어로 확인
    • 부팅 시간은 systemd-analyze 명령어로 확인

Test Environment

Hardware

ItemValue
BoardRaspberry Pi 3 Model B V1.2
NFC ModulePN532 NFC RFID Module
Audio3.5mm Speaker

Operating System

ItemValue
ImageRASPBERRY PI OS LITE (64-BIT)
KernelLinux pi3 6.6.51+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.51-1+rpt3 (2024-10-08) aarch64 GNU/Linux

Software / Library

ItemVersion
Python3.11.2
pip23.0.1
adafruit-circuitpython-pn5322.4.3
pygame2.6.1

Connecting wires

Connection Overview

Raspberry Pi GPIO PinPN532 PinCable Color
6 (GND)1 (GND)Black
4 (5V)2 (5V)Red
3 (GPIO2, SDA)3 (SDA)White
5 (GPIO3, SCL)4 (SCL)Brown

Actual Wiring Photo

I2C Setting

  1. 터미널 실행
  2. sudo raspi-config 명령어 입력
  3. 3. Interface Options 선택
  4. I5 I2C 선택
  5. “Would you like the ARM I2C interface to be enabled?”
    • Yes 선택
  6. 설정이 끝나면 Finish라즈베리 파이 재부팅

Install Python Library

  1. 패키지 목록 업데이트 & pip 설치
sudo apt-get update
sudo apt-get install -y python3-pip
  1. 가상 환경 생성 및 활성화
python3 -m venv .venv
source .venv/bin/activate
  1. 라이브러리 설치
pip3 install adafruit-circuitpython-pn532
pip3 install pygame

Sample Code

import time
import board
import busio
from adafruit_pn532.i2c import PN532_I2C
import pygame

# 1) Initialize PN532
i2c = busio.I2C(board.SCL, board.SDA)
pn532 = PN532_I2C(i2c, debug=False)
pn532.SAM_configuration()

# 2) Initialize pygame sound
pygame.mixer.init()

track_path = "/home/user/sample.mp3"  # Path to your audio file
card_present = False  # Whether a card is currently detected

print("Please place and remove the card repeatedly.")

try:
    while True:
        # Read card UID (0.5 second timeout)
        uid = pn532.read_passive_target(timeout=0.5)

        if uid is not None:
            if not card_present:
                print(f"Card detected! UID: {uid}")
                # Play the audio file
                pygame.mixer.music.load(track_path)
                pygame.mixer.music.play()
                card_present = True
        else:
            if card_present:
                # If the card was present and is now removed, stop playback
                print("Card removed.")
                pygame.mixer.music.stop()
                card_present = False

        time.sleep(0.1)

except KeyboardInterrupt:
    print("Terminated by user.")
    pygame.mixer.music.stop()

Booting Time

  • 기본 세팅과 PN532 장비 및 라이브러리 설치했을때와 오차 범위 내로 큰 차이 없음
$ systemd-analyze
Startup finished in 5.852s (kernel) + 18.954s (userspace) = 24.807s
multi-user.target reached after 12.796s in userspace.

Disk Usage

FilesystemUsedMounted on
/dev/mmcblk0p165M/boot/firmware
/dev/mmcblk0p22.6G/

Power Consumption

StateVoltageAmpere (Max)Watt (Max)
Booting5V0.6A3W
Idle5V0.28A1.4W
Polling5V0.5A2.5W
Playing5V0.5A2.5W

Conclusion

  • 부팅 시간은 약 25초로 큰 차이 없음
  • 소비 전력은 부팅시 약 3W, 유휴시 약 1.4W 소모로 부팅시 전력 소모가 조금 더 있음
  • NFC 카드를 Polling시 전력 소모 발생

Next Steps

  • 라즈베리 파이 Zero 모델에 대한 부팅 시간 및 전력 사용량 확인

0개의 댓글