Giter Club home page Giter Club logo

steppermidi's Introduction

Steppermidi

Simple way to play midi on a stepper motor.

Motivation

There are a lot of projects that make Musik with Arduino and a Stepper motor.

But somehow they all use some roundabout way of getting MIDI to the Microcontroller (or so I felt). I wanted a CLI based approach on a linux PC which would allow me play any MIDI file to the Microcontroller. So I did some digging...

Needed Hardware

  • ESP32 or similar
  • A4988 stepper motor driver
  • stepper motor
  • power supply for stepper motor

Check e.g. the following resourced for a minimal HW setup:

What does it do?

The ESP32 is using the Midi library to listen to Midi data coming in through the serial port (i.e. USB connected to your PC) It will then drive the stepper motor to produce the note required by the Midi data.

Features

  • Logs on to your wifi and produces some debugging output on telnet port (since serial is occupied with MIDI data)
  • Calculates a lookup table for intervals needed to play a certain note on the fly at setup
  • Accepts Midi files streamed from your PC
  • blinks LED

Constraints

There is only one channel supported. If you have a midi file with multiple channel, you need to filter out the channel beforehand and stream that to the ESP. If you have a midi with multiple channels the playback will sound strange. In part this is due to the extremely rudimentary and blocking implementation of playing the notes. This could be handled much more elegantly, possibly even by simply using this library: https://github.com/daniel-centore/arduino-tone-library

Details

This uses the excellent arduino_midi_library: https://github.com/FortySevenEffects/arduino_midi_library Using the USB serial to transfer the Midi Data, you need to set the Baud Rate to 115200 (that’s what ttymidi uses as default). We are using callbacks which start/stop the playing of notes once a note starts/ends.

Installing and playing music

On the PC

Prepare your MIDI file.

You can use timidity to quieten unwanted tracks and output the result to a file timidity -OmM -o imperialmarch_trumpet.mid -Q 1,2,3,4,6,7,8,9,10,11,12,13,14 Downloads/imperialmarch.mid

Prepare the MIDI out via serial

Use ttymidi to create an ALSA port which is bound to a Serial Device /dev/ttyUSB0

./ttymidi -v -s /dev/ttyUSB0 -n myweirdcontroller

Play MIDI via Serial

Use pmidi to play the MIDI file via the serial port.

Check which ports are available to play to

    pmidi -l
     Port     Client name                       Port name
     14:0     Midi Through                      Midi Through Port-0
    128:1     myweirdcontroller                 MIDI in

Use pmidi to play a midi file to that ALSA port (decisive pointer on that gem. It’s about using timidity as ALSA input. Just substitute with ttymidi as above)

pmidi -p128:1 imperialmarch_trumpet.mid

steppermidi's People

Contributors

alexfederlin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.