Setup Menu Uses Text Editor Hack

Many embedded devices that require a setup menu will use a USB serial port which you connect to your favorite terminal emulator. But we recently encountered a generic USB knob that did setup using a text editor, like Notepad or even Vim (although that was a bit ugly). A company called iWit makes several kinds of USB knobs which end up in many such products.

These generic USB knobs are normally just plug-and-play, and are used to control your PC’s volume and muting. Some models, like the iWit, the user can configure the mapping within the device. For example, knob rotation can be set to generate up and down arrow keys, and knob press could be ENTER. One could do this kind of mapping on the PC, but many of these USB knobs can do it for you. The crux of the setup is this menu (which you can see in action in the first 30 seconds of the video below).

1 Clockwise : Up Key
2 Counterclockwise : Down Key
3 Press : Enter
4 Press+Clockwise : Next
5 Press+Counterclockwise : Previous
6 Long Press : Play/Pause

That’s nice, of course, but the surprising point is how the setup menu is implemented in the first place. The knob, already being an HID, spews forth the setup menu as if it were being typed from a keyboard. Turning the knob to select an option generates ANSI escape sequences for up and down cursor movement and somehow highlights the current line. Looking at the stream, you can see that the menus are proceeded with these codes:

ESC [ 4 ~        Private code?
ESC [ 1 ; 2 H    Cursor row 1, col 2 
ESC [ D          Cursor back one column
ESC [ 3 ~        Private code?

and item selection is simply the up and down cursor movement codes:

ESC [ A          Cursor up one row
ESC [ B          Cursor down one row

This makes sense, if we were talking to a terminal. But it’s not entirely clear how the typical text editor handles ANSI escape sequences. It’s not a big stretch to imagine that up and down cursor codes would be interpreted as arrow keys by either the operating system or the editor itself, but the highlighting remains a bit of a mystery. If you have any ideas, or have done anything similar yourself, let us know in the comments below.

The video below was found on [Nelson Chu]’s Expresii blog, an artist who specializes in simulating organic brush strokes in computer graphics systems. The particular knob used in this article was branded DROK, so you might have this capability in your USB knob even though it doesn’t say iWit on the label. If you’d like full control of your USB knob, build your own as we wrote about in this article from 2020.

19 thoughts on “Setup Menu Uses Text Editor Hack

  1. Or do like mbed and make a fake USB drive with fake files. Or make a fake Ethernet adapter and a web server to configure it. Put a dhcp server in there and it’s plug and play. Better yet, do both and put urls in the fake files that will take you to the web server. It’s just click click click and bob’s your uncle on any platform. Love the new microcontrollers with EIP quad SPI flash, tons and tons of room for all that code.

    1. That was my thought, plus some modifiers maybe. Shift+up/down to select a line (if the cursor is at the start of the line), shift+left/right to select a character, shift+ctrl+left/right to select a word, shift+end/home to select to the end/start of the line.

    1. Like 6 discrete positions? Not sure about that, but Adafruit has a bunch of “trinkey” boards that plug right in to USB A, have a samd21 (so Arduino or CircuitPython, both of which can do USB hid or serial or whatever), and some input device. I know there’s a rotary encoder one, maybe that will serve your purpose?

      1. Years ago I made a 16 position hexiadecimal switch hooked to either a serial or parallel port that I polled to determine its position. If it was unchanged, nothing happened. if it changed, then there was a program associated with its position,e.g. email, word processor, etc. It would check if that program was running. If it was, it would maximize it. If it was not, it would start it up and maximize it. The desktop was one position. (Obviously you want to make sure it isn’t in process of changing position so you check it twice.) I loved it, but no machine has either an rs232 or a parallel port any more. I would like to make one hooked to USB.

    2. You might be interested in V-USB. It’s a software implementation of low speed USB on AVR so that you can for example make them act like a HID. However its not simple stuff. Maybe somebody wrote some kind of Arduinorythingwrapper for this? You might also search for “Digispark”, small boards with Attiny85 and USB iirc (not 100% if for power only however). They are/were available on Ali and similar sites.

      1. I played around with Digisparks and used them as rubber ducky which was possible because of V-USB But if you can use a raspberry pi pico with native USB support. You could let it generate special keys and have AutoIT do your bidding (assuming your on Windows)

  2. I have one of these and it works very well as a simple volume control with press for mute. Actually bought the Surface dial first for this purpose but the movement was scratchy and cheap. Returned it and bought this. Great to have the extra hundred bucks and a better encoder.

  3. I made this a couple of years ago with an Arduino Micro that has a ATmega32U4. It uses the USB interface as HID, and works with a rotary encoder with push button to quickly control the volume and mute on my desk. 3D printed an enclosure and knob. It is one of the very few projects that I actually ever completed.

    Similarly I also made for my brother something similar in an aluminium case and three heavy duty push buttons to output keyboard shortcuts so that he can control with a foot, the start, pause, and stop recording in his studio. Also included a CLI console so it can be easily re-configured to emulate other key presses.

  4. If I was going to put a big knob on a computer I’d want the one used on Omega Race arcade games, modified to have a push/click function. The tapered metal knob had super smooth rotation and the weight just felt good. Give it a flick then rapid tap the fire button to “death blossom” the enemies.

    Tempest had a terrible knob that would groan and vibrate if spun fast.

  5. I bought one of these a year or so ago (with a different brand printed on) thinking that I could use it as a rotary controller for arcade games, but never figured out how to actually use it for that. Just tested it, this totally works. Bonkers.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.