# Arduino USB HID Controller

**URL:** <https://discourse.zynthian.org/t/arduino-usb-hid-controller/4814>\
**Category:** Hardware\
**Created:** [October 17, 2020, 9:35pm UTC](https://discourse.zynthian.org/t/arduino-usb-hid-controller/4814 "2020-10-17T21:35:15Z")\
**Posts on this page:** 20\
**Page:** 4

<div class="post-metadata">

**Author:** ![wyleu](https://discourse.zynthian.org/user_avatar/discourse.zynthian.org/wyleu/32/514_2.png) [@wyleu](https://discourse.zynthian.org/u/wyleu)\
**Post date:** [February 22, 2021, 4:24pm UTC](https://discourse.zynthian.org/t/arduino-usb-hid-controller/4814/62 "2021-02-22T16:24:04Z")

</div>

Thanks. I will dig …  
Actually where should I dig for the MKRZERO …?

> <https://github.com/arduino/ArduinoCore-samd/blob/master/variants/mkrzero/variant.cpp>

---

<div class="post-metadata">

**Author:** ![riban](https://discourse.zynthian.org/user_avatar/discourse.zynthian.org/riban/32/2331_2.png) [@riban](https://discourse.zynthian.org/u/riban)\
**Post date:** [February 22, 2021, 4:44pm UTC](https://discourse.zynthian.org/t/arduino-usb-hid-controller/4814/63 "2021-02-22T16:44:06Z")

</div>

Looks like the MKRZERO uses pin names D0…D7.

---

<div class="post-metadata">

**Author:** ![wyleu](https://discourse.zynthian.org/user_avatar/discourse.zynthian.org/wyleu/32/514_2.png) [@wyleu](https://discourse.zynthian.org/u/wyleu)\
**Post date:** [February 22, 2021, 5:28pm UTC](https://discourse.zynthian.org/t/arduino-usb-hid-controller/4814/64 "2021-02-22T17:28:37Z")

</div>

Doesn’t seem to make any difference. I will explore more . .

---

<div class="post-metadata">

**Author:** ![smiths73v3](https://discourse.zynthian.org/user_avatar/discourse.zynthian.org/smiths73v3/32/5452_2.png) [@smiths73v3](https://discourse.zynthian.org/u/smiths73v3)\
**Post date:** [February 23, 2021, 12:42am UTC](https://discourse.zynthian.org/t/arduino-usb-hid-controller/4814/65 "2021-02-23T00:42:17Z")

</div>

@riban is correct. These are the pin names on my microcontroller board. I’ve set this up for the ST Black Pill Clone because it has lots of GPIO pins to use. I am even using GPIO pins for the GND signal to the encoders to simplify wiring, AND I skipped GPIO pins in between the encoders so I can solder in JST connectors. So many GPIO pins…

If this is used with anything other than the Black Pill Clone(US$4) , you will need to change the encoder mappings with the Arduino pin names for your board.  
ENCODER\_DEF\_PIN\_MAP(back,PA10,PA9,PA8,PA7,PA6);  
I don’t see any way possible to wire up 4 encoders and 4 buttons on the MKZERO. You might comment out 3 of the encoders, and the buttons just to give it a try, but this seems more like a dead end.

Here is what I used:  
STM32F401 Development Board STM32F401CCU6 STM32F4 Development Board Learning Board for Arduino

---

<div class="post-metadata">

**Author:** ![wyleu](https://discourse.zynthian.org/user_avatar/discourse.zynthian.org/wyleu/32/514_2.png) [@wyleu](https://discourse.zynthian.org/u/wyleu)\
**Post date:** [February 23, 2021, 11:06am UTC](https://discourse.zynthian.org/t/arduino-usb-hid-controller/4814/66 "2021-02-23T11:06:35Z")

</div>

The MKR ZERO has 21 available Digital pins so I don’t think there will be a problem and enough of them have interrupts to allow encoders to work. Indeed I’ve already use it with 4 encoders & 4 switches using the control\_surface package.

What I was hoping to do was use your code base ( which is considerably more considered than mine) to provide a MIDI equivalent of what you have done with the keyboard approach.

My programming background has been Python based for twenty or so years and C in it’s various forms is pretty alien to me. Sadly that means that issues like Pin naming don’t come particularly easy to me. There are far too many symbols that are difficult to discover precise meaning for without literally learning it all from scratch.

---

<div class="post-metadata">

**Author:** ![smiths73v3](https://discourse.zynthian.org/user_avatar/discourse.zynthian.org/smiths73v3/32/5452_2.png) [@smiths73v3](https://discourse.zynthian.org/u/smiths73v3)\
**Post date:** [February 23, 2021, 1:31pm UTC](https://discourse.zynthian.org/t/arduino-usb-hid-controller/4814/67 "2021-02-23T13:31:39Z")

</div>

@Wyleu,

21 IO pins is more than enough. I’ll take a better look and see if I can find a good mapping. Can you send me how you have them wired up on your project? I’ll use that as a starting point.

---

<div class="post-metadata">

**Author:** ![wyleu](https://discourse.zynthian.org/user_avatar/discourse.zynthian.org/wyleu/32/514_2.png) [@wyleu](https://discourse.zynthian.org/u/wyleu)\
**Post date:** [February 23, 2021, 2:21pm UTC](https://discourse.zynthian.org/t/arduino-usb-hid-controller/4814/68 "2021-02-23T14:21:15Z")

</div>

| Pin on MKRZERO | Control | Device | Comments |
| --- | --- | --- | --- |
| D0 | Encoder | Channel | - |
| D1 | Encoder | Channel | - |
| D2 | Switch | Channel | - |
| D3 | Encoder | Back | - |
| D4 | Encoder | Back | - |
| D5 | Switch | Back | - |
| D11 | Encoder | L/S | - |
| D6 | Encoder | L/S | Swapped with pin 10 for interrupt for encoder |
| D9 | Switch | L/S | - |
| D7 | Encoder | Select | - |
| D8 | Encoder | Select | - |
| D10 | Switch | Select | Swapped with pin 6 for interrupt for encoder |
| Front panel switches | - | - | - |
| D13 | Push Button | 1 | - |
| D12 | Push Button | 2 | - |
| D20 | Push Button | 3 | - |
| D21 | Push Button | 4 | - |

[![](https://content.arduino.cc/assets/Pinout-MKRZERO_latest.png) ](https://content.arduino.cc/assets/Pinout-MKRZERO_latest.png)

I knoocked together a quick cut & paste from the SimpleRotary example and it all seems to respond.

---

<div class="post-metadata">

**Author:** ![smiths73v3](https://discourse.zynthian.org/user_avatar/discourse.zynthian.org/smiths73v3/32/5452_2.png) [@smiths73v3](https://discourse.zynthian.org/u/smiths73v3)\
**Post date:** [February 24, 2021, 2:32am UTC](https://discourse.zynthian.org/t/arduino-usb-hid-controller/4814/69 "2021-02-24T02:32:14Z")

</div>

Ok, Perfect. I’ll take a stab at it hopefully before the weekend.

---

<div class="post-metadata">

**Author:** ![wyleu](https://discourse.zynthian.org/user_avatar/discourse.zynthian.org/wyleu/32/514_2.png) [@wyleu](https://discourse.zynthian.org/u/wyleu)\
**Post date:** [March 10, 2021, 3:07pm UTC](https://discourse.zynthian.org/t/arduino-usb-hid-controller/4814/70 "2021-03-10T15:07:18Z")

</div>

Just got the switches and encoders responding with your code.

It works! ( I’d left setup code commented)

Things occur on the zynthian interface when controls are ackled .!! 😃

Fill the sky with hats !!! ⛑ 🧢 🎓 🎩 👒 🎷 🎩

There is, of course, a new thingy… Made up of two old thingy’s …

It’s beginning to look like a useable system…

 ![IMG_20210311_110738](https://discourse.zynthian.org/uploads/default/original/2X/4/467cf2c3a6940df6bcc4411fefc9b36b871a097b.jpeg) ![IMG_20210311_110919](https://discourse.zynthian.org/uploads/default/original/2X/3/383686e59a6723b8c0a2dda2fa4ed8e21407ae70.jpeg)

---

<div class="post-metadata">

**Author:** ![opadave](https://discourse.zynthian.org/letter_avatar_proxy/v4/letter/o/e5b9ba/32.png) [@opadave](https://discourse.zynthian.org/u/opadave)\
**Post date:** [March 11, 2021, 11:19pm UTC](https://discourse.zynthian.org/t/arduino-usb-hid-controller/4814/71 "2021-03-11T23:19:13Z")

</div>

Looking good sir. Nice clean wiring  
Has anyone had a go with a raspi pico yet? I’m wondering how the pio might be useful.

---

<div class="post-metadata">

**Author:** ![MaxMaxis](https://discourse.zynthian.org/letter_avatar_proxy/v4/letter/m/90db22/32.png) [@MaxMaxis](https://discourse.zynthian.org/u/MaxMaxis)\
**Post date:** [March 11, 2021, 11:51pm UTC](https://discourse.zynthian.org/t/arduino-usb-hid-controller/4814/72 "2021-03-11T23:51:32Z")

</div>

Arduino has developed their own board using the same processor as the Pi Pico, official Arduino IDE support in imminent, which will provide easier application of existing code libraries than the Pi Pico C++ tool chain.

---

<div class="post-metadata">

**Author:** ![MaxMaxis](https://discourse.zynthian.org/letter_avatar_proxy/v4/letter/m/90db22/32.png) [@MaxMaxis](https://discourse.zynthian.org/u/MaxMaxis)\
**Post date:** [March 11, 2021, 11:55pm UTC](https://discourse.zynthian.org/t/arduino-usb-hid-controller/4814/73 "2021-03-11T23:55:14Z")

</div>

Sorry to be so late, [this library header file containing about 60 MIDI messages](https://github.com/vidmo91/MIDIUSBcommands):  
including On/OFF, 7 bit and 14 bit CC , might be a useful reference.  
And for others who might be searching for code:  
The [FortySevenEffects](https://github.com/FortySevenEffects/arduino_midi_library) library has broken out a separate [Arduino USB-MIDI Transport](https://github.com/lathoub/Arduino-USBMIDI).  
If you find the Arduino assigned USB device name annoying,  
you can dig into the IDE and [patch it](http://liveelectronics.musinou.net/MIDIdeviceName.php).

---

<div class="post-metadata">

**Author:** ![wyleu](https://discourse.zynthian.org/user_avatar/discourse.zynthian.org/wyleu/32/514_2.png) [@wyleu](https://discourse.zynthian.org/u/wyleu)\
**Post date:** [March 12, 2021, 2:15pm UTC](https://discourse.zynthian.org/t/arduino-usb-hid-controller/4814/74 "2021-03-12T14:15:32Z")

</div>

@smiths73v3 Can you modify the layer parameters with your device? I can’t seem to switch out of the select encoder allowing me to scroll up and down in the parameter lists in the centre of the screen. The encoders work because I can see movement in the sequencer but can’t get any joy out of the parameters themselves.

---

<div class="post-metadata">

**Author:** ![riban](https://discourse.zynthian.org/user_avatar/discourse.zynthian.org/riban/32/2331_2.png) [@riban](https://discourse.zynthian.org/u/riban)\
**Post date:** [March 12, 2021, 4:33pm UTC](https://discourse.zynthian.org/t/arduino-usb-hid-controller/4814/75 "2021-03-12T16:33:15Z")

</div>

I don’t think this is currently possible from a QWERTY (or similar) keyboard because CUIA is not mapped / implemented everywhere. I feel this needs fixing at a low level. I added CUIA handlers for the encoders to step sequencer but it should really be in the base class from which all GUI panels derive.

---

<div class="post-metadata">

**Author:** ![wyleu](https://discourse.zynthian.org/user_avatar/discourse.zynthian.org/wyleu/32/514_2.png) [@wyleu](https://discourse.zynthian.org/u/wyleu)\
**Post date:** [March 12, 2021, 4:47pm UTC](https://discourse.zynthian.org/t/arduino-usb-hid-controller/4814/76 "2021-03-12T16:47:05Z")

</div>

Not so worried about the qwerty as the lack of layer parameters.  
We can’t map the 4 encoders to operate live for a performance, which would seem to be something we should present on implementations of our interface.

Or in more specific terms give me a nice volume control pot at top of guitar stand height!  
I’ll stick it in as a feature request.

---

<div class="post-metadata">

**Author:** ![riban](https://discourse.zynthian.org/user_avatar/discourse.zynthian.org/riban/32/2331_2.png) [@riban](https://discourse.zynthian.org/u/riban)\
**Post date:** [March 12, 2021, 4:52pm UTC](https://discourse.zynthian.org/t/arduino-usb-hid-controller/4814/77 "2021-03-12T16:52:55Z")

</div>

I pointed out that QWERTY uses CUIA and this is not exposed so you will probably suffer same constraint.

---

<div class="post-metadata">

**Author:** ![wyleu](https://discourse.zynthian.org/user_avatar/discourse.zynthian.org/wyleu/32/514_2.png) [@wyleu](https://discourse.zynthian.org/u/wyleu)\
**Post date:** [March 12, 2021, 5:01pm UTC](https://discourse.zynthian.org/t/arduino-usb-hid-controller/4814/78 "2021-03-12T17:01:01Z")

</div>

Yeah that sounds like a trip into a room left uncleared for a good tidy up!.

Would we suffer the same confusion in the MIDI implementation or would we simply expose a similarly edge case encumbered situation?

---

<div class="post-metadata">

**Author:** ![riban](https://discourse.zynthian.org/user_avatar/discourse.zynthian.org/riban/32/2331_2.png) [@riban](https://discourse.zynthian.org/u/riban)\
**Post date:** [March 12, 2021, 6:11pm UTC](https://discourse.zynthian.org/t/arduino-usb-hid-controller/4814/79 "2021-03-12T18:11:21Z")

</div>

MIDI note2cuia supports the encoder actions but the screens need to react to them so will probably have same issue.

---

<div class="post-metadata">

**Author:** ![smiths73v3](https://discourse.zynthian.org/user_avatar/discourse.zynthian.org/smiths73v3/32/5452_2.png) [@smiths73v3](https://discourse.zynthian.org/u/smiths73v3)\
**Post date:** [March 13, 2021, 5:58pm UTC](https://discourse.zynthian.org/t/arduino-usb-hid-controller/4814/80 "2021-03-13T17:58:09Z")

</div>

@wyleu and @riban  
Yes, this is what I encountered, and I tested both for QWERTY and MIDI. The CUIA interactions do not modify the UI Engine parameters. I attempted to dig into this a little bit to solve the issues, but my limited python skills, and lack of understanding of how all of the Zynth modules fit together keep getting in the way. I saw that it was complete for Step, but was not able to figure out how to do the same for the engines.

---

<div class="post-metadata">

**Author:** ![smiths73v3](https://discourse.zynthian.org/user_avatar/discourse.zynthian.org/smiths73v3/32/5452_2.png) [@smiths73v3](https://discourse.zynthian.org/u/smiths73v3)\
**Post date:** [March 13, 2021, 6:00pm UTC](https://discourse.zynthian.org/t/arduino-usb-hid-controller/4814/81 "2021-03-13T18:00:00Z")

</div>

My apologies for not getting a config up for you, my day job got in the way of my funtime… ☹ Glad to see that you have it working!

[Previous page](https://discourse.zynthian.org/t/arduino-usb-hid-controller/4814.md?page=3)

[Next page](https://discourse.zynthian.org/t/arduino-usb-hid-controller/4814.md?page=5)
