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
  • NVIDIA unveils new Jetson Thor platform
  • Toocaa L2 laser cutter and engraver review: safety first
  • SwissMicros DM42n review: keeping a legacy alive
  • Miniware TS21 review
  • Banana Pi CanMV-K230D-Zero review
  • Mehatronika interviews: Stefan Engleder
  • teenage engineering OP-XY review: after dark
  • Mehatronika interviews: Rodrigo Sim
  • 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

Dušan DakićBy Dušan Dakić05/05/2022Updated:26/02/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;
           }

   }
   }
}
teenage engineering
Previous Articleteenage engineering OP-Z review
Next Article SunFounder 10.1” HDMI IPS Touchscreen Review
Dušan Dakić
  • Instagram

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.

Related posts

teenage engineering OP-XY review: after dark

9.1 01/06/2025

Arturia AstroLab review

9.1 29/09/2024

teenage engineering OP-1 field review

10 18/07/2023

teenage engineering TX-6 review

9.5 27/11/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 SwissMicros teenage engineering TelitPower Wurth Elektronik Youyeetoo
Facebook X (Twitter) Instagram LinkedIn
  • 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.

Logo magazin Mehatronika
Manage Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behaviour or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
  • Manage options
  • Manage services
  • Manage {vendor_count} vendors
  • Read more about these purposes
View preferences
  • {title}
  • {title}
  • {title}
Logo magazin Mehatronika
Manage Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behaviour or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
  • Manage options
  • Manage services
  • Manage {vendor_count} vendors
  • Read more about these purposes
View preferences
  • {title}
  • {title}
  • {title}