peterhinch / micropython-vs1053

Synchronous and asynchronous drivers for VS1053b MP3/FLAC player
MIT License
25 stars 7 forks source link

ESP8266 async? #5

Open roboknight opened 10 months ago

roboknight commented 10 months ago

This is where I really hate GitHub. I don't really want to create an issue, but just to ask about async on the ESP8266. What is the major problem here? I'm using this processor in a project, and it would be really awesome if I could check button "presses" while something is playing. Unfortunately, as awesome as this controller is, it seems to have several drawbacks to what I want to do. And while your project is awesome (it truly is... when I got this working on the NodeMCU, or at least a clone, it was really beautiful.), I'd like to be able to play back asynchronously so I could check some "buttons" while things are playing. Is the processor just to limited, or might there be a way? Again, didn't really want to create an issue around this because I'm not sure this is a solvable problem.

Thanks for reading.

peterhinch commented 10 months ago

The ESP8266 is quite a minimal processor with limited RAM. While it does support asyncio in general applications, audio work is pushing the boundaries. The compatibility matrix shows that the asynchronous driver is more demanding of resources and in my testing it was unusable with ESP8266.

roboknight commented 10 months ago

Thanks. I was afraid of that. Well, my application isn't super critical, but it is just going to be irksome as the thing I'm trying to duplicate was a purpose-built VLSI blob-top chip and was a pretty amazing little chip. It likely even used less battery power than the NodeMCU/VS1053/(amplifier chip I can't remember right now) combo I'm using. Although, it now has SD card capability that the old thing did not. Basically, the old chip stored up to 48 MIDI songs and was able to play them (actually, some were duplicated and others not used, so maybe it didn't quite store 48). And the MIDI was quite impressive for a little blob top. At any rate, I was trying to make something pretty similar to build another one, and the ESP8266 seemed like a good controller micro as it had a lot of library support for both Arduino and MicroPython. Ultimately, MicroPython seemed way easier to implement the actual code (libraries are just... more complete? It takes way less code to use them, usually). The ONLY thing it seems to be missing is any kind of interrupt-on-pin so that you could detect something occurring while play is going on and stop it, or maybe start another song. But, I suppose I can live with that.

peterhinch commented 10 months ago

If you have an ESP8266 to hand there is no harm in trying the async version, particularly with low bit rate MP3's. The firmware may have improved since I tested. Otherwise you could use the synchronous version (which has been tested) with a pin interrupt to cancel play.

roboknight commented 10 months ago

I might do that. I had to compile the synch version to fit in 64k ram otherwise it crashes (4M flash and they couldn’t spring for 128 or 256k? Glad mpy-compile is a thing). I haven’t tried over clocking either. But a pin interrupt example would be welcome, as I was looking for something along those lines.

peterhinch commented 10 months ago

See the docs. You create a callback function which runs when the pin changes state.

Note that if you do get async running there is a much better way of handling pin changes which does not use interrupts. See the tutorial - follow the link.

roboknight commented 10 months ago

Thanks. I must have skimmed right by the pin docs. I’ll see what I can do. The interrupt setup looks like the ticket.