scottlawsonbc / audio-reactive-led-strip

:musical_note: :rainbow: Real-time LED strip music visualization using Python and the ESP8266 or Raspberry Pi
MIT License
2.68k stars 644 forks source link

ESP8266 NodeMCU Lua #34

Closed d-rez closed 4 months ago

d-rez commented 7 years ago

I wrote a pretty simple ESP8266 NodeMCU Lua script for handling UDP packets for this project, including a strip fade-out when no packets are delivered for 5s. Would you be interested in a pull request for that?

scottlawsonbc commented 7 years ago

How does work? And are there any performance issues using Lua?

d-rez commented 7 years ago

buffer:set() (which is needed for per-LED update) for some reason takes a lot of time (I'm still looking to improve this somehow), but after setting the CPU speed to 160MHz (node.setcpufreq(node.CPU160MHZ)), I'm able to drive 60 LEDs at 45FPS (all LEDs being updated with every packet) or 80 LEDs at ~35FPS. Haven't tried with more LEDs but if I go above these FPS, it has issues keeping up, my router sends lots of retransmits and the effect lags behind a few seconds until you switch to one with less LEDs being updated. Serial port also looks "stuck" when that happens.

Here's how it works currently: https://www.youtube.com/watch?v=gWMWE8um7ZE

And thanks for an awesome visualiser! :) Now I just need that loopback output from win7+ integrated somehow :)

EDIT: I've noticed I mixed up greens with reds, should probably fix it ;p Fixed!

d-rez commented 7 years ago

I went much further and managed to optimize the Lua version greatly (60 FPS @ 60 LEDs) with selectable passive effects when not controlled by the PC, nice transitions, brightness and speed controls, Android app... Also got the pyaudio WASAPI fix working. I'm loving this and I'll probably want to extend this project to Razer Chroma devices if the Python wrapper is working.

https://www.youtube.com/watch?v=FoTgSMvDpUw

Quick question, what is dithering for? I'm not using that in Lua but haven't noticed any difference with software dithering and without

scottlawsonbc commented 7 years ago

That looks very cool! Is that an amazon echo in the video? In #30 there was a person who connected their strip to Alexa.

I don't quite understand how the Lua code works. Do you have to install any external libraries, or does it just work out of the box with the Lua interpreter?

Quick question, what is dithering for? I'm not using that in Lua but haven't noticed any difference with software dithering and without

There is a good overview of temporal dithering here. Temporal dithering is a technique used to extend the color depth by rapidly switching between similar brightness values.

I'm loving this and I'll probably want to extend this project to Razer Chroma devices if the Python wrapper is working.

Razer Chroma would be a great application, and I think this project could be one of the best music visualizers for the Chroma devices.

Just to let you know, I've been working on a new version of the visualization code in the develop branch which simplifies adding support for new hardware devices (such as Razer Chroma), and makes it easier to interface with other applications. The new version has:

The new version is currently undocumented and has no GUI support at the moment. Unfortunately, I am overwhelmed with my university courses at the moment and won't be able to finish the release until the end of April or beginning of May.

d-rez commented 7 years ago

Thanks! Haha that's actually not an Echo, that's an RGB mug holder from Razer. I guess I could connect my strip to Google Assistant through my Raspberry Pi / homeassistant, too!

Lua for ESP8266 NodeMCU is basically a firmware package, like Arduino firmware. I wrote my own UDP packet interpreter and pushed it to the chip.

I've already done the initial Chroma support and its looking good! Had to do a few hacks like reshaping numpy matrices (which is all new stuff for me) and the library I'm using is a bit buggy, some values hardcoded for 60-long strip, but it works!

https://gfycat.com/HighPartialGroundbeetle https://gfycat.com/CourageousLoathsomeAnnashummingbird

I don't own any Chroma keybards so no idea how I'd like to implement it for a 2D visualisation yet

The new spectrum effect looks sick, although doesn't look synced to music in that video? Looking forward to the new version! Is it the https://github.com/scottlawsonbc/audio-reactive-led-strip/tree/develop branch?

Regarding the initial question, the Lua code grew outside just visualisation I'll probably push it to a repo when it's ready ;)

d-rez commented 7 years ago

Just a heads-up that I think I almost finished Chroma support, the only issue is that my config is non-transferrable and hardcoded to 60LEDs due to matrix manipulations I'm doing to re-map and calculate axis means... I need a better way of doing that. I know this goes outside the scope of this particular issue, but I don't want to create a new one until I have properly configurable code :)

https://vid.me/YbS3

I think it looks awesome though!

joeybab3 commented 7 years ago

How does the delay on the Chroma compare to that of the ESP8266 or pi?

d-rez commented 7 years ago

It's not noticeable either way. I'd say the strip is more responsive actually

d-rez commented 6 years ago

Got a new laptop, real-life Chroma SDK example: https://www.youtube.com/watch?v=QKsfK_zStsI

I have no clue to edit the matrix to sizes I need and/or do a better job at approximating colours for shorter arrays like the mouse etc. I need to do more research...