A python script to create a midi device, and send control change messages out through it.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE
README.md
rotary_encoder.py

README.md

rpi-midi-rotary-encoder

rotary_encoder.py

A python script to create a midi device, and send control change messages out through it.

import RPi.GPIO as GPIO
import time
import mido
import os
import re

Also requires 'amidithru'

For a first time setup on a pi, you may have to install rpi.gpio for python3:

sudo apt-get update
sudo apt-get install python3-rpi.gpio 

The script is hopefully laid out clearly enough that customizing and adjusting things should be easy.

Common usage would be to put it on a Raspberry Pi which is connected to a rotary encoder, and run this script to monitor the voltage changes and relay appropriate midi data out through a chosen virtual interface, usable to other software running on the Pi.

Generally, add an entry to your crontab to call the script on startup: (Make sure you set your path properly)

@reboot /usr/bin/sudo /path/to/rotary_encoder.py &

Note about sudo

This script requires root to run, so you need to call it with sudo, without password, or save the startup command to the root user's crontab, without need for sudo.

To have this work on boot with sudo, you must not have sudo require a password to work.

You can achieve this by adding a new file and rule to your sudoers config. with visudo (username modep in examples):

sudo visudo -f /etc/sudoers.d/modep

Once in visudo, write the sudoers rule to allow your user to run sudo without a password:

modep ALL = (ALL:ALL) NOPASSWD: ALL

After that, you can log out and back in or reboot, and then be able to run sudo things without a password.