Skip to content

Walkmp3rson learn guide does not work with CP 9.x Freezes and displays USB not recognizable on PC Windows #9211

@dwetchells

Description

@dwetchells

CircuitPython version

Adafruit CircuitPython version 9.4.0

Code/REPL

===========================================================================
# SPDX-FileCopyrightText: 2022 John Park and Tod Kurt for Adafruit Industries
# SPDX-License-Identifier: MIT
'''Walkmp3rson digital cassette tape player (ok fine it's just SD cards)'''

import time
import os
import board
import busio
import sdcardio
import storage
import audiomixer
import audiobusio
import audiomp3
from adafruit_neokey.neokey1x4 import NeoKey1x4
from adafruit_seesaw import seesaw, rotaryio
import displayio
import terminalio
from adafruit_display_text import label
from adafruit_st7789 import ST7789
from adafruit_progressbar.progressbar import HorizontalProgressBar
from adafruit_progressbar.verticalprogressbar import VerticalProgressBar

displayio.release_displays()

# SPI for TFT display, and SD Card reader on TFT display
spi = board.SPI()
# display setup
tft_cs = board.D6
tft_dc = board.D9
tft_reset = board.D12
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=tft_reset)
display = ST7789(display_bus, width=320, height=240, rotation=90)

# SD Card setup
sd_cs = board.D13
sdcard = sdcardio.SDCard(spi, sd_cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")

# I2C NeoKey setup
i2c = busio.I2C(board.SCL, board.SDA)
neokey = NeoKey1x4(i2c, addr=0x30)
amber = 0x300800
red = 0x900000
green = 0x009000

neokey.pixels.fill(amber)
keys = [
    (neokey, 0, green),
    (neokey, 1, red),
    (neokey, 2, green),
    (neokey, 3, green),
]
#  states for key presses
key_states = [False, False, False, False]

# STEMMA QT Rotary encoder setup
rotary_seesaw = seesaw.Seesaw(i2c, addr=0x36)  # default address is 0x36
encoder = rotaryio.IncrementalEncoder(rotary_seesaw)
last_encoder_pos = 0

# file system setup
mp3s = []
for filename in os.listdir('/sd'):
    if filename.lower().endswith('.mp3') and not filename.startswith('.'):
        mp3s.append("/sd/"+filename)

mp3s.sort()  # sort alphanumerically for mixtape  order, e.g., "1_King_of_Rock.mp3"
for mp3 in mp3s:
    print(mp3)
    
track_number = 0
mp3_filename = mp3s[track_number]
mp3_bytes = os.stat(mp3_filename)[6]  # size in bytes is position 6
mp3_file = open(mp3_filename, "rb")
mp3stream = audiomp3.MP3Decoder(mp3_file)

Behavior

Walkmp3rson program crashes. Does not display anything on TFT display. If connected to Windows PC, I get a Windows error message stating the USB drive is not recognizable and disconnect the CIRCUITPY drive from my PC. If I comment the line >>> mp3stream = audiomp3.MP3Decoder(mp3_file) <<< then the program continue for until the next error which is mp3stream not defined, naturally.

Thank you for all your help and understanding. ThinMan

Description

on a RP2040 Feather used in JP Learn guide Walkmp3rson. Used all parts described in guide. Works fine using CP version 8.12. Found issue with module audiomp3 in CP 9.x. Here below is the example I used to cause the crash. If I comment out the last line the program continues on. The code is the same as JP guide.

Additional information

When this line is commented out the program continues
mp3stream = audiomp3.MP3Decoder(mp3_file)

Activity

added this to the 9.x.x milestone on Apr 29, 2024
modified the milestones: 9.x.x, 9.1.0 on May 29, 2024
self-assigned this
on Jun 3, 2024
dhalbert

dhalbert commented on Jun 3, 2024

@dhalbert
Collaborator

@dwetchells If you reduce the program to something like the below, does it still crash? I have removed all the display and control peripheral code. Does it crash on pretty much any MP3 file?

# ... appropriate import statements

# SD Card setup
sd_cs = board.D13
sdcard = sdcardio.SDCard(spi, sd_cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")

mp3_filename = "something.mp3" # your first filename

mp3_file = open(mp3_filename, "rb")
mp3stream = audiomp3.MP3Decoder(mp3_file)
dwetchells

dwetchells commented on Jun 3, 2024

@dwetchells
Author
dwetchells

dwetchells commented on Jun 3, 2024

@dwetchells
Author
dhalbert

dhalbert commented on Jun 4, 2024

@dhalbert
Collaborator

I tried the code you have above, only changing some pin assignments to use a TFT FeatherWing with an SD card socket. I am using an Adafruit Feather RP2040. I do not see the hard crash you see after mp3stream = audiomp3.MP3Decoder(mp3_file). I am using a generic Micro Center 16GB SD card.

I am using the two low-bit rateMP3 files from here:
https://github.com/adafruit/Adafruit_Learning_System_Guides/tree/main/MP3_Playback_RP2040/Pico_Multi_File

If you have an MP3 file that causes a crash, could you point to it or drop it here? You may need to .zip it up. Or if you can't do that, could you give me details about the MP3 bit rate, etc.?

dwetchells

dwetchells commented on Jun 4, 2024

@dwetchells
Author
dhalbert

dhalbert commented on Jun 4, 2024

@dhalbert
Collaborator

I was using a couple of different TFT FeatherWings: https://www.adafruit.com/search?q=tft+featherwing. These don't actually have the correct display (it shows up as a mirror image), but that doesn't matter -- it's not going to affect the operation of the program, because these displays are write-only. But the TFT FeatherWings have an SD socket too, so that provided the SD card for me without having to wire it up. If you have an SD card FeatherWing or similar, you could try that. Else try to make the connections as short as possible.

Try 9.0.5 or 9.1.0-beta.3, but this sounds more like an SD card problem than a version problem. Also try the .mp3's I pointed to above. It may be an MP3 problem of some kind.

dhalbert

dhalbert commented on Jun 4, 2024

@dhalbert
Collaborator

I tested again with a 320kb bitrate MP3 and did not see a crash. I'm going to take this issue off the 9.1.0 milestone for now, but happy to keep debugging.

modified the milestones: 9.1.0, Support on Jun 4, 2024

16 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugrp2040Raspberry Pi RP2040

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @tannewt@dhalbert@dwetchells

      Issue actions

        Walkmp3rson learn guide does not work with CP 9.x Freezes and displays USB not recognizable on PC Windows · Issue #9211 · adafruit/circuitpython