Tuesday, July 21, 2026

Arduino Pro Micro MIDI DIN 5-Pin Loopback Tester & Hardware Validator

Download Project : https://github.com/bonardalfin/Arduino-Pro-Micro-MIDI-DIN-5-Pin-Loopback-Tester/

Part :
Arduino Pro Micro USB C : https://s.shopee.co.id/4funcsGw7B
Kabel Midi 5 Pin : https://s.shopee.co.id/AKZANMHjxK 
6N138 : https://s.shopee.co.id/8Ko5zinV6v
LCD OLED DISPLAY 0.91inch I2C : https://s.shopee.co.id/6ffs0gpfYS


This project is an automated MIDI hardware validator built on the Arduino Pro Micro (ATmega32U4). It is designed to test and verify 5V DIN 5-pin MIDI IN and MIDI OUT physical circuits simultaneously.

The system operates in two core modes:

  • Automated MIDI Transmitter (MIDI OUT): Generates random MIDI Note On/Off messages every 3 seconds via the hardware UART interface (Serial1).
  • Real-time MIDI Receiver & Parser (MIDI IN): Intercepts incoming MIDI messages via an optically isolated optocoupler circuit (6N138) and renders event data in real time on a 0.91-inch I2C OLED display (SSD1306).

Connecting a standard 5-pin DIN cable from the local MIDI OUT port to the local MIDI IN port allows full loopback validation of the onboard driver, optocoupler, and serial parsing logic.


Pinout and Hardware Connection

The following table details the pin mappings between the Arduino Pro Micro (ATmega32U4 5V/16MHz), the 0.91" SSD1306 I2C OLED Display, and the MIDI DIN 5-Pin IN/OUT hardware circuits:

Component / Module Module Pin / Function Pro Micro Pin Description / Notes
OLED Display VCC VCC (5V) Main power supply for OLED controller
OLED Display GND GND System common ground
OLED Display SDA Pin 2 (SDA) Hardware I2C Data line
OLED Display SCL Pin 3 (SCL) Hardware I2C Clock line
MIDI IN (6N138) Pin 6 (VO Output) Pin 0 (RX0) Hardware Serial RX1 line (Requires 470 Ω pull-up to 5V)
MIDI OUT Connector Pin 5 (CSNK / Signal) Pin 1 (TX0) Hardware Serial TX1 line (Connected via 220 Ω series resistor)
MIDI OUT Connector Pin 4 (CSRC / Power) VCC (5V) 5V current loop supply (Connected via 220 Ω series resistor)
MIDI OUT Connector Pin 2 (GND) GND Cable shield ground reference

Hardware Circuit Specifications

1. MIDI IN Circuit (Optical Isolation)

To maintain compliance with the MIDI 1.0 Electrical Specification and prevent ground loops:

  • Optocoupler IC: 6N138 (High-speed Darlington output).
  • Protection Diode: 1N4148 placed anti-parallel across Pin 2 (Anode) and Pin 3 (Cathode) of 6N138.
  • Resistor R1 (Base Drop): 10 kΩ connected between 6N138 Pin 7 and GND.
  • Resistor R2 (Pull-Up): 470 Ω connected between 6N138 Pin 6 and 5V.
  • Resistor R3 (Current Limit): 220 Ω connected between DIN Pin 4 and 6N138 Pin 2.
  • DIN 5-Pin IN Jack:
    • Pin 4 connected to R3 (220 Ω).
    • Pin 5 connected to 6N138 Pin 3.
    • Pin 2 (Ground) must remain floating/unconnected to isolate external ground loops.

2. MIDI OUT Circuit (5V Current Loop)

  • DIN 5-Pin OUT Jack:
    • Pin 4 connected to VCC (5V) via 220 Ω series resistor.
    • Pin 5 connected to Arduino TX0 (Pin 1) via 220 Ω series resistor.
    • Pin 2 connected directly to System GND.

Software Dependencies

This project relies on the following Arduino libraries:

  • MIDI Library by Francois Best (version ^5.0.0): Handles MIDI protocol packet generation and parsing over hardware serial.
  • Adafruit_SSD1306 by Adafruit (version ^2.5.0): Monochrome display driver for SSD1306 displays.
  • Adafruit_GFX by Adafruit (version ^1.10.0): Core graphics library for displays.

System Architecture and Firmware Flow

The sketch leverages Serial1 on the ATmega32U4, leaving the primary Serial interface reserved for USB CDC communications.

  1. Display & Hardware Serial Setup:
    • Initializes the 128x32 OLED display at I2C address 0x3C.
    • Registers callback handlers (handleNoteOn, handleNoteOff) with the MIDI library.
    • Begins Serial1 at the mandatory MIDI baud rate of 31250 bps.
    • Disables software THRU (MIDI.turnThruOff()) to prevent incoming serial packets from echoing back to TX automatically.
  2. Main Processing Loop (loop()):
    • Calls MIDI.read() continuously on every cycle to parse incoming UART bytes.
    • Executes a non-blocking timer using millis() configured for a 3000ms interval.
  3. Transmission Sequence (Every 3 seconds):
    • Selects a random MIDI note pitch between 36 (C2) and 96 (C7) with a velocity between 64 and 127.
    • Updates the OLED buffer with KIRIM NoteOn status and displays the pitch and velocity.
    • Transmits Note On via MIDI.sendNoteOn().
    • Waits 200ms, then transmits the corresponding Note Off via MIDI.sendNoteOff().
  4. Reception Callback Execution:
    • When an incoming Note On or Note Off frame is parsed on RX0, the callback interrupts the display state and instantly renders TERIMA NoteOn or TERIMA NoteOff along with the received channel, note value, and velocity.

Installation and Flashing

  1. Open the Arduino IDE and load your sketch file.
  2. Go to Tools > Board and select Arduino Leonardo or Arduino Micro.
  3. Select the correct serial port under Tools > Port.
  4. Click Upload.

No comments:

Post a Comment

 
Copyright 2024 BONARD ALFIN PROJECT. All rights reserved.