Leonardo multiple usb endpoints for midi gamport, ps/2 keyboard

I'm trying to use my leonardo to emulate a gameport. It needs to send 4 analogue inputs, 4 digital inputs (switches) and midi in and out via USB. There are libraries that do this separately. I've used control_surface for the midi. There are HID libraries/code for the joystick and keyboard functions. My question is can all this be done on one leonardo? Can I plug it into a USB port on a computer and get a midi device, a joystick/gamepad, and a keyboard?

I'm new to arduino development but willing to learn. This is really question about the capabilities of the atmega32u4. I've read it can do 6 usb endpoints, but 3 are taken by the serial port. I'd be happy exclude midi out, which would mean 3 endpoints. However, I've also think I've read that these are paired as 3 ins and 3 outs, so this mightn't be possible. Any advice gratefully appreciated!

Check out this which pushes the 32U4 (Leonardo) pretty far

GitHub - necroware/gameport-adapter: GamePort adapter to connect old DB15 joysticks to USB port

I have used the 32U4 for HID but not extended it into the territory you are considering. Finding the enabling lib may be a challenge unless you really search the net.

I'd seen that one. It's very well coded, I think I can use as a base. However, it doesn't incorporate midi in or out, or the ps/2 keyboard. The problem is that the control_surface library uses too much memory. If I use it, I think I can only do midi. There has to be a better way...but that's not really what I came to ask about. Can I get this many usb devices out of a Leonardo, assuming the code can be done efficently enough?

Unknown.
The uC is old and challenged with 2.5K SRAM and 32K flash.

@iamjustanotheruser, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project :wink: See About the Installation & Troubleshooting category.

A "full speed" device like MIDI requires 3 endpoints, and I think the normal Arduino retains the "serial" port (also three endpoints) for upload purposes, so support MIDI plus HID seems pretty doubtful. I don't think you get to make a "standard" port like MIDI uni-directional to save endpoints :frowning:

Use one of the SAM21 boards. 16 endpoints, plus lots more memory and code space.

1 Like

Thanks. I tried to change the category when I was posting but the drop down box wasn't working.

Thanks heaps. I think it's possible to send the midi data via the serial interface and then unpack it with software (hairlessmidi), so have USB HID for keyboard and joystick and then send midi by the serial port.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.