/practiceMonitor

A FitBit for MIDI keyboards

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

Pi Practice Monitor

Like a FitBit for (MIDI) keyboard players

Goal

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?

Main Hardware

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).

Software

  • 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.

Display

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?

Minimum Viable Product

Need to define this and implement it first! Nothing fancy!!

Stretch Goals (post MVP)

  • Data collection, storage, presentation
  • Use Adafruit IoT ?
    • Device sends session data updates to cloud
    • Phone/desktop app queries cloud and shows data analysis

Issues

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?").

Installation

Linux service

  • 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

Workflow Revisited

  • 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"

To Do

  • 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.