arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
21.98k stars 4.77k forks source link

Tasmota needs sound !! #3628

Closed gemu2015 closed 6 years ago

gemu2015 commented 6 years ago

i created an MP3 driver for this extremely cheap MP3 Player => DFPlayer mini (<2 Euros, 3 watt audio) 3 commands:

MP3Play track track =>1-N MP3Volume volume volume => 0-100 MP3Stop

you simply place any mp3 files on a micro sd card and can then play it i use it for sensor alarms when e.g. air quality is too bad and i want to use it for extending my haus alarm siren you could even think of an alarm clock with different alarm sounds or even musik.

it consumes nearly no resources, needs only one pin (software uart transmit)

attached is the (tiny) driver file. simply add it to the project (currently uses fixed GPIO 16 as transmit)

xdrv_98_mp3.ino.zip

arendst commented 6 years ago

Ordered one. Now where do I get the music from....

mike2nl commented 6 years ago

Free online Text To Speech (TTS) service with natural sounding voices: http://www.fromtexttospeech.com/

mike2nl commented 6 years ago

gemu2015 has optimized his mp3 driver 18 hours ago: https://github.com/gemu2015/Sonoff-Tasmota/blob/display-drivers/sonoff/xdrv_98_mp3.ino

He has added some defines, changed the void for mp3 play and changed the beloning code for the defines.

Here the file: --- file deleted because it is better to get it from the source now (active development)

BTW: here is a good data sheet: http://image.dfrobot.com/image/data/DFR0299/DFPlayer%20Mini%20Manul.pdf

Another BTW: DFRobot from GitHub has made a full function code, read it here: https://github.com/DFRobot/DFRobotDFPlayerMini/tree/master/examples/FullFunction

mike2nl commented 6 years ago

The little 'DFPlayer mini' arrived today and he plays like hell.

Test is done with the minimal configuration of 4 button, speaker (8ohm, 1watt) and the 5VDC power supply. Great sound from that little speaker.

The audio files came from my NAS with full actor and song name. He plays it well and all the buttons working like described in the data sheet.

Next step is to use it with tasmota. mikes_test_4_button

arendst commented 6 years ago

Got one too. Hard time finding a speaker. Got one too. Works with just a Wemos D1 mini powered from an external USB power supply.

On to the software...

mike2nl commented 6 years ago

BTW:

Have to see to find that player without the pins because my kids wish to have him now combined with her LilyPad's plus all the RGB LED's and the button.

gemu2015 commented 6 years ago

the player works with 3.3V. The specs say 3.2 to 5 V (typ 4.2)

i use mine with 3.3 Volts. you need no resistors then.

however the more voltage the more audio power

mike2nl commented 6 years ago

@gemu2015 strange because when i use 3,3 VDC i get these rare effect that the player stops after a second and the blue LED goes off. It can be possible that my 3.3VDC regulator, see photo please, is not 100% ok but it works with other 3.3VDC hardware. So then my player must be damaged.

The 3.3V is stable until 800mA that means that something must be wrong. Will see what's going wrong. And yes with a 3.3VDC power supply you need no resistor (data sheet).

Thank's for your feedback.

andrethomas commented 6 years ago

The 3.3V is stable until 800mA

That's 2.64 watts of power... in theory a 8 ohm speaker should not use more than 413mA @ 3.3V

mike2nl commented 6 years ago

@andrethomas right but the voltage regulator closes at 380mA so far i have messaured. With a second supply it works. It looks like that the 3.3V regulator is damaged. Today i got a new one, used him and it works. That is strange because i never used such a high current >= 450mA. And from 5V to 3.3V by 500mA makes ~0.9W. But the coling plate can 20W. So it must be the regulator self.

So that voltage issue is ok now and had not a lot of time to work on some software to test things. Hope i have some free time the next days.

arendst wrote: On to the software... Possible he is faster again ;-).

mike2nl commented 6 years ago

If someone will use the mp3 player driver xdrv_98_mp3.ino he has to change one thing in that file.

I use Arduino IDE 1.8.5 (.6 is out).

i added this in the user_config.ino: // -- MP3 player on GPIO 14 -----------------------

define USE_MP3_PLAYER // Use the tiny mp3 player

And i added #include in the xdrv_98_mp3.ino file. between:

ifdef USE_MP3_PLAYER

TasmotaSerial *MP3Player;

So it must look like:

ifdef USE_MP3_PLAYER

#include TasmotaSerial *MP3Player;

Otherwise Arduino IDE's compiler will shoot out an error that the MP3Player has no type.

mike2nl commented 6 years ago

Right now i´m busy with the selectable GPIO pin. Software is changed and upload is running. Will report back later...

@arendst Hope you can give me a hint. Text missing on nr. 98 Figure 1: selsction 1

Update 1: Argh, i think i found it in the template under kSensorNames. There it is missing.

Update 2: Yes in the kSensorNames i had to add my text now it works.

The MP3 Player is selectable in all four GPIO's but i use it on GPIO 14. Please see the screenshot. Figure 2: selsction 2

I selected the MP3 Player for GPIO 14 and saved it. The sonoff basic restarts. Next the status messages from the web console: CMD: gpios RSL: RESULT = {"GPIOs3":["88 (Switch7n)", ......, "98 (Mp3 Player)"]}

CMD: gpio RSL: RESULT = {"GPIO1":"0 (None)","GPIO3":"0 (None)","GPIO4":"0 (None)","GPIO14":"98 (Mp3 Player)"}

Then i was able to play the sound file and it worked well. Here the text from the web console: CMD: MP3Play 001 RSL: RESULT = {"MP3Play":1} CMD: MP3Volume 60 RSL: RESULT = {"MP3Volume":60} CMD: MP3Stop RSL: RESULT = {"MP3Stop"}

To play more then one title the files has to be named in 001.mp3, 002.mp3 and so on until 255.mp3. There is the possibility to play folders but that is another story. So far it works and i have changed the en-GB.h file only. A full of function MP3 Player needs more memory and the web page has to changed too so far needed, Oh no, all these work and questions ;-).

What can i do the change the other language files. Use as first step the default from the en-GB.h file anmd wait for translantions or may i use google translate?

mike2nl commented 6 years ago

Short Update:

Next i want to test some more commands (e.g. Play Next, Play All, Folder, ...) Have studied the data sheet i have from the original source and will do some tests to get a feedback. Some little tests but the free time is small at this time of the year.

Question to all of you: Is this something of interest or do you say: "no the three commands are enough". Then i will do it in two parts and the advanced part later for me or the one who wish to have it. Possible is configuration too in the user_config.h with simple/ default & /advanced

Please some feedback...

ascillato commented 6 years ago

Cool!

Very nice indeed. I like it! :+1:

You can make a PR with just the basic commands when you have it working and then, when you have the rest, you can make another PR to add more features.

That only depends on your time and how it is easier for you. The space difference between 3 commands and 6 (for example) should be very little. So It does not make the difference for the overall project.

When you make the PR, please add the line //#define USE_MP3_PLAYER // Use the tiny mp3 player to user_config.h file as commented out in order to keep the flash size low for the versions that do not require this feature.

mike2nl commented 6 years ago

@ascillato Thanks for the kind words. Additonal i have cleaned up the original xdrv_98 code a little bit for better and faster reading. Will rename it to xdrv_91 because i have seen so much 96, 97 and 98 stuff. I hope i get it done while(weekend) {...};

mike2nl commented 6 years ago

After merging needs testing. Will do the test today or tomorrow. Then report back and when that is ok we can close the issue, i think.

mike2nl commented 6 years ago

so have doen some rule tests under Version":"6.2.0.2". My merge request version. Have to do the same with the latest version.

Rule Test 1: rule1 on Time#Minute do mp3play 001 endon = worked every minute

Rule Test 2: rule1 on Time#Minute do backlog mp3play 001; ruletimer1 10 endon on rules#timer=1 do mp3stop endon = worked every minute

Rules are cool ;-).

mike2nl commented 6 years ago

@ascillato , @arendst , @gemu2015 , @andrethomas

For all of you the Update 5: Today i got the next delivery of 5 sonoff-sv. Yeah it looks fun.

So i used my new driver, more optimized with a switch() and i have the code further outlined for a more better reading and overview. It gets better and better.

Netxt actions:

Action after that:

BTW: I have found now 5 types of the little MP3 Player with different layouts and different commnad types. Strange but yeah that's live. There is also a module that has a speaker on it. So have to order two of each of them now on ali express to test them. No, much more to learn.

So far it looks amazing and rules are cool!

dr-apple commented 6 years ago

I don't understand how to connect rx and tx from the DFPlayer to the esp8266 ?

ascillato commented 6 years ago

We should add all this information to the wiki

ascillato commented 6 years ago

Commands added to the wiki: https://github.com/arendst/Sonoff-Tasmota/wiki/Commands#dfplayer-mini-mp3-player

ascillato2 commented 6 years ago

Closing issue as DFPlayer mini has been implemented in Tasmota.

Thanks @mike2nl, @gemu2015, @arendst

Jason2866 commented 6 years ago

Hello @mike2nl i get this compile error in VSC when i enable it via #define USE_MP3_PLAYER

Compiling .pioenvs\sonoff\lib29e\ESP8266WiFi\ESP8266WiFiSTA.cpp.o D:/Sonoff-Tasmota-development.6.2.1.3/sonoff/xdrv_14_mp3.ino: In function 'void MP3PlayerInit()': D:/Sonoff-Tasmota-development.6.2.1.3/sonoff/xdrv_14_mp3.ino:112:29: error: 'MP3_VOLUME' was not declared in this scope MP3_CMD(MP3_CMD_VOLUME, MP3_VOLUME); // set volume depending on the entry in the user_config.h ^ Compiling .pioenvs\sonoff\lib29e\ESP8266WiFi\ESP8266WiFiScan.cpp.o Compiling .pioenvs\sonoff\lib29e\ESP8266WiFi\WiFiClient.cpp.o Compiling .pioenvs\sonoff\lib29e\ESP8266WiFi\WiFiClientSecure.cpp.o *** [.pioenvs\sonoff\src\sonoff.ino.cpp.o] Error 1

mike2nl commented 6 years ago

@Jason2866 1st. I don't use VSC, mine is Arduino IDE 1.8.5 (1.8.7 is out) 2nd. In the user_config you will find the following at line 345 & 346: //#define USE_MP3_PLAYER // Use of the DFPlayer Mini MP3 Player RB-DFR-562 commands: play, volume and stop

define MP3_VOLUME 10 // Set the startup volume on init, the range can be 0..30(max)

To use the mp3 player delete the two '//', but i think you know that ;-). MP3_VOLUME 10 - is declared so far i see. You have the latest version?

Jason2866 commented 6 years ago

@mike2nl Had a problem with VSC.... Compiles without a problem. Thx

kinghill44 commented 5 years ago

Hello,

Nice Plugin. Is it possible to include the Commands Next/Prev Song to Tasmota Firmware?

THX

ascillato2 commented 5 years ago

Copied request from @AUyttendaele in #5039 :

Hi the MP3Player is working fine but is lacking commands to be truly functional

Addition of Following basic commands would be great NEXT_SONG | 0x01 | Play next song. PREV_SONG | 0x02 | Play previous song. SHUFFLE_PLAY | 0x18 | Playback shuffle mode. Data is 0 to enable, 1 to disable.

These would allow a basic MP3 player functionality.

The Folder commands would be nice but are not of the same importance. PLAY_FOLDER_FILE | 0x0f | Play the file with the specified folder and index number SHUFFLE_FOLDER | 0x28 | Playback shuffle mode for folder specified. Data high byte is the folder index.

Thanks

eggfat commented 5 years ago

Hi there, Im trying to install this onto a d1 mini but Im having no luck. Does the DFPlayer have to be wired to the d1 using a board to install the firmware ? Many thanks for any help. Here are the errors I'm getting. arduino.ar(core_esp8266_main.cpp.o):(.text._ZL12loop_wrapperv+0x4): undefined reference to setup' arduino.ar(core_esp8266_main.cpp.o):(.text._ZL12loop_wrapperv+0x8): undefined reference toloop' arduino.ar(core_esp8266_main.cpp.o): In function loop_wrapper': /Users/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.1/cores/esp8266/core_esp8266_main.cpp:111: undefined reference tosetup' /Users/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.1/cores/esp8266/core_esp8266_main.cpp:111: undefined reference to `loop' collect2: error: ld returned 1 exit status exit status 1 Error compiling for board WeMos D1 R2 & mini.

ascillato commented 5 years ago

Hi,

Your are having a compilation issue not related to DFPlayer. Please, address your issue to the Tasmota Support Chat. Thanks

TheBurgundyBear commented 4 years ago

Commands added to the wiki: https://github.com/arendst/Sonoff-Tasmota/wiki/Commands#dfplayer-mini-mp3-player

Hello! It appears this Wiki page does not exist anymore? I'm attempting to get my DFPlayer working after having issues with ESPHome and firewalls. Any assistance with how to set up the DFPlayer with Tasmota is appreciated!

meingraham commented 4 years ago

Documentation was moved several months ago. Older issues unfortunately will still refer to the older links.

Please visit tasmota.com

TheBurgundyBear commented 4 years ago

Documentation was moved several months ago. Older issues unfortunately will still refer to the older links.

Please visit tasmota.com

Nice! Thank you! However, what I'm specifically looking for is a template or something to get the DFPlayer to work and I haven't come across that yet. I see the commands at that link, but nothing else.

meingraham commented 4 years ago

Like most peripherals, you have to connect it to a free GPIO and configure Tasmota with the appropriate component (i.e., 100 - MP3_DFR562). There is no pre-made template because practically any ESP device can be used to attach the supported MP3 player peripheral (DFR562). You will have to configure your device accordingly. I don't believe that the MP3 driver is pre-compiled into any of the Tasmota variants. You will have to compile your own binary with USE_MP3_PLAYER defined.

TheBurgundyBear commented 4 years ago

Like most peripherals, you have to connect it to a free GPIO and configure Tasmota with the appropriate component (i.e., 100 - MP3_DFR562)...

Thank you once again, @meingraham. It does appear that the driver is included in the sensors binary:

image

So you're saying all I need to do is hook up a free GPIO PIN? When using ESPHome, I had it hooked up to TX and RX on a NodeMCU.

meingraham commented 4 years ago

Yes, it requires Rx/Tx.

You define the additional component on a free GPIO so Tasmota knows you have that peripheral connected and uses the driver for the correct protocol for the DFPlayer Mini. It's not an actual physical connection.

I have not used this module so I can't provide much more information. If you have further questions, I recommend you visit Tasmota's Discord.

TheBurgundyBear commented 4 years ago

Yes, it requires Rx/Tx...

Yeah, unfortunately the console is saying "Command Unknown." Do you happen to have a link to the Discord? The hyperlink located here: https://tasmota.github.io/docs/FAQ/ is linking to http://thehackbox.org/tasmota/release/

And for some reason Google isn't yielding anything either! Starting to wonder if I'm having DNS issues... this is weird.

meingraham commented 4 years ago

Yeah, that link appears to be wrong. It's not your DNS.

The support forums links are also at the bottom of the docs homepage.

https://discord.gg/Ks2Kzd4

TheBurgundyBear commented 4 years ago

Yeah, that link appears to be wrong. It's not your DNS...

Thanks so much for the help, @meingraham! I'm into the Discord now! The troubleshooting continues...

saschaludwig commented 4 years ago

Commands added to the wiki: https://github.com/arendst/Sonoff-Tasmota/wiki/Commands#dfplayer-mini-mp3-player

The link is invalid :-(

ascillato commented 4 years ago

Docs have been moved to http://tasmota.com

brjhaverkamp commented 3 years ago

Was reading on this mp3 player solution. Sounds interesting. But looking for more information, I just noticed that it isn't listed in the supported devices page. At least I couldn't find it there.

meingraham commented 3 years ago

https://tasmota.github.io/docs/Commands/#mp3-player

brjhaverkamp commented 3 years ago

Hi Miengraham,

Indeed, there is the information on the Commands in that section. But the device itself is not listed in the offical supported devices list: https://templates.blakadder.com/ (linked via https://tasmota.github.io/docs/devices/) I was looking for a tasmota enabled music player, but couldn't find one on that list. I stumbled upon the commands and the reference to the DFPlayer mini more or less by chance.

meingraham commented 3 years ago

@brjhaverkamp

Both the templates site and the Tasmota docs are open. Your contributions are welcomed.