Skip to content

Keypad and pn532 don't play nice together #8328

@crazyiop

Description

@crazyiop

CircuitPython version

Adafruit CircuitPython 8.2.4 on 2023-08-22; BPI-PicoW-S3 with ESP32S3

Code/REPL

import board
import busio
import sdcardio
import storage
import audiobusio
import digitalio
import keypad
import gc
from adafruit_pn532.spi import PN532_SPI
import time

#########
# Buttons
#########

keys = keypad.Keys(
    [board.GP13, board.GP14, board.GP15, board.GP16, board.GP17],
    value_when_pressed=False,
    pull=True
)



#########
# sd card
#########

sd_do = board.GP9
sd_sck = board.GP10
sd_di = board.GP11
sd_cs = board.GP12

sd_spi = busio.SPI(sd_sck, MOSI=sd_di, MISO=sd_do)
sdcard = sdcardio.SDCard(sd_spi, sd_cs)

vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")
print('sd card ready')


#####
# nfc
#####

sck = board.GP18
miso = board.GP19
mosi = board.GP20
nfc_cs = board.GP21

spi = busio.SPI(sck, mosi, miso)
cs_pin = digitalio.DigitalInOut(nfc_cs)
pn532 = PN532_SPI(spi, cs_pin, debug=False)
pn532.SAM_configuration()
print('PN532 ready !')


#####
# I2S
#####

# using a max98357 breakout
# https://learn.adafruit.com/adafruit-max98357-i2s-class-d-mono-amp/overview
# i2s amp power direcly connected to the 5V of the board (Usb power)

din = board.GP3
bclk = board.GP4
lrclk = board.GP5
audio = audiobusio.I2SOut(bit_clock=bclk, word_select=lrclk, data=din)
print('i2s ready')


##############
# Player logic
##############

while True:
    playing_uid = None
    print('waiting for a tag to play·...')
    while playing_uid is None:
        playing_uid = pn532.read_passive_target(timeout=0.1)
        if playing_uid:
            break
        time.sleep(1)
        gc.collect()

        # this loop eventually crash when doing nothing (not puting a tag in
        # range, nor pressing any of the button of the Keypad)

    print(playing_uid)
    print('part where I play a song from sd depending on the nfc tag ID...')

Behavior

I encouter crash with the message You are in safe mode because: Internal watchdog timer expired. and get that everytime I run the code.

It started to happen When I added a 5 key Keypad to my previously working project (a player that play song from an sdcard upon finding an nfc tag).

The project, at a previous state, was working fine with: nfc poling + i2s song playing + some control from an i2c rotary encoder poling (volume, next on click). I wanted to move from the rotary to a Keypad for the controls.

Description

The given code is a minimal failing example of my code.

  • as is, it will crash, from ~10s to ~2min (but rarely more than 1min)
  • When commenting the pn532.read_passive_target(): It works fine (no crash after 10+ minutes)
  • When commenting the whole Keypad definition: It works fine too (no crash after 10+ minutes)

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions