No Tag scnned ESP32 with PN532 testes oder SPI and I2C

Hey folks,

first topic :wink:

I am currently having problems with the PN532 and an ESP32.
The project is based on the standalone tag reader from adonno.
However, I need more IO inputs for buttons. Hence the ESP32.
Buttons work like charm.

Using I2C, I can sometimes read RFID tags after flashing. but only a few times. As a test, I have now connected the RFID reader via SPI. here is an attached LOG:

INFO Reading configuration /config/esphome/tagreader.yaml...
INFO Starting log output from tagreader-kinder.local using esphome API
INFO Successfully connected to tagreader-kinder.local
[13:16:01][I][app:102]: ESPHome version 2021.9.3 compiled on Oct 20 2021, 10:44:47
[13:16:01][I][app:104]: Project adonno.tag_reader version 1.6
[13:16:01][C][wifi:501]: WiFi:
[13:16:01][C][wifi:361]:   SSID: [redacted]
[13:16:01][C][wifi:362]:   IP Address: 192.168.178.61
[13:16:01][C][wifi:364]:   BSSID: [redacted]
[13:16:01][C][wifi:365]:   Hostname: 'tagreader-kinder'
[13:16:01][C][wifi:369]:   Signal strength: -59 dB ▂▄▆█
[13:16:01][V][wifi:371]:   Priority: 0.0
[13:16:01][C][wifi:373]:   Channel: 1
[13:16:01][C][wifi:374]:   Subnet: 255.255.255.0
[13:16:01][C][wifi:375]:   Gateway: 192.168.178.1
[13:16:01][C][wifi:376]:   DNS1: 192.168.178.1
[13:16:01][C][wifi:377]:   DNS2: 0.0.0.0
[13:16:01][C][spi:081]: SPI bus:
[13:16:01][C][spi:082]:   CLK Pin: GPIO18 (Mode: OUTPUT)
[13:16:01][C][spi:083]:   MISO Pin: GPIO19 (Mode: INPUT)
[13:16:01][C][spi:084]:   MOSI Pin: GPIO23 (Mode: OUTPUT)
[13:16:01][C][spi:085]:   Using HW SPI: YES
[13:16:01][C][template.switch:058]: Template Switch 'TagReaderKinder Buzzer Enabled'
[13:16:01][C][template.switch:058]:   Icon: 'mdi:volume-high'
[13:16:01][C][template.switch:059]:   Restore State: YES
[13:16:01][C][template.switch:060]:   Optimistic: YES
[13:16:01][C][template.switch:058]: Template Switch 'TagReaderKinder LED enabled'
[13:16:01][C][template.switch:058]:   Icon: 'mdi:alarm-light-outline'
[13:16:01][C][template.switch:059]:   Restore State: YES
[13:16:01][C][template.switch:060]:   Optimistic: YES
[13:16:01][C][ledc.output:032]: LEDC Output:
[13:16:01][C][ledc.output:033]:   Pin GPIO26 (Mode: OUTPUT)
[13:16:01][C][ledc.output:034]:   LEDC Channel: 0
[13:16:02][C][ledc.output:035]:   Frequency: 988.0 Hz
[13:16:02][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'next'
[13:16:02][C][gpio.binary_sensor:016]:   Pin: GPIO17 (Mode: INPUT_PULLUP, INVERTED)
[13:16:02][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'previous'
[13:16:02][C][gpio.binary_sensor:016]:   Pin: GPIO21 (Mode: INPUT_PULLUP, INVERTED)
[13:16:02][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'play_pause'
[13:16:02][C][gpio.binary_sensor:016]:   Pin: GPIO16 (Mode: INPUT_PULLUP, INVERTED)
[13:16:02][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'volume_up'
[13:16:02][C][gpio.binary_sensor:016]:   Pin: GPIO22 (Mode: INPUT_PULLUP, INVERTED)
[13:16:02][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'volume_down'
[13:16:02][C][gpio.binary_sensor:016]:   Pin: GPIO4 (Mode: INPUT_PULLUP, INVERTED)
[13:16:02][C][fastled:019]: FastLED light:
[13:16:02][C][fastled:020]:   Num LEDs: 1
[13:16:02][C][fastled:021]:   Max refresh rate: 400
[13:16:02][C][logger:193]: Logger:
[13:16:02][C][logger:194]:   Level: VERBOSE
[13:16:02][C][logger:195]:   Log Baud Rate: 115200
[13:16:02][C][logger:196]:   Hardware UART: UART0
[13:16:02][C][light:097]: Light 'TagReaderKinder LED'
[13:16:02][C][light:099]:   Default Transition Length: 0.0s
[13:16:02][C][light:100]:   Gamma Correct: 2.80
[13:16:02][C][pn532:344]: PN532:
[13:16:02][C][pn532:356]:   Update Interval: 1.0s
[13:16:02][C][pn532_spi:156]:   CS Pin: GPIO27 (Mode: OUTPUT)
[13:16:02][C][rtttl:017]: Rtttl
[13:16:02][C][status:034]: Status Binary Sensor 'TagReaderKinder Status'
[13:16:02][C][status:034]:   Device Class: 'connectivity'
[13:16:02][C][ota:029]: Over-The-Air Updates:
[13:16:02][C][ota:030]:   Address: tagreader-kinder.local:3232
[13:16:02][V][pn532_spi:029]: Writing data: 00.00.FF.04.FC.D4.4A.01.00.E1.00 (11)
[13:16:02][V][pn532:243]: Reading ACK...
[13:16:02][V][pn532_spi:037]: Waiting for ready byte...
[13:16:02][V][pn532_spi:062]: Reading data...
[13:16:02][V][pn532_spi:068]: Read data: 01.00.00.FF.00.FF.00 (7)
[13:16:02][V][pn532:254]: ACK valid: YES
[13:16:02][V][pn532_spi:073]: Reading response
[13:16:02][V][pn532_spi:084]: Not ready yet...
[13:16:02][V][pn532_spi:084]: Not ready yet...
[13:16:02][V][pn532_spi:084]: Not ready yet...
[13:16:02][V][pn532_spi:084]: Not ready yet...
[13:16:02][V][pn532_spi:084]: Not ready yet...
[13:16:02][V][pn532_spi:084]: Not ready yet...
[13:16:02][V][pn532_spi:084]: Not ready yet...
[13:16:02][V][pn532_spi:084]: Not ready yet...
[13:16:02][V][pn532_spi:084]: Not ready yet...
[13:16:02][V][pn532_spi:084]: Not ready yet...
[13:16:02][V][pn532_spi:084]: Not ready yet...
[13:16:02][V][pn532_spi:084]: Not ready yet...
[13:16:02][V][pn532_spi:084]: Not ready yet...
[13:16:02][V][pn532_spi:084]: Not ready yet...
[13:16:02][V][pn532_spi:087]: Timed out waiting for readiness from PN532!
[13:16:02][V][pn532:265]: Turning RF field OFF
[13:16:02][V][pn532_spi:029]: Writing data: 00.00.FF.04.FC.D4.32.01.00.F9.00 (11)
[13:16:02][V][pn532:243]: Reading ACK...
[13:16:02][V][pn532_spi:037]: Waiting for ready byte...
[13:16:02][V][pn532_spi:062]: Reading data...
[13:16:02][V][pn532_spi:068]: Read data: 01.00.00.FF.00.FF.00 (7)
[13:16:02][V][pn532:254]: ACK valid: YES
[13:16:02][V][component:207]: Component pn532 took a long time for an operation (0.17 s).
[13:16:02][V][component:208]: Components should block for at most 20-30ms.
[13:16:02][C][api:135]: API Server:
[13:16:02][C][api:136]:   Address: tagreader-kinder.local:6053
[13:16:02][C][api:140]:   Using noise encryption: NO
[13:16:03][V][pn532_spi:029]: Writing data: 00.00.FF.04.FC.D4.4A.01.00.E1.00 (11)
[13:16:03][V][pn532:243]: Reading ACK...
[13:16:03][V][pn532_spi:037]: Waiting for ready byte...
[13:16:03][V][pn532_spi:062]: Reading data...
[13:16:03][V][pn532_spi:068]: Read data: 01.00.00.FF.00.FF.00 (7)
[13:16:03][V][pn532:254]: ACK valid: YES
[13:16:03][V][pn532_spi:073]: Reading response
[13:16:03][V][pn532_spi:084]: Not ready yet...
[13:16:03][V][pn532_spi:084]: Not ready yet...
[13:16:03][V][pn532_spi:084]: Not ready yet...
[13:16:03][V][pn532_spi:084]: Not ready yet...
[13:16:03][V][pn532_spi:084]: Not ready yet...
[13:16:03][V][pn532_spi:084]: Not ready yet...
[13:16:03][V][pn532_spi:084]: Not ready yet...
[13:16:03][V][pn532_spi:084]: Not ready yet...
[13:16:03][V][pn532_spi:084]: Not ready yet...
[13:16:03][V][pn532_spi:084]: Not ready yet...
[13:16:03][V][pn532_spi:084]: Not ready yet...
[13:16:03][V][pn532_spi:084]: Not ready yet...
[13:16:03][V][pn532_spi:084]: Not ready yet...
[13:16:03][V][pn532_spi:084]: Not ready yet...
[13:16:03][V][pn532_spi:087]: Timed out waiting for readiness from PN532!
[13:16:03][V][pn532:265]: Turning RF field OFF
[13:16:03][V][pn532_spi:029]: Writing data: 00.00.FF.04.FC.D4.32.01.00.F9.00 (11)
[13:16:03][V][pn532:243]: Reading ACK...
[13:16:03][V][pn532_spi:037]: Waiting for ready byte...
[13:16:03][V][pn532_spi:062]: Reading data...
[13:16:03][V][pn532_spi:068]: Read data: 01.00.00.FF.00.FF.00 (7)
[13:16:03][V][pn532:254]: ACK valid: YES

Config:


# Insert your SSID and Your PWD after inital setup
wifi:
  networks:
    - ssid: !secret wlan_ssid        # Enter your WiFi SSID here. Example: `ssid: 'your_network_name'`
      password: !secret wlan_password     # Enter your wifi password here. Example: `password: 'abcde123456'`
 # ap:
   # ssid: ${devicename}

# Enable the captive portal for inital WiFi setup
#captive_portal:

substitutions:
  devicename: tagreader-kinder
  friendly_name: TagReaderKinder
  mediaplayer: media_player.familienzimmer

esphome:
  name: $devicename
  platform: ESP32
  board: nodemcu-32s
  #nodemcu-32s


  # This will allow for (future) project identification,
  # configuration and updates.
  project:
    name: adonno.tag_reader
    version: "1.6"
# If buzzer is enabled, notify on api connection success
  on_boot:
    priority: -10
    then:
    - wait_until:
        api.connected:
    - logger.log: API is connected!
    - rtttl.play: "success:d=24,o=5,b=100:c,g,b"
    - light.turn_on:
        id: activity_led
        brightness: 100%
        red: 0%
        green: 0%
        blue: 100%
        flash_length: 500ms
    - switch.turn_on: buzzer_enabled
    - switch.turn_on: led_enabled
    
# Define switches to control LED and buzzer from HA
switch:
- platform: template
  name: "${friendly_name} Buzzer Enabled"
  id: buzzer_enabled
  icon: mdi:volume-high
  optimistic: true
  restore_state: true
- platform: template
  name: "${friendly_name} LED enabled"
  id: led_enabled
  icon: mdi:alarm-light-outline
  optimistic: true
  restore_state: true
  
api:
  services:
  - service: rfidreader_tag_ok
    then:
    - rtttl.play: "beep:d=50,o=5,b=100:e6"

  - service: rfidreader_tag_ko
    then:
    - rtttl.play: "beep:d=8,o=5,b=100:b"

  - service: play_rtttl
    variables:
      song_str: string
    then:
    - rtttl.play: !lambda 'return song_str;'

# Enable logging
logger:
  level: VERBOSE

# Enable OTA upgrade
ota:

spi:
  clk_pin: GPIO18
  mosi_pin: GPIO23
  miso_pin: GPIO19
  
pn532_spi:
  cs_pin: GPIO27
  id: pn532_board
  update_interval: 1s
  on_tag: 
    then:
      - homeassistant.tag_scanned: !lambda 'return x;'
      - if:
          condition:
            switch.is_on: buzzer_enabled
          then:
          - rtttl.play: "success:d=24,o=5,b=100:c,g,b"
      - if:
          condition:
            switch.is_on: led_enabled
          then:
          - light.turn_on:
              id: activity_led
              brightness: 100%
              red: 0%
              green: 100%
              blue: 0%
              flash_length: 500ms

# Define the buzzer output
output:
- platform: ledc
  pin: GPIO26
  id: buzzer
  
# Define buzzer as output for RTTTL
rtttl:
  output: buzzer 
  
binary_sensor:
  - platform: status
    name: "${friendly_name} Status"
    
    #Next Track
  - platform: gpio
    id: next
    pin:
      number: GPIO17
      mode: INPUT_PULLUP
      inverted: true  
    filters:
      - delayed_on_off: 100ms
    on_press:
      - then:
        - homeassistant.service: 
            service: media_player.media_next_track
            data:
                entity_id: ${mediaplayer}


    #Previous Track
  - platform: gpio
    id: previous
    pin:
      number: GPIO21
      mode: INPUT_PULLUP
      inverted: true  
    filters:
      - delayed_on_off: 100ms
    on_press:
      then:
        - homeassistant.service: 
            service: media_player.media_previous_track
            data:
                entity_id: ${mediaplayer}

    #Play/Pause
  - platform: gpio
    id: play_pause
    pin:
      number: GPIO16
      mode: INPUT_PULLUP
      inverted: true  
    filters:
      - delayed_on_off: 100ms
    on_press:
      then:
        - homeassistant.service: 
            service: media_player.media_play_pause
            data:
                entity_id: ${mediaplayer}
                
    #Volume up
  - platform: gpio
    id: volume_up
    pin:
      number: GPIO22
      mode: INPUT_PULLUP
      inverted: true  
    filters:
      - delayed_on_off: 100ms
    on_press:
      then:
        - homeassistant.service: 
            service: media_player.volume_up
            data:
                entity_id: ${mediaplayer}
                
    #Volume down
  - platform: gpio
    id: volume_down
    pin:
      number: GPIO4
      mode: INPUT_PULLUP
      inverted: true  
    filters:
      - delayed_on_off: 100ms
    on_press:
      then:
        - homeassistant.service: 
            service: media_player.volume_down
            data:
                entity_id: ${mediaplayer}
  

# Configure LED
light:
- platform: fastled_clockless
  chipset: WS2812
  pin: GPIO25
  default_transition_length: 10ms
  num_leds: 1
  flash_transition_length: 500ms
  rgb_order: GRB
  id: activity_led
  name: "${friendly_name} LED"
  restore_mode: ALWAYS_OFF

RFID Reader connected like:

I have the same issue, did you manage to find a solution? Other people who had this problem said it was a wiring issue, but I checked and it doesn’t seem to be the case

I tested with another esp32 board and another rfid board. Same result. I switched back to esp8266 d1 mini. Works like a charm.

I have the same issue, any solution? Thanks!

I have the same problem with pn532_i2c, pn532_spi never worked for me.
I found a solution for pn532_i2c, but it doesn’t work for pn532_spi.
The solution is add 4.7k pullup resistor to 3.3v for sda and scl.
I want to read 2 pn532, one for entry and one for exit.
So I need to use pn532_spi and pn532_i2c.
If someone can help me, I will be very grateful.
Good luck with your project.

1 Like