omriharel / deej

Set app volumes with real sliders! deej is an Arduino & Go project to let you build your own hardware mixer for Windows and Linux
https://deej.rocks
MIT License
4.79k stars 445 forks source link

Support for Raspberry Pi Pico #35

Closed shaylanger closed 3 years ago

shaylanger commented 3 years ago

I recently built a volume control using Deej and a raspberry pi pico, and figured others might find the python code for the pico usefull (if they wanted to build this as well using a pico)

save this code in a file called main.py on the pico and when the pico is plugged in the Deej program will be able to listen to the potentiometers (you will need to adjust the config.yaml to only have 3 sliders)

Note the Pico only has 3 analog pins (26-28) so it only supports up to 3 potentiometers

import machine
import utime

NOISE = 10
POTENTIOMETER_COVERSION = 64.0625610948 #Converts the Pico's 65536 max to match Deej's expected 1023 max
POTENTIOMETERS = [
    machine.ADC(26),
    machine.ADC(27),
    machine.ADC(28)
]
values = [0] * len (POTENTIOMETERS)            

while True:
    results = ""
    for i, potentiometer in enumerate(POTENTIOMETERS):

        curr = round(potentiometer.read_u16() / POTENTIOMETER_COVERSION)

        # this check will normalize the results and reduce noise 
        if values[i] > (curr + NOISE) or values[i] < (curr - NOISE):
            values[i] = curr

        results = results + str(values[i])

        if i != len(POTENTIOMETERS) - 1:
            results = results + "|"

    print(results)
    utime.sleep(.2)
omriharel commented 3 years ago

Hi @shaylanger, thanks for writing!

This is cool, however I think it's more appropriate for it to be accessible via your fork of deej - you can essentially create your copy of the project and add the relevant code and instructions there, ensuring that any future changes you make continue to live on in that location. If that sounds good to you, perhaps you can do that and then edit the issue to link to your fork?

Please let me know if you have any questions.

omriharel commented 3 years ago

Closing for now!

jleuth commented 2 years ago

For some reason, you are the only person ive seen use a pico for a deej build, i could not find anyrthing on a deej pico build anywhere else. Thank you!

2tondo commented 6 months ago

I had the same issue as the guy above me, love your work

akumar48 commented 6 months ago

Thanks a lot this is awesome!