Encoders Spin Us Right Round

Rotary encoders are great devices. Monitoring just a few pins you can easily and quickly read in rotation and direction of a user input (as well as many other applications). But as with anything, there are caveats. I recently had the chance to dive into some of the benefits and drawbacks of rotary encoders and how to work with them.

I often work with students on different levels of electronic projects. One student project needed a rotary encoder. These come in mechanical and optical variants. In a way, they are very simple devices. In another way, they have some complex nuances. The target board was an ST Nucleo. This particular board has a small ARM processor and can use mbed environment for development and programming. The board itself can take Arduino daughter boards and have additional pins for ST morpho boards (whatever those are).

The mbed system is the ARM’s answer to Arduino. A web-based IDE lets you write C++ code with tons of support libraries. The board looks like a USB drive, so you download the program to this ersatz drive, and the board is programmed. I posted an intro to mbed awhile back with a similar board, so if you want a refresher on that, you might like to read that first.

Reading the Encoder

The encoder we had was on a little PCB that you get when you buy one of those Chinese Arduino 37 sensor kits. (By the way, if you are looking for documentation on those kinds of boards, look here.; in particular, this was a KY-040 module.) The board has power and ground pins, along with three pins. One of the pins is a switch closure to ground when you depress the shaft of the encoder. The other two encode the direction and speed of the shaft rotation. There are three pull-up resistors, one for each output.

I expected to explain how the device worked, and then assist in writing some code with a good example of having to debounce, use pin change interrupts, and obviously throw in some other arcane lore. Turns out that was wholly unnecessary. Well… sort of.

Continue reading “Encoders Spin Us Right Round”

The Hard Drive MIDI Controller

[shantea] builds MIDI controllers, and after a successful first endeavor with a matrix of buttons and knobs, he decided to branch out to something a little bit cooler. It’s called Ceylon, and it’s effectively a turntable controller built from an old hard drive.

As a contrast to the first MIDI controller, this would be a stripped-down build, with just three faders, LEDs for eye candy, a pair of pots for gain control, and a hard disk surrounded by six anti-vandal buttons. The hard disk is the star of the show, acting as a rotary encoder.

When manually spun, the hard disk generates a few phases of sinusoidal waves. The faster you spin it, the higher the amplitude and frequency. These signals are far too weak to be sampled directly by a microcontroller, and for digital control – as in, MIDI – you don’t need to read the analog signals anyway. These signals were turned digital with the help of an LM339 quad comparator. With two of these comparators and signals out of the hard disk that are 90 degrees out of phase, quadrature encoding is pretty easy.

The software for this MIDI controller is based on the OpenDeck Platform, a neat system that allows anyone to create their own MIDI controllers and devices.  It’s also a great looking board that seems to perform well. Video below.

Continue reading “The Hard Drive MIDI Controller”