richclarkson / Sabre

Ambient Lamp
0 stars 1 forks source link

Find a solution for Audio Library and FastLED library to work together #14

Open richclarkson opened 6 years ago

richclarkson commented 6 years ago

As a quick test I added a very simple LED sequence to the audio code I've been working on. It seems that as soon as any information is sent to the LEDs it messes with the Audio, the LEDs still work fine but the audio readings become very erratic and almost strobe like. Possibly something to do with timing or interrupts. From the forums there are plenty of things to try code wise and a few things we can try hardware wise including something like this if it comes to it. First thing i'll do is see if I can recreate the issue with a paired down version of the FFT code to make it easier to see what is going on, i'll comment when i've got it up in the FFT branch.

richclarkson commented 6 years ago

@sfaletti I got a minimal version of the file here so we can test this Audio + FastLED issue, let me know if there is anything in there that doesn't make sense to you. Running on Arduino IDE. Might also be worth submitting to the PJRC forum if I can't make any progress on it today.

richclarkson commented 6 years ago

Going to keep a checklist here of things I have tried that have not worked. So far it seems something in FastLED.show(); is the cause. I will continue to update this list.

sfaletti commented 6 years ago

Is it worth trying another library? If the delays are working it definitely sounds like a race condition.

richclarkson commented 6 years ago

Yes that's definitely on the list to try. Looking at the OctoWS2811 LED Library, the Adafruit Dotstar Library and the NeoPixelBus library.

richclarkson commented 6 years ago

NeoPixelBus working great on the minimal version of the RMS file. No weird spikes or redness coming through! Definitely something to do with the FastLED library in the FastLED.show(); function. I'm happy to switch over the the NeoPixelBus library but not sure how to bring the Fire2012() code across to work with NeoPixelBus for the Fire Lamp mode (which seems to be a feature people love). @sfaletti Do you think it would be practical (or even possible) to use NeoPixelBus to drive the LEDs during audio reactive stuff then use FastLED to do the non music reactive stuff (lamp modes)?

richclarkson commented 6 years ago

If we do have to move Fire2012 across looks like someone has already looked into it and seems not too bad. Some other elements of FastLED that would need to be brought across: Rainbow function and global brightness setting.

sfaletti commented 6 years ago

How hard would those really be to roll on our own? If we have hsv calculations they shouldn't be too hard to implement.

richclarkson commented 6 years ago

I'm sure that Rainbow will be fine, and global brightness shouldn't be too tricky. Fire2012 is the only one that I'm not sure about. I suppose it's just a case of figuring out what is going on in its functions: qsub8, random8, qadd8, and HeatColor.

sfaletti commented 6 years ago

It might be possible in that case to grab the LED values from FastLED without writing them to the hardware and causing the timer issues. We can then pass them to a working library. I'm saying without knowing if we can get access to the library at that level. It's also not ideal.

Is it possible to change the pins and timers used by FastLED?

richclarkson commented 6 years ago

I'm sure I tried changing the pins but will try again and let you know. However when it comes to the timers I'm not sure which timers to change in FastLED or where to change them.

richclarkson commented 6 years ago

Jeepers I could kick myself. Changing to Pin 2 & 3 and using FastLED worked. Audio coming in great and LEDs are behaving wonderfully.

richclarkson commented 6 years ago

Added a FastLED and RMS_minimal combined file [here] called Animations_with_RMS(https://github.com/richclarkson/Sabre/tree/LED_animations/old_src/Animations_wtih_RMS). It compiles and runs fine in arduino IDE. It only runs a paired down version of the RMS so the Ripple Music Mode has not been tested yet as that needs all 8 FFT channels.

sfaletti commented 6 years ago

Glad that's working. I'm getting the control inversion / dependency injection working now. Hopefully I can knock it out tonight and then tomorrow or Wed we can get the two systems integrated.

Can you test each channel individually? Maybe running the same sound loop over each channel to get a sense of the split might be a decent test. Or try something like this or this.

richclarkson commented 6 years ago

Yes I'll do that tomorrow, I had all 8 channels well with serialprint but would be good to get it into ripple mode and make sure that's working.

richclarkson commented 6 years ago

Yes I can confirm Ripple mode working with 8 channels. I used this file.