mehr infos, kein Problem:
grundsätzlich habe ich gefühlt alle libarys die ich dazu finden konnte ausprobiert.
In einem anderen Forum konnte ich noch folgenden Code und verkabelung finden:
Code: Alles auswählen
def isPlaying(): #routine to get the playing status
statdef isPlaying(): #routine to get the playing status
statusBytes = [1,2,3]
while len(statusBytes)!=10: #sometimes you get double status
uart.write(STATUS_ARRAY) # ask for the status
time.sleep(0.1) #give it some time
statusBytes = uart.read()
time.sleep(0.1) #give it some time
if statusBytes[6] == 1:
return True
else:
return False
from machine import Pin,UART
import time
#constant
UART_TX = 0
UART_RX = 1
ONBOARD_LED_GPx = 25
BUTTON_GPx = 13
DEBUG = False
## command to play the next sound
PLAY_ARRAY = bytearray(5)
PLAY_ARRAY[0] = 0x7E
PLAY_ARRAY[1] = 0xFF
PLAY_ARRAY[2] = 0x03
PLAY_ARRAY[3] = 0x01
PLAY_ARRAY[4] = 0xEF
## command to get status
STATUS_ARRAY = bytearray(5)
STATUS_ARRAY[0] = 0x7E
STATUS_ARRAY[1] = 0xFF
STATUS_ARRAY[2] = 0x03
STATUS_ARRAY[3] = 0x42
STATUS_ARRAY[4] = 0xEF
## command to define the device to play
DEVICE_ARRAY = bytearray(8)
DEVICE_ARRAY[0] = 0x7E
DEVICE_ARRAY[1] = 0xFF
DEVICE_ARRAY[2] = 0x06
DEVICE_ARRAY[3] = 0x09
DEVICE_ARRAY[4] = 0x00
DEVICE_ARRAY[5] = 0x00
DEVICE_ARRAY[6] = 0x02
DEVICE_ARRAY[7] = 0xEF
## command to set max volume
VOLUME_ARRAY = bytearray(8)
VOLUME_ARRAY[0] = 0x7E
VOLUME_ARRAY[1] = 0xFF
VOLUME_ARRAY[2] = 0x06
VOLUME_ARRAY[3] = 0x06
VOLUME_ARRAY[4] = 0x00
VOLUME_ARRAY[5] = 0x00
VOLUME_ARRAY[6] = 0x0E
VOLUME_ARRAY[7] = 0xEF
#variable
pressed = False # start out with the button unpressed
#device definition
uart = UART(0, baudrate=9600, tx=Pin(UART_TX), rx=Pin(UART_RX))
led_onboard = machine.Pin(ONBOARD_LED_GPx, machine.Pin.OUT)
button = machine.Pin(BUTTON_GPx, machine.Pin.IN, machine.Pin.PULL_UP)
#define a button handler
def button_handler(port):
global pressed
if not pressed:
if DEBUG:
print("need to press")
pressed = True
led_onboard.value(1)
#main
uart.write(DEVICE_ARRAY)
time.sleep(0.2) # give it some time to read the data
uart.write(VOLUME_ARRAY)
time.sleep(0.2) # give it some time to read the data
uart.write(PLAY_ARRAY)
led_onboard.value(0)
time.sleep(0.2)
#put the button handler in place
button.irq(trigger=machine.Pin.IRQ_RISING, handler=button_handler)
while True:
if pressed:
pressed = False # absorb the press
led_onboard.value(0)
if DEBUG:
print("button pressed") #debug
if isPlaying():
if DEBUG:
print("debug: still playing")
time.sleep(1)
else:
if DEBUG:
print("debug: play another song")
# looks like we can play another song
uart.write(PLAY_ARRAY)
time.sleep(1) #lets give it a rest
else:
time.sleep(1) #lets give it a rest
if DEBUG:
print("debug button not pressed") #debug
Wärend es bei dem Ersteller funktioniert regt sich bei meinem dfplayer nichts.
Über thonny direkt konnte ich nur eine micropython libary finden:
https://pypi.org/project/micropython-dfplayer/
In einem anderen Forum mit selbigen Thema hat mir ein anderer User scheinbar die selbe libary über github vorgeschlagen:
https://github.com/redoxcode/micropython-dfplayer
Mit dieser habe ich nun weiter gearbeitet, erster Erfolg: der player blinkt gelegentlich.
returnt sowohl bei ihm als auch bei mir immer -1 (connection fehler), dabei blinkt der player kurz.
führt bei ihm zum erfolg, bei mir weder Ton noch blinken.
Code: Alles auswählen
# dfplay.py
import time
from dfplayer import DFPlayer
df = DFPlayer(uart_id=1, tx_pin_id=4, rx_pin_id=5)
# wait some time till the DFPlayer is ready
time.sleep(0.2)
# change the volume (0-30). The DFPlayer doesn't remember these settings
df.volume(5)
time.sleep(0.2)
# play file ./01/003.mp3
df.play(1, 3)
Ich würde auch den Beitrag vom anderen Forum verlinken, ich hoffe das ist okay (ist halt in englisch):
https://forums.raspberrypi.com/viewtopi ... 0#p2229930
Die SD Karte wurde nach vorgaben der libary und den zur verfügung gestellten beispiel dateien bespielt.
Hier alles weitere an libarys und code die/der ausprobiert wurde/n:
https://www.elektronik-kompendium.de/si ... 712021.htm
https://www.elektronik-kompendium.de/si ... 712031.htm
https://github.com/mannbro/PicoDFPlayer
https://www.reddit.com/r/raspberrypipic ... with_pico/
https://forum-raspberrypi.de/forum/thre ... r-problem/
https://forums.raspberrypi.com/viewtopic.php?t=305880
https://forums.raspberrypi.com/viewtopi ... r#p2156823
Die verkabelung wurde natürlich immer angepasst!
Sollten weitere Fragen bestehen gerne Fragen

ich bin für jede hilfe dankbar, denn ich komme wirklich nicht weiter.
Und bevor es andere feststellen: Ja - ich habe von micropython nicht viel ahnung und betreibe für diesen Teil des projektes viel copy und paste. Ein grundverständis ist aber teilweise da UND copy und paste ist ja nicht schlecht wenn es funktioniert

nur leider tut es das dieses mal nicht... habt ein bisschen nachsicht, ich komme halt eher aus dem java und android bereich.