Rotary Encoders in Colour on the i2c Bus

This is a follow-up to my previous writings on the subject of rotary encoders: Rotary Encoders on the i2c Bus. This time I am using the Sparkfun Rotary Encoder – Illuminated (RGB) (Part: COM-10982), this has the same rotary goodness as the SparkFun 12-step rotary encoder but with the addition of three LED’s to provide a whole host of colours on the rotating shaft.

Test Setup

Again I will be using the MCP23017 port expander to add 16 digital I/O ports to the Arduino via the i2c bus,  the rotary encoder part operates in the same manner as before and we can use the internal pull-up resistors to reduce the number of components. The LED’s operate with a common anode and the push button also operates on 5v rather than the usual switching to ground.

For my test setup I have connected the rotary encoder to GPA0 and GPA1, the push button to GPA2 and the Red, Green and Blue LED’s to GPA5, GPA4 and GPA3. Note the 10K pull-down resistor on the push button.

My program on the Arduino changes the colours as you rotate the shaft, you will see seven colours, to see more you would need to use PWM to control the LED’s brightness. With the common anode on the LED’s the logic for switching them is inverted, so HIGH = off, LOW = on. You will need the Adafruit MCP23017 Arduino Library.

Links

9 thoughts on “Rotary Encoders in Colour on the i2c Bus”

  1. Can I “interrogate” you a bit about resistors?
    I calculated the LED resistors to be 120 ohm for the red and 104 ohm for the green and blue but as this is only the second time I’ve tried resistor/LED calculations… I don’t exactly trust myself. and seeing your values of 220 ohms for all 3 has made me want to ask you how you came by those values.

    I noticed you’ve got pull-up resistors on SCL and SDA… I’m using SPI not I2C, so it’s a bit different but I’ve not included pull-ups or pull-downs on any of my SPI lines… I’d love to hear opinions on that too.

    Nice to see stuff online about projects with this encoder… there’s still not that much information around.

    1. Hello Andrew.
      Not sure about the SPI bus, I’ve not had chance to play with that sort of thing. The advice for pullups on the I2C bus seems to vary, I can’t remember why I put them in at the moment.

      The 220R resistors on the LED’s are used to limit the current, LED’s will take all they can eat until they go pop. The datasheet for the rotary encoder says the forward current for the LEDs is 25mA.

      So V / R = I: 5v / 220R = 0.023A x 1000 = 23mA. Or to put it another way: V / I = R: 5v / 0.025A = 200R, I used 220R as those are the best value I have below the maximum rating.

  2. Thanks for that… and thanks again for the original post… some useful information on a “not discussed enough” component.

  3. I did (5V – 2V) / 25mA = 120 Ohm
    & (5V – 3.3V) / 25mA = 68 Ohm
    But, like I said, I don’t trust that I’m doing the right thing.

    1. where do these 2v and 3.3v come from? The voltage you use to calculate is whatever is on the common input (common anode) of the LED’s. The current also needs to be within the tolerance for that of the MCP23017.

  4. Oh… I think I’m beginning to get it… you’re not only protecting the LEDs… you’re limiting the current load from the MCP23x17 too. Good job I saw this before going ahead and trusting my own calculations. Thanks again for this article.

Leave a Reply

Your email address will not be published. Required fields are marked *