Like a FitBit for (MIDI) keyboard players
A bit of hardware (plus software/firmware, of course) that I can plug into a MIDI keyboard (via USB) that will monitor my keyboard practice. At a minimum, show elapsed time for the week's practice. But other interesting stats are possible.
First, implement a Minimum Viable Product; add bells and whistles later (what a concept!).
Eventually create a front-end – app? website? – to slice and dice the data. Add social features?
We need something that can act as a MIDI/USB "host". This seems to be problematic for anything smaller than a Raspberry Pi Zero, which is what I'm using now (Zero2W). I was hoping to use a Pi Pico or the like, but USB Host capability is currently poorly supported (in CircuitPython anyway).
- Full RPi Python (3.11.x) code
- with Adafruit Blinka (see 'Installation' below) and a bunch of other stuff!
- Also some udev rules & scripts to run it all
- If we ever move to a smaller device, CircuitPython will probably be necessary.
Now using an Adafruit 1.3: TFT display - looks nice! Except it's slow! Either find a workaround or find a replacement display. My first instance of this part has developed visible defects. Are they fragile? short lived?
Need to define this and implement it first! Nothing fancy!!
- Data collection, storage, presentation
- Use Adafruit IoT ?
- Device sends session data updates to cloud
- Phone/desktop app queries cloud and shows data analysis
- Power-down safety
This is the second reason, after cost, that I'd prefer a Pico - how to make it safe to
simply power down the device?
- One solution: Make RPi Linux filesystem read-only. See https://learn.adafruit.com/read-only-raspberry-pi
- Can I make some of it R/W? For persistence? Needed??
- Workaround: GUI menu for shutdown
- One solution: Make RPi Linux filesystem read-only. See https://learn.adafruit.com/read-only-raspberry-pi
- https://github.com/RobCranfill/practiceMonitor/security/dependabot/1
- Alternate display
Since the display of the elapsed session time seems problematic (doesn't update nicely) can we show something else? Like just a "Session in progress" screen? But that doesn't encourage extending a session ("I see I have practiced for 17 minutes - can I make it to 20?").
-
Python 3.11.2 used
-
Runs in a 'venv':
python -m venv zenv --system-site-packages
source zenv/bin/activate
-
Python libs
- Blinka:
pip3 install --upgrade adafruit-python-shell
wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/raspi-blinka.py
sudo -E env PATH=$PATH python3 raspi-blinka.py
sudo apt-get install python-dev
pip install -f requirements.txt
- Blinka:
-
Misc
- sudo apt-get install fonts-dejavu
- Why did I have do do the following? (Did I have to??)
python3 -m pip install --upgrade --force-reinstall adafruit-blinka
-
The following are no longer needed, since we use the above requirements file. Delete after verification!
-
Linux softare
- RTMIDI backend for Mido
- pip install --pre python-rtmidi
- pip install mido[ports-rtmidi]
- sudo apt-get install libasound2-dev
sudo apt-get install libjack-dev
- RTMIDI backend for Mido
-
Adafruit Blinka as per https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/installing-circuitpython-on-raspberry-pi
-
PIL
-
pip install pillow
-
Adafruit Libs
- pip install adafruit-circuitpython-rgb-display
- IOT (Internet of Things)
pip3 install adafruit-io
- see https://learn.adafruit.com/welcome-to-adafruit-io/python-and-adafruit-io
-
TODO:
- Use syslog (or whatever)
- Done:
How to check if service already running? (For running from command line)
-
Notes
- script at /lib/systesmd/system/pmz.service
sudo cp pmz.service /lib/systemd/system/
sudo chmod 644 /lib/systemd/system/pmz.service
sudo systemctl daemon-reload
sudo systemctl [enable|disable|start|stop|status] pmz.service
- script at /lib/systesmd/system/pmz.service
- Attach PiZero2W via USB MIDI cable (& OTC connector) to MPKmini; via USB to power brick.
- Wait until 'ping pizero2w.local' returns a hit.
- On PC, run './mountsmb.sh' to mount SMB share, start Code pointing to SMB share.
- Use Termius (or whatever) to SSH to pizero2w.local.
- On PiZero2w, run 'source zenv/bin/activate' to start venv for PMon.
- Scripts on pmz:
- pmz.sh - runs the code in the forground, for development
- mountsmb.sh - as above
- check_pm_service.sh - sees if PMon is running in background; bad things happen if you try to run code twice.
- runPMZ.sh - script that runs the PMon as a service, for running standalone.
- Document above at "Linux Service"
- USE GITHUB 'ISSUES' FOR THIS.
- Completed:
- Handle no MIDI device attached - including displaying msg on LCD
- Handle SIGTERM/INT &c (blank screen, etc)
- Show MIDI device name on LCD
- LCD display - backlight off doesn't work
- Clear/poweroff display when done
- Auto-select appropriate MIDI device
- Create stand-alone command to turn off backlight; use it.