Skip to content

MIDI via RS 232 or USB to serial

Dale Whinham edited this page Mar 25, 2021 · 3 revisions

You can send MIDI data to mt32-pi using a serial port directly using suitable cabling and software such as Hairless MIDI on a modern computer, or SoftMPU on a vintage computer.

mt32-pi supports a wide range of baud rates, which can be configured with the gpio_baud_rate option in the configuration file. This means you use serial ports that cannot operate at the standard MIDI baud rate of 31250.

Modern computers

For modern computers, you can use a USB-to-serial converter to directly connect mt32-pi to the machine without the need for a USB MIDI interface, which can be more cost-effective than purchasing a USB MIDI interface for the PC and a GPIO MIDI interface for the Raspberry Pi. You can then use mt32-pi for:

  • Playing games using DOSBox with MIDI support.
  • Playing MIDI files, e.g. ripped from games or original compositions.
  • Making music with a modern DAW (digital audio workstation) that uses classic MT-32 sounds.

Vintage computers

Some vintage computers (e.g. old laptops, "thin client" machines) lack a game port or any sort of way to give the machine an MPU-401-like interface for connecting MIDI hardware the traditional way.

Fortunately, many of these machines feature the venerable serial port (aka. RS-232 port, or COM port). With appropriate driver software and hardware interfacing, you can use the serial port to get MIDI out of the machine and into mt32-pi.

The catch is that the receiving equipment must be able to handle PC baud rates. MIDI uses a baud rate of 31250bps, which is not a standard PC baud rate. The closest standard PC baud rate is 38400bps, and most synthesizers with a "PC" connection such as the Roland SC-55MkII or SC55-ST will use this baud rate.

Interfacing with the Raspberry Pi

The method of connection varies depending on what kind of host computer you are using. Here are some examples of how you can create a serial port connection.

"Real" RS-232 ports (vintage computers)

RS-232 ports use signalling voltages that are dangerous to the Raspberry Pi! In order to safely connect a Raspberry Pi to a PC's serial port, you must use an appropriate level shifter to convert the signals to suitable levels.

One example is a simple module based on the MAX3232 chip - search for "MAX3232" or "RS-232 to TTL converter". These are available very cheaply from various online suppliers.

Connect the module as follows:

Converter pin Raspberry Pi pin
VCC 1 (3.3V)
GND 6 (GND) - or any other GND pin
RXD 10 (UART RXD)
TXD 8 (UART TXD) - not required*

⚠️ Note: mt32-pi does not transmit any MIDI unless gpio_thru is enabled, so you can leave the TXD signal from the Pi disconnected if you want.

You can now connect the module to the host computer's serial port. It may be convenient to use a serial port extension cable, or maybe even a null modem cable between the PC and the module, but you will need to ensure that the cable connector genders are correct and that the RXD/TXD signals are going to the right pins.

USB to serial converters (modern computers)

USB to serial converters are inexpensive (e.g. some varieties can be found for less than $1-2 on AliExpress!) and many varieties are available. You may even have one handy if you have worked on any Arduino/microcontroller projects before. They are often based around chipsets such as the FT232RL from FTDI, or CP2102 from Silicon Labs.

⚠️ Note: Make sure that the converter outputs 3.3V signals or can be set to do so! Converters using 5V signalling will damage the Raspberry Pi!

Connect the converter as follows:

Converter pin Raspberry Pi pin
GND 6 (GND) - or any other GND pin
TXD 10 (UART RXD)
RXD 8 (UART TXD) - not required*

⚠️ Note: Do not connect any power (VCC/+5V/+3.3V etc.) pins between the devices. Only GND and the TXD/RXD signals should be connected.

⚠️ Note: mt32-pi does not transmit any MIDI unless gpio_thru is enabled. You can leave the TXD signal from the Pi disconnected if you want; though you may want to ground the RXD signal on the converter to prevent noise/garbage being received.

Software configuration

As serial ports are not usually treated as MIDI interfaces by the operating system or application software, some additional software is needed to "bridge" the serial port to the application and make it usable as a MIDI device.

MS-DOS: serial port MIDI with SoftMPU

SoftMPU is a clever piece of software for MS-DOS that emulates an "intelligent-mode" MPU-401 interface, which solves the problem of older games failing to work properly with later "non-intelligent" interfaces found on Sound Blaster cards and similar.

One of its features is to allow MIDI output via the serial port instead of the game port. Unfortunately, SoftMPU cannot work with software that uses "protected mode" (e.g. via DOS extenders) such as Doom, due to the way SoftMPU's port trapping works.

To use the serial port feature of SoftMPU with mt32-pi:

  1. Set the gpio_baud_rate option in the mt32-pi configuration file to 38400.
  2. Make a connection between the host computer and the Raspberry Pi as described above and power on the Raspberry Pi.
  3. Install SoftMPU onto the MS-DOS machine and start it with SOFTMPU.EXE /MPU:330 /OUTPUT:COM1.
    • If your machine has multiple COM ports, you may need to change the output switch to COM2 or another value.
  4. Start your game. You should see the status LED on the Raspberry Pi blinking to indicate MIDI reception, and hear MIDI being played from mt32-pi.
  5. If it doesn't work, try swapping the RXD/TXD connections between the module and the Pi - some modules may be wired differently.

Windows: serial port MIDI with Hairless MIDI/loopMIDI

There are two pieces of software required to use your serial port as a MIDI device:

  • Hairless MIDI - this creates a bridge between a standard Windows MIDI device and your serial port.
  • loopMIDI - this creates a virtual MIDI device for your application/game to use.

To use them to connect mt32-pi to a modern computer via a USB to serial converter:

  1. Launch loopMIDI, type a memorable name in the "New port-name" box, and click the "+" button. This creates a virtual MIDI device for you to use. You can now close this window and it will be hidden in the system tray.
  2. Launch Hairless MIDI, open File -> Preferences and make a note of the baud rate.
    • The default of 115200 is fine, or you can increase it to reduce latency if your serial device supports it.
    • Baud rates below 31250 should not be used as they are slower than the MIDI standard baud rate.
  3. Set the gpio_baud_rate option in the mt32-pi configuration file to match the baud rate in the previous step, and start mt32-pi.
  4. Click OK to return to the main window.
  5. From the "Serial port" dropdown on the left-hand-side, choose your USB to serial device.
  6. From the "MIDI In" dropdown on the right-hand-side, choose the virtual MIDI device you created earlier in loopMIDI.
  7. Make sure the "Serial<->MIDI Bridge" checkbox is checked to enable the connection.
  8. You can now use any MIDI-capable software to output MIDI to mt32-pi by setting it to use the virtual loopMIDI device you created.
    • A good test would be to try playing a MIDI file with a program such as MidiPlay.

DOSBox configuration

To use DOSBox under Windows with the setup described above, you can carry out the following:

  1. Launch DOSBox, type MIXER /LISTMIDI, and make a note of the number corresponding to the virtual MIDI device you created earlier. This is the ID of your MIDI device.
  2. Open your DOSBox configuration file and find the [midi] section. Set mididevice=win32, and midiconfig to the ID you noted earlier (e.g. midiconfig=2).
  3. Relaunch DOSBox and start a game. You may need to configure the game to use MT-32 or General MIDI music output. You should see the status LED on the Raspberry Pi blinking to indicate MIDI reception, and hear MIDI being played from mt32-pi.
Clone this wiki locally