Close Menu
magazin Mehatronikamagazin Mehatronika
  • Srpski
  • Home
  • News
  • Reviews
    • SBCs
    • Development systems
    • Accessories
    • Tools
    • STEM
    • Music
    • Consumer technology
  • Forums
Facebook X (Twitter) Instagram LinkedIn
Trending
  • Banana Pi CanMV-K230D-Zero review
  • Mehatronika interviews: Stefan Engleder
  • teenage engineering OP-XY review: after dark
  • Mehatronika interviews: Rodrigo Sim
  • LattePanda Mu i3-N305 review: More power
  • Raspberry Pi’s new storage options reviewed – Part 2: the Raspberry Pi SSD Kit
  • Raspberry Pi’s new storage options reviewed – Part 1: the SD cards
  • Raspberry Pi AI HAT+ (26 TOPS) review
  • English
    • Srpski
    • English
LinkedIn Facebook X (Twitter) Instagram
magazin Mehatronikamagazin Mehatronika
  • Home
  • News
  • Reviews
    • SBCs
    • Development systems
    • Accessories
    • Tools
    • STEM
    • Music
    • Consumer technology
  • Forums
magazin Mehatronikamagazin Mehatronika
Home»Reviews»Music»OP-Z unexpected MIDI demo project
Music

OP-Z unexpected MIDI demo project

By Dušan Dakić05/05/2022Updated:02/26/20253 Mins Read
OP-Z MIDI one

And now for an unexpected demo…
… we are an engineering magazine, after all, so we wanted to create a bit of a crossover project to finish this review off. We grabbed one of our favourite MCUs – the SAME51-based ATMEL ATSAME51J19 and got to work!

We wanted to add a little OLED-based display to the OP-Z and use it for displaying the current beat inside the bar. We decided to use the MIDI protocol for this, as it gave us the necessary data out of the sequencer.

Using the USB-MIDI library we listen to start, stop and clock signals. As per the standard MIDI implementation, the OP-Z sends 24 clock pulses per quarter note. This means in order to get accurate beat sync we just need to count those pulses.

Sadly, there’s the little problem of the pulses being abour 20 ms apart. The core of the MCU absolutely has to be ready to receieve the pulse, and if it doesn’t – the entire thing gets out-of-sync. With some optimization, the M4 core had no issues keeping up – and we were left with a pretty sweet little project that we feel shows off how much is possible using just MIDI data.

GitHub Project Code
https://github.com/magazinMehatronika/MIDI-Beat-Tracker

#include <MIDI.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>

  #define BUTTON_A  9
  #define BUTTON_B  6
  #define BUTTON_C  5

using namespace midi;
MIDI_CREATE_DEFAULT_INSTANCE();

Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire);


int sync = 0;
int counter = 0;

int modeSel = 0;

bool enabler = false;

void setup()
{
    MIDI.begin(MIDI_CHANNEL_OMNI);  // Listen to all incoming messages

    delay(250); // wait for the OLED to power up
    display.begin(0x3C, true); // Address 0x3C default
    display.setRotation(1);

    
    display.clearDisplay();


    pinMode(BUTTON_A, INPUT_PULLUP);
    pinMode(BUTTON_B, INPUT_PULLUP);
    pinMode(BUTTON_C, INPUT_PULLUP);

}

void loop()
{

   digitalWrite(LED_BUILTIN, LOW);

  if(!digitalRead(BUTTON_A)) modeSel = 0;
  if(!digitalRead(BUTTON_B)) modeSel = 1;
  if(!digitalRead(BUTTON_C)) modeSel = 2;
   

   if(MIDI.read()){
            switch(MIDI.getType()){      // Get the type of the message we caught

            case Start:

            enabler = true;

            sync = 0;
            counter = 0;
            break;

            case Stop:

            enabler = false;

            display.clearDisplay();
            display.display();

            sync = 0;
            counter = 0;

            break;
            
            case Clock:
            if (enabler == true){
            
            if (sync == 0){

            switch (counter){

             case 0:
              display.clearDisplay();
              
              display.setTextSize(4,8);
              display.setTextColor(SH110X_WHITE);
              display.setCursor(0,0);

              switch(modeSel){
                case 0:
                display.print("One");
                break;
                case 1:
                display.print("Je'n");
                break;
                case 2:
                display.print("Ja--");
                break;
              }
              

              display.display();
              counter++;
              break;

              case 1:
              display.clearDisplay();


              display.setTextSize(4,8);
              display.setTextColor(SH110X_WHITE);
              display.setCursor(0,0);

              switch(modeSel){
                case 0:
                display.print("Two");
                break;
                case 1:
                display.print("Dva");
                break;
                case 2:
                display.print("--pa");
                break;
              }
              display.display();
              counter++;
              break;

              case 2:
              display.clearDisplay();

              display.setTextSize(4,8);
              display.setTextColor(SH110X_WHITE);
              display.setCursor(0,0);

              switch(modeSel){
                case 0:
                display.print("Three");
                break;
                case 1:
                display.print("Tri");
                break;
                case 2:
                display.print("pa--");
                break;
              }
              display.display();
              counter++;
              break;

              case 3:
              display.clearDisplay();

              display.setTextSize(4,8);
              display.setTextColor(SH110X_WHITE);
              display.setCursor(0,0);

              switch(modeSel){
                case 0:
                display.print("Four");
                break;
                case 1:
                display.print("Cet");
                break;
                case 2:
                display.print("--pa");
                break;
              }
              display.display();
              counter = 0;
              break;
              
            }
            
            digitalWrite(LED_BUILTIN, HIGH);
            delay(10);                // Wait for a second
            digitalWrite(LED_BUILTIN, LOW);
            sync = 24;
            }
            sync--;
            break;
           }

   }
   }
}
  • About
  • Latest Posts
Dušan Dakić
Dušan Dakić
Writer/Comms manager at magazin Mehatronika
Dušan has been with magazin Mehatronika since 2019, focusing on tech reviews and how-to articles, as well as handling communications with our partners worldwide.

He’s also the key person behind Mehatronika's English translations, especially of education- and maker-oriented texts.
Dušan Dakić
Latest posts by Dušan Dakić (see all)
  • teenage engineering OP-XY review: after dark - 06/01/2025
  • Mehatronika interviews: Rodrigo Sim - 05/17/2025
  • LattePanda Mu i3-N305 review: More power - 03/16/2025
teenage engineering
Previous Articleteenage engineering OP-Z review
Next Article SunFounder 10.1” HDMI IPS Touchscreen Review

Related posts

teenage engineering OP-XY review: after dark

9.1 06/01/2025

Arturia AstroLab review

9.1 09/29/2024

teenage engineering OP-1 field review

10 07/18/2023

teenage engineering TX-6 review

9.5 11/27/2022

Using the teenage engineering OP-Z and POM-400 with the Korg minilogue xd

08/08/2022

teenage engineering OP-Z review

9.3 05/05/2022
Brands
52Pi ABB Arturia ASBIS Banana Pi CADCAM Data CircuitMess Clockwork Pi Copa-Data DFRobot Digilent Eaton Elecfreaks Elecrow ELESA+GANTER Eurocom Fanuc FriendlyElec Intel LattePanda Lilygo Mersen miniWare Mixtile NumWorks NVIDIA Okuma Orange Pi Pickering Pine Microsystems Radxa Raspberry Pi Robotistan Samsung Schunk Seeed STMicroelectronics SunFounder teenage engineering TelitPower Wurth Elektronik Youyeetoo
Facebook X (Twitter) Instagram LinkedIn
  • Privacy policy
  • Editorial policy
  • Contact us
  • Media kit
  • Sending in review units

magazin Mehatronika - Agencija “Gomo Design”
Stanoja Glavaša 37, 26300 Vršac, Serbia
+381 60 0171 273

© 2025 magazin Mehatronika by Gomo Design.

Type above and press Enter to search. Press Esc to cancel.

We use some minimal cookies to give you the best page experience. Please let us know if you're okay with this.AcceptPrivacy policy