Rotary Encoders Become I2C Devices

Rotary encoders are the bee’s knees. Not only do you get absolute positioning, you can also use a rotary encoder (with a fancy tact button underneath) for an easy UI for any electronics project. There’s a problem with rotary encoders, though: it’s going to use Gray code or something weird, and getting a rotary encoder to work with your code isn’t as easy as a simple button.

For his Hackaday Prize project, [fattore.saimon] has come up with the solution for using multiple rotary encoders in any project. It’s a board that turns a rotary encoder into an I2C device. Now, instead of counting rising and falling edges, adding a rotary encoder to a project is as easy as connecting four wires.

The project is built around the PIC16F18344, a small but surprisingly capable microcontroller that reads a rotary encoder and spits data out as an I2C slave device. Also on board are a few pins for an RGB LED, general purpose pins, the ability to set all seven bits of the I2C address (who wants 127 rotary encoders?), and castellated holes for connecting several boards together.

This project is an update of [fattore]’s earlier I2C Encoder, and there are a lot of improvements in the current version. It’s slightly smaller, has better connectors, and uses a more powerful microcontroller. That’s just what you need if you want a ton of rotary encoders for all those cool interactive projects.

42 thoughts on “Rotary Encoders Become I2C Devices

        1. Let’s hope the Chinese steal it and sell them for $2.

          That might sound mean, but realistically this kind of thing should be open hardware and it will benefit everybody much more than the few bucks a guy makes from selling them for $13 to a dozen people.

          And I remind you that China is a socialist country and not a full capitalist one. (Take note Trump.)

    1. What do you think it should cost? I don’t think $13 is at all out of line. I think people have become spoiled by being able to buy cheap junk electronics from Aliexpress for $1.88 with free shipping from China. If you are buying a unique item from a maker working out of their basement or garage, someone who’s not buying parts and PCBs a thousand at a time, please don’t be offended when they ask for a reasonable amount of money to make it worth their trouble to do these things.

      1. $5 shipping sounds reasonable.

        For parts:
        The CPU is $1 in small quantities (IMHO, not the best part choice, you could do it for less, possibly half)
        The rotary encoder is about $1.5 to $2.5.
        Add PCBs for $2 each (while PCBs in small quantities can be done cheap now, you still have overhead shipping costs)
        $2 for an RGB LED.
        $1 for the connectors

        So that adds up to $8.5 if you do this yourself. So $7 isn’t that bad actually.

        1. Sorry 7$ is only the pcb, no encoder, led and connector.
          For the components i spend around 2- 2.5$
          You have also to include: tax, payment fee and the eBay/Tindie fee.
          Plus the time for testing and packaging.
          And a bit of profit ????

        2. Just for my entertainment during convalescence and as a total noob in that topic I did some uneducated calculations for a batch of 1000. All prices in Euros.

          PCB build and partly assembled, including shipping, prices per item/job

          0,70 PIC16F18344-I/GZ-ND (digikey /100 price)
          0,10 14 smd parts (just a guess)

          0,50 pcb+assembly / pcbway
          (prices seem to start at 600 USD)

          0,70 rotary button PEC11R-4215F-N0024 / digikey
          0,56 rgb 5mm led WP154A4SUREQBFZGW / digikey
          —–
          2,56 (subtotal) per item

          Asuming 5 minutes per item to test, complete build, test, programm and test in some sort of
          special rig gives 84 hours of work. Calculated with DE minimum wage 8,84 € it adds per item

          0,75 DE minimum labour cost per item
          ====
          3,31 total cost of production

          I would calculate parts+labor being 30-50% of the selling price (this is where the earnings come in after the income taxes go out…), going for the lowest price this would result in

          ====
          7,00 Cost per item for buyer (just to have a round value, 11,00 for 30%, 8,30 for 40%)
          This does not include taxes. Expect to see more than +20% for Europe.

          For shippping i used some guesses, not totally optimizing it. I assume packing is done in a simple “one item per box, put in the invoice and attach printed label” to minimize brain usage.

          0,25 100x50x40 or so box
          3,70 shipping Warensendung InternationalS DHL Germany (och!)
          0,15 labour cost as before
          —-
          4,10 total international (!) shipping const

          So we have
          ====
          11,10 Customer proudly has a product in his hands.

          Discussion. 11 Euros for an i2c rotary encoder. Pfff. But with a RGB LED!!

          If I’m going for a small scale product and could need them in moderate quantities, I would manufacture such a design in my product.

          If I’m buying and my boss is paying I would like to see some “box of 10 items” options to put them in my box.

          If I’m a private cheapskate I would go for a Arduino Nano that could manage 2 knobs. This costs me 2,50 Euro (2 x 0,25 + 1,95).

          So as a seller sitting in Europe and selling from europe, this seems as a not so exciting looking business.

          The tindie shop goes one step into the right direction: offloading some cost to customer. No encoder, no RGB, less labor makes minus 2,00 Euros. Now go cut shipping costs (might be impossible due to state of origin).

          And fear the chinese. They could run a batch of 100.000 on a saturday evening, software is somehow trivial (pjrc lib, compile, i2c slave event handlers, upload, done) and alibaba, ebay and aliexpress will be full of little plastic bags for 4,00 USD each including shipping all world wide.

    1. Hopefully it gets cheaper as it’s adopted? Seems like it’s being produced at an extremely small scale at the moment. Give it a minute, it’s tough to make a product cost-effective in a small operation.

    1. Yep, article is wrong, this is a simple quadrature RPG (rotary pulse generator). Nothing “absolute” about it.

      (It would be nice if Hackaday authors were penalized for innacurate write-ups. Might improve their next atricle.)

      And I might add, that if this *was* a gray code encoded rotary switch, and you found that “weird” or difficult to interface in your Arduino code, you’re probably not much at writing code either.

    2. If you look at the documentation of addresses, It stores a running position number (Which can probably be reset at will to 0 over I2C), but also has a max and min value for it, so you could make it act like an absolute or discreet encoder. There is no “Pulse Stream” though, since that is intercepted internally on the board and locally processed into position values. Basically, it just means you can sleep easy knowing that your code won’t miss a pulse.

  1. When buying small scale production modules you pay a little extrs usually. I woukd estimate parts and effort building it myself if i needed this device.

    If you would prototype this design can save a lot of hassle.

  2. i want to control DC motors with encoders on them, would this be useful at doing this? the software part? i want to use a Teensy3.6 to control 2 motors in a plotter.

    1. If the motors already have encoders, then this would not seem to be helpful.

      Gearmotors with quad-encoded output are pretty common. Most of these put out some fixed number of quad-encoded pulses per revolution. These pulses are easy to pick off using interrupts in order to use them as something that can keep track of clockwise or counterclockwise movements. The precision that you can get in the end depends on the number of pulses in the encoder itself, the gear ratio of gearing, and the “backlash” in the gearing.

      If you have some way of getting the initial position of the system (e.g. end-stops), then you can use the information from the quad-encoder to keep track of the system overall.

      The benefit of a system like this over a stepper is that it’s closed-loop, so you can always “know” where the system is (within the limits of obtainable precision) .. and DC motors tend to have a lot more performance, pound for pound, than steppers (usually faster, and usually with more peak torque for a given size). However, controlling DC motors and keeping then them tightly synchronized to the point that you can use them for a plotter not trivial. Not crazy-difficult, but definitely not super-easy.

      A Teensy 3.6 could definitely do this, and still plenty of grunt left to spare. Even an LC can control four such motors pretty easily. Two pins to capture the quad-encoded position signal, and two pins for the DC motor controller would be a common setup,

      1. ok cool so this wouldnt apply. but the rest of your comment is brilliant! I would like to design a board that would have a socketed Teensy 3.6, 3 motor drivers, support for 3 encoders, and endstops (opto or makebot style) I would like it to run Marlin with LCD support. but seeing as this is my first foray into this, i dont know how to do that just yet. the plan is to have a board that can drop into an old printer or plotter and give the machine new life and total control of it to do as they wish.

      2. What you’re looking for is a servo controller – a PID controller driving a MOSFET bridge with current feedback that drives the motor (usually a DC brushed motor) with position information fed back to the motor from an encoder. This is a bog-standard commercial device – lots of options from Advanced Motion Controls, Gecko, Rutex, Leadshine, Ocean Controls, Maxon etc etc.

      1. I’ve always used button matrices in which I’d connect encoders. Just connect encoder A/B signals in same column. Works just fine for usual quadrature encoders (I am reading 32 encoders in 8×8 matrix on ATmega32u4).

    1. For a small home player operation? Nah, with shipping (I believe) that is perfectly reasonable. For small projects, this unit could be well worth the cost in terms of saving time or even requiring more expensive parts because you just ran out of IO on your micro board!

  3. It’s sweet that so many of you think that [fattore.saimon]’s time should be a gift to you. I’m sure he has to eat just like everyone else does.

    But hey, if you want to create something useful for us all to share then make a penny a piece on selling it, then please go right ahead.

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