Re: [Csnd] GPIO to MIDI (Raspberry Pi & Csound)
Date | 2020-04-23 12:05 |
From | Mark Ferguson |
Subject | Re: [Csnd] GPIO to MIDI (Raspberry Pi & Csound) |
Hi Matti, Thanks! Unless I'm mistaken, I think you can do the ADC via the following little device: https://www.freva.com/2019/06/12/light-sensor-on-raspberry-pi/ That can connect directly to the GPIOs. Sorry, perhaps should have been clearer at the start: it's mainly the code element I need help with; how to somehow convert GPIO values to MIDI, if that is even possible... Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here |
Date | 2020-04-23 12:38 |
From | Matti Koskinen |
Subject | Re: [Csnd] GPIO to MIDI (Raspberry Pi & Csound) |
Hi Mark, Can't you use OSC-messages? -m
On 23.4.2020 14.05, Mark Ferguson
wrote:
Hi Matti, Thanks! Unless I'm mistaken, I think you can do the ADC via the following little device: https://www.freva.com/2019/06/12/light-sensor-on-raspberry-pi/ That can connect directly to the GPIOs. Sorry, perhaps should have been clearer at the start: it's mainly the code element I need help with; how to somehow convert GPIO values to MIDI, if that is even possible... Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here |
Date | 2020-04-23 13:24 |
From | Tarmo Johannes |
Subject | Re: [Csnd] GPIO to MIDI (Raspberry Pi & Csound) |
Attachments | installatsioon.py |
Hi, I had a quick look at the LDR module and the sample code. If I am correct, it gives 1 if the light level is above a threshold and 0 otherwise - as kind of switch. If this is what you need, I suggest to use Csound Python API and add the Csound code to the sample python script that was on the page like this (and use SetChannel to pass the value to Csound). I paset and attach a rather old file that I used in similar situation with proximity sensor and some circuit. Then convert 1->127 and use midiout opcode to send to your midi device https://csound.com/docs/manual/midiout.html If you want analog data, you need a AD converter like https://learn.adafruit.com/raspberry-pi-analog-to-digital-converters/mcp3008 in between and look for python examples how to use that. If you have Arduino, it is easier in between, indeed. tarmo --- #!/usr/bin/python # must be run with sudo! # sudo /etc/rc.local # export PYTHONPATH=/usr/local/lib before running this script import csnd6 import random from time import sleep useGPIO = True if useGPIO: import RPi.GPIO as GPIO pin = 19 GPIO.setmode(GPIO.BOARD) GPIO.setup(pin, GPIO.IN) #GPIO.input(pin) cs = csnd6.Csound() cs.Compile("/home/pi/csound/installatsioon/installatsioon.csd") perf = csnd6.CsoundPerformanceThread(cs) perf.Play() oldValue = 0 while True: #TODO: perfthread OK if useGPIO: value = GPIO.input(pin) else: value = random.randint(0,1) sleep(3) if (value==oldValue): # sometimes occasional single 1-s. Send only if as the same as previous cs.SetChannel("signal",value) oldValue=value sleep(0.1) # 10 times in a second perf.Stop() # see ei juhtu tegelikult kunagi perf.Join() cs.Reset() Kontakt Mark Ferguson (<markfergusonaudio@gmail.com>) kirjutas kuupäeval N, 23. aprill 2020 kell 14:05: Hi Matti, |