Enabling Zynthian USB Printer Port for MIDI Output

Hi,

I would like to use the USB “printer” port on the Zynthian mainboard to send MIDI messages to an external device (computer, synthesizers, etc.). I am currently running Raspberry Pi OS, and I would like to know how to enable this port so that when I connect the hardware to a PC, it is recognized as a standard MIDI device.

Specifically, I’m looking for guidance on configuring the USB port as a USB-MIDI class device and exposing it via the USB gadget subsystem or any relevant kernel modules that are required. Any pointers on device tree overlays, ALSA MIDI configurations, or necessary firmware would also be appreciated.

Thank you in advance!

Best regards, João Pedro

I vaguely remember it’s been mentioned here before, try a search?

Hi @soumello :slight_smile:,

Can you please clarify what your hardware setup and operating system environment are?

You mention a Zynthian mainboard with USB-B (“printer”) port and RaspberryOS in the same sentence, which is a bit odd, since the Zynthian MB is designed to work specifically, if not exclusively, with ZynthianOS (Oram or Vangelis) while Raspberry OS is conceived to run on every Raspi SBC.

Anyway, the hierarchy of the USB A-to-B gadget mode connection is not reversible: the appliance with a B port acts as an USB target/receiver (device) and the appliance with an A port acts as a master/transmitter (hub). Thus, the USB B port of the Zynthian MB makes it visible to an external computer as a Midi Out destination (USB device), but Zynthian cannot operate symmetrically as a Midi controller (USB host) on the same connection, just as a printer is not meant to drive a computer.

Conversely, USB (B) gadget appliances hooked to the Raspberry USB A ports will be enumerated as external Midi Out destinations, if they are class-compliant devices that expose to the Linux-Debian subsystem their USB Midi classes and drivers.

Cheers :rainbow:

1 Like

An official V5 has a USB type B connector which may be connected to a host, e.g. computer. It will present zynthian as a USB MIDI device. This is already enabled in zynthianOS.

2 Likes

I’d like to clarify that the Zynthian mainboard can indeed be used with Raspberry Pi OS. It only requires some adjustments in the config.txt. Basically, the audio interface on the mainboard is a HiFiBerry, which has native support in Raspberry Pi OS, and the 5-pin MIDI ports can be handled via ttymidi. I am already running the Zynthian mainboard under Raspberry Pi OS without issues.

As you may know, Zynthian OS is essentially a customized Raspberry Pi OS with additional software layers. For my project, I intend to add an auto-sampler functionality, which means I want to send MIDI notes to an external device and record the notes it plays. I have already accomplished this via the 5-pin MIDI interface.

My specific question is: how can I enable the USB-B port on the Zynthian mainboard (located next to the power supply) so that the hardware can be connected to a computer and recognized as a standard MIDI device?

Any guidance on configuring the USB gadget mode on the Zynthian mainboard under Raspberry Pi OS would be greatly appreciated.

Thank you in advance!

1 Like

In /boot/firmware/config.txt

# Enable OTG
dtoverlay=dwc2

Please remember to explain, each time you post a new topic, that you are picking the zynthian project’s brains for your own, non-zynthian project. We won’t necessarily remember who you are or what you are doing between threads/topics and it will be assumed that topics on the zynthian forum relate to zynthian… suprisingly!!! As stated above, the configuration to enable OTG already exists in the zynthianOS (custom Debian).

Hello,

Apologies for the confusion, I’m new to this forum! To clarify: I am not using Zynthian OS. I purchased the Zynthian mainboard for a personal project as a keyboardist, since I want a device with auto-sampling capabilities, and the Zynthian board fits perfectly for this purpose.

Regarding the config.txt, I already have it set as:

dtoverlay=dw2

However, when I connect the board to my computer via USB, nothing is detected—the computer doesn’t even make the usual connection sound.

Do I need to install any additional drivers for it to work as a USB MIDI device? Also, should this USB output appear in amidi -l or aconnect -l on my system?

Thank you in advance for your guidance.

Best regards, João Mello

What version of RPi do you have?

raspberry pi 4 latest version OS 13

Have you looked on the Raspberry Pi, Debian, Raspbian forums for an answer? I would expect it to be similar but we are using Debian 12 so things may have changed for Debian 13.

I searched on Raspberry Pi, Debian, and Raspbian forums but couldn’t find a definitive answer specific to the Zynthian mainboard USB-B port on Raspberry Pi OS 13.

I also investigated this further and ChatGPT suggested that on Raspberry Pi 4 (non-Compute Module), the USB OTG device mode might not be exposed in the same way as on CM3/CM4, even if the mainboard has a USB-B connector. According to that explanation, the USB-B port would only work in gadget mode when using a Compute Module (CM3/CM4), not a standard Raspberry Pi 4 board.

Could you confirm whether the Zynthian mainboard USB-B port is expected to work as a USB gadget (e.g., MIDI device) with a standard Raspberry Pi 4, or only with Compute Modules?

As described above. The official V5 uses a Raspberry Pi 5 and previously a Raspberry Pi 4 and OTG USB MIDI works out of the box.

Hi @soumello!

Configuring the RPi’s USB-C port for OTG is not something specific of zynthian nor the zynthian mainboard. This forum is not the best place for this kind of highly technical system-related questions, anyway, the zynthian-sys repository includes the needed bits for it, as ZynthianOS currently does. Take a look at:

And of course, the config.txt:

# For more options and information see
# http://rptl.io/configtxt
# Some settings may impact device functionality. See link above for details

# Additional overlays and parameters are documented
# /boot/firmware/overlays/README

# Automatically load overlays for detected DSI displays
display_auto_detect=1

# Automatically load initramfs files, if found
auto_initramfs=1

# Don't have the firmware create an initial video= setting in cmdline.txt.
# Use the kernel's default instead.
disable_fw_kms_setup=1

# Run in 64-bit mode
arm_64bit=1

# Run as fast as firmware / board allows
arm_boost=1

[cm4]
# Enable host mode on the 2711 built-in XHCI USB controller.
# This line should be removed if the legacy DWC2 controller is required
# (e.g. for USB device mode) or if USB support is not required.
otg_mode=1

[all]

# Disable compensation for displays with overscan
disable_overscan=1

# Force HDMI output
hdmi_force_hotplug=1

# uncomment to increase signal to HDMI, if you have interference,
# blanking, or no display
#config_hdmi_boost=4

# Disable Splash Screen
disable_splash=1

# Boot at full CPU freq
initial_turbo=30

# Allow maximum current in USB ports (Pi5 => 1.6A, Pi4 => 1.2A)
usb_max_current_enable=1

[pi5]

# Is this needed on Pi5?
# Fix core freq for avoiding fluctuation on SPI freq (RGB LEDs)
#core_freq=500
#core_freq_min=500
[pi4]

# Fix core freq for avoiding fluctuation on SPI freq (RGB LEDs)
core_freq=500
core_freq_min=500
[all]

# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=i2c_arm=on
dtparam=i2s=on
dtparam=spi=on

# Uncomment to change I2C clock. Default is 100000.
#dtparam=i2c_arm_baudrate=400000

# Enable MMAP support (Jackd, etc.)
dtoverlay=i2s-mmap

# Enable UART for MIDI
enable_uart=1

[pi5]
# Enable tty0 on RPi5
dtoverlay=uart0-pi5
# Enable OTG
dtoverlay=dwc2
[pi4]
# Swap back the ttyAMA0 to GPIO
dtoverlay=miniuart-bt
# Enable OTG
dtoverlay=dwc2
[pi3]
# Swap back the ttyAMA0 to GPIO
dtoverlay=miniuart-bt
[all]

# Adjust UART clock for MIDI Baudrate (31250)
dtoverlay=midi-uart0

# Enable RBPi Onboard Audio (Headphones) => loads snd_bcm2835
dtparam=audio=on
audio_pwm_mode=2

# Soundcard Config
dtoverlay=hifiberry-dacplusadcpro
force_eeprom_read=0

# Display Config
#display_lcd_rotate=2

dtparam=rtc=off
dtoverlay=i2c-rtc,rv3028

Specifically, the lines containing:

# Enable OTG
dtoverlay=dwc2

For higher details of how to configure OTG for your application, please, dive into more specialized forums, like the RBPi forum or technical linux system forums. For instance:

or:

https://linux-sunxi.org/USB_Gadget/Configfs

Good look!

2 Likes

Hi! Thanks for the reply.

What is confusing me is that the Zynthian mainboard has a USB-B (“printer-style”) port, and my goal is to make that port behave as a MIDI device, while the USB-A ports behave as MIDI hosts.

I am not trying to use the Raspberry Pi’s USB-C port for this.

From what I understand, the solutions usually discussed in those forums explain how to make the Raspberry Pi USB-C port work as a USB MIDI device (using things like dtoverlay=dwc2). However, what I’m actually interested in is using the USB-B port on the Zynthian mainboard for that purpose.

Because of that, I’m a bit unsure if dtoverlay=dwc2 would apply in this case, since it seems to be specific to configuring the Raspberry Pi’s USB-C port in device mode.

So my question is really about whether the USB-B port on the Zynthian mainboard can be configured to behave as a MIDI device, while keeping the USB-A ports working as MIDI hosts

You don’t have to perform any DIY actions @soumello, if you want Zynthian to be seen as a receiving Midi device on USB-B, from an external DAW or sequencer. If you own an official V5 mainboard, ZynthianOS Is simply designed to use the USB-B port automatically in your desired way.

What you cannot do is using that port to connect to the Z another device, that Z can see as an external Midi destination.

I did a bit of research some time ago, and discovered that, unless you delve into very tricky and probably unsuccessful exoteric low-level hardware settings, the polarity of the OTG gadget mode of USB-B ports cannot be reversed. The unit carrying the hexagonal female connector is the target/receiving device, and the other appliance with the USB-A connector is the master/transmitter, and that’s all! :wink:

Kind regards :rainbow:

1 Like

The zynthian mainboard USB-B is wired to the RBPi USB-C port. They are the same port

It’s the only USB port in the RBPi that can be configured for OTG (device mode).

Regards

1 Like