Demonstrating Gray Codes With Industrial Display

Many people base huge swaths of their lives on foundational philosophical texts, yet few have read them in their entirety. The one that springs to the forefront of many of our minds is The Art of Computer Programming by Donald Knuth. Full of many clever and outright revolutionary algorithms and new ways of thinking about how computers work, [Attoparsec] has been attempting to read this tome from cover to cover, and has found some interesting tidbits. One of those is the various algorithms around Gray Codes, and he built this device as a visual aid.

Gray Codes, otherwise known as reflected binary, is a way of ordering an arbitrarily large set of binary values so that only one bit changes between any two of them. The most common place these are utilized is in things like rotary encoders, where it provides better assurance that the position of a shaft is in a known location. To demonstrate this in a more visual way [Attoparsec] hooked up an industrial signal light, normally used for communicating the status of machinery in a factory, and then programmed it to display the various codes. A standard binary counter is used as a reference, and it can also display standard Gray Code as well as a number of other algorithms used for solving similar problems.

[Attoparsec] built this as an interactive display for the Open Sauce festival in San Francisco. To that end it needed to be fairly rugged, so he built it out of old industrial equipment, which is also a fitting theme for the light itself. There’s also a speed controller and an emergency stop button which also add to the motif. For a deeper dive on Gray Codes and their uses, take a look at this feature from a few years back.

4 thoughts on “Demonstrating Gray Codes With Industrial Display

  1. I had a peer who avoided reading Art of Computer Programming because first they assumed it would be massive.
    Then they thought OK, it would be too dense.
    Then, because Knuth is one of the grandfathers, the book must assume a hard code C foundation, right?

    FINALLY they ready it and were surprised.!! :-)

    Example was almost over-explained, so it didn’t matter what language you knew. There were even logic examples in a hypothetical language, which might as well be Python.

    I used to write a lot of Python automation, and the book helped me to rid of some ugly mistakes I was making.

  2. I’ve implemented devices in which quadrature encoder output was decoded in software. It was a fun process of wrapping my brain around what was going on.

    I found it very interesting how quadrature (Gray code, 2 channel) signals were decoded in hardware in some now-old-timey Atari trackball controllers. That was educational. My initial software decoding efforts consisted of using a lookup table to compare sequentially captured bit states to determine the direction. There was a lightbulb moment when I saw in hardware that the direction was indicated by the value of one channel at the time the other channel changed states, e.g. if A=1 when B 0>1, then a direction is indicated but if A=1 when B goes 1>0 then the other direction is indicated.

    I never ran across the “reflected” aspect and methods for generating Gray code of, essentially, arbitrary numbers of channels.

    (The real treat for me in this article was the link to Al’s older article. I either missed it, or I have reached the age where I get to enjoy learning the same information for the first time over and over…)

  3. For some reason, this made me think of some old articles on how to hack the poor security on some old answering machines and combination locks, were the device would only check the last N digits pressed for an N length code. Looked it up and ways to create an efficient sequence for an N length code is based on De Bruijn sequences (circa 1946), which are in turn related to Gray codes. Great video that gave me a fun trip down the rabbit hole.

Leave a Reply to CGCancel 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.