TaylorTMusic / MIDI2GPIO

Use the Pi Zero as a MIDI USB gadget, and pass along note and velocity information to PWM GPIO pins.
18 stars 4 forks source link

Not an issue, just a question about WS2812B #1

Open cluc-dev opened 5 years ago

cluc-dev commented 5 years ago

Hi there! first of all, I would like to thank you for this great project.

I was wondering if you could offer me a little guidance, I'm hoping to use MIDI from Ableton to light up some digital RGB leds. Unfortunately, I'm at a loss as to where I should start modifying your code to do so.

Could you perhaps point me to some example code I could merge with yours, to control WS2812B leds?

Thank you!

TaylorTMusic commented 5 years ago

Sure thing, If you haven't already, take a look at MIDI2GPIO.py In the folder "MIDI2GPIO". I tried to comment about what the python script is doing as much as possible as I'm just learning Python with this script as I went.

Since I'm outputting a MIDI Note on an individual GPIO header it was easy to rig up a single LED to each note, for your example with an addressable LED strip, you're probably going to need to import a library made for the WS2812B into the script near the top, just like I did with:

import RPi.GPIO as GPIO

Then read the library information and replace the sections in my code where it says:

pwm1.ChangeDutyCycle(bright)

To whatever LED you're trying to address and turn on.

Also, I added a function to change the LED brightness based on the velocity of the note. This is done with Pulse Width Modulation (PWM). You probably don't need it for your use case, as it might make it more complicated with the WS2812B. You can remove those lines.

Just found a great resource to get you started:

https://tutorials-raspberrypi.com/connect-control-raspberry-pi-ws2812-rgb-led-strips/

cluc-dev commented 5 years ago

Thanks so much for your quick reply!

Easier than I thought! You have given me every piece I need to get going. Expect to see a WS2812B fork soon!

On Mon, Mar 4, 2019 at 11:40 AM Taylor Thomas notifications@github.com wrote:

Sure thing, If you haven't already, take a look at MIDI2GPIO.py In the folder "MIDI2GPIO". I tried to comment about what the python script is doing as much as possible as I'm just learning Python with this script as I went.

Since I'm outputting a MIDI Note on an individual GPIO header it was easy to rig up a single LED to each note, for your example with an addressable LED strip, you're probably going to need to import a library made for the WS2812B into the script near the top, just like I did with:

import RPi.GPIO as GPIO

Then read the library information and replace the sections in my code where it says:

pwm1.ChangeDutyCycle(bright)

To whatever LED you're trying to address and turn on.

Also, I added a function to change the LED brightness based on the velocity of the note. This is done with Pulse Width Modulation (PWM). You probably don't need it for your use case, as it might make it more complicated with the WS2812B. You can remove those lines.

Just found a great resource to get you started:

https://tutorials-raspberrypi.com/connect-control-raspberry-pi-ws2812-rgb-led-strips/

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/TaylorTMusic/MIDI2GPIO/issues/1#issuecomment-469368743, or mute the thread https://github.com/notifications/unsubscribe-auth/AHOPfKfBdRIJMi37i2IdtRmM4mR8VqaDks5vTWiKgaJpZM4bbqpX .

TaylorTMusic commented 5 years ago

Absolutely, I'll be looking forward too it and might build something with them since it's easier to work with addressable LED's!

cluc-dev commented 5 years ago

I have made some good progress! I was trying out the Max4Live stuff, but ran into a missing media file, "Trigg.me SEND.amxd"

I did some searching and it looks like I can buy Trigg.me for $8 on gumroad. Is that something I'm supposed to do, or am I making a mistake somewhere? It indeed seems to be something that would be used for this purpose.

TaylorTMusic commented 5 years ago

Oops, left that in the files I guess. So it triggers midi when audio reaches a threshold in Ableton, so not needed, but if you want to trigger lights based on certain sounds and audio that's not midi, it's worth it!