Reading LEDs for crowdsourcing kits: Which way and why does it matter?

Email a Friend

In February, WNYC set out to design and build Cicada Trackers for the emergence of Brood II that occurs every 17 years. During development of the prototype we ran into a minor hurdle:  We wanted our listeners to be able to read the temperature from their sensor, but the kit we wanted to use lacked the 7-segment LEDs needed to present the temperature in a human readable form. Worried that not all Radioshacks stocking the Arduino Uno and SideKick Basic Kit For Arduino would necessarily have 7 segment LEDs we decided instead to use the LEDs that shipped with the Basic Kit.

Our first prototypes were a success; the thermometer was reasonably accurate. The website readily converted a bit pattern into a temperature. Everything worked well until we handed the sensor to somebody outside of our team to try.  Their immediate response was "Which way do we read it?"

At the time, the unit’s output was a line of LEDs displaying the thermometer’s value as a binary number. Numbers in this form are not all that different from the decimal numbers we work with every day. We know for example 1,234 is (1 * 1000) + (2 * 100) + (3 * 10) + (4). Binary numbers work much the same way, but i in increments of two instead of ten. 10,011,010,010 is (1 * 1024) + (1 * 128) + (1 * 64) + (1 * 16) + (1 * 2). Like a decimal number, reversing the order of the digits in a binary number changes its meaning. Just as 1,234 and 4,321 are not the same number in decimal, 10,011,010,010 when working in binary.

In our first revision we changed the color of one of the LEDs so our builders knew which end was the beginning. This worked well until we asked people outside of our project to test our instructions. Almost half the time the different colored LED was installed on the wrong side rendering the sensor useless. How nice it would be to be able to answer "It doesn't matter" to the question of the LED’s direction.

With that in mind, I began working on a way to encode a number so we could detect if it was entered backwards. From this effort I developed the directional parity algorithm used in the WNYC Cicada TrackerThis algorithm has proved useful for our builders but anyone hoping to use it in their own code would be unable to. In our initial version the encoder is specific to the Arduino, the decoder is in Javascript and both versions are hard coded to only work with 9 bit values.

Yesterday I released a general purpose version of of the directional parity algorithm written in Python. It works with numbers of arbitrary size and includes command line versions for shell script users. In the days to come I anticipate adding libraries for other languages as well. Feel free to download and let us know what sort of applications you’re using it for.