Jump to content

Banner.jpg.b83b14cd4142fe10848741bb2a14c66b.jpg

Using (Multiple) Rotary Encoders with Arduino


Macavity

Recommended Posts

For all you Arduino Lovers out there, here's
some information, plus a vague question! 🥳

I am currently seeking to read multiple (i.e. Eight) Rotary Encoders with
an Arduino Mega! Conveniently there is a LIBRARY that does just that:
https://www.pjrc.com/teensy/td_libs_Encoder.html

The main problem is that neither the Arduino or Arduino "Mega" have
many (classic) interrupt pins... Two and Six resp. Has anyone tried to
enable additional "PINT" pins... used external CMOS... Bus Expanders? 🤔

FWIW, just bought myself a Teensy 2++ (5 Volt, 8-bit compatible etc.)
That (the Teensy family) could give me LOTS of interrupt pins to use?  😎
Then I could [somehow] transfer the data from Teensy to Arduino?!?

Anyway, I hope someone found the above (encoder) LINK useful!
Just relieving a bit of boredom while searching though code / libs
(arguments?) that never achieve *quite* what I am looking for... 🤣
 

Link to comment
Share on other sites

In my experience microcontrollers rarely have many interrupt pins. The external hardware is normally designed such that lots of sources can generate the interupt (typically using an open collector/drain signal) and then it's down to the interrupt service routine to determine the true source.

  • Like 1
Link to comment
Share on other sites

2 minutes ago, Seelive said:

In my experience microcontrollers rarely have many interrupt pins. The external hardware is normally designed such that lots of sources can generate the interupt (typically using an open collector/drain signal) and then it's down to the interrupt service routine to determine the true source.

Yes, that's the way I've generally seen it done.

If you're already using the Teensy though Chris, can't you do the entire job with that?

James

  • Like 1
Link to comment
Share on other sites

Thanks both - Always nice to find people who "talk the same language"...
True that -- Microprocessors etc. not having all THAT many interrupts!) 🤔

I did wonder about the idea of "OR-ing" together encoder outputs into
"one big" interrupt somehow? lol. But decided to try the Teensy route
(as you say, James) "do everything". Have an LED-flashing Teensy now! 🥳 
Can compile / load Teensy code via Standard Arduino GUI (extension).

The rest of the circuit (the MIDI controller thing!) is Arduino Mega based
and e.g. reads out 2,4... 8 way rotary switches non-digitally using resistor
chains and Arduino analogue inputs. I use a FEW *BCD* rotary switches
for 16-way rotary inputs which only have four outputs to read digitally!

My idea is now is to move up to (say) 24-way "rotary switches"  and use
rotary encoders! Works fine with one or two! The results is used(!) and
displayed on multiple LCDs  which are connected via I2C bus etc. etc.

If anyone is interested I'll keep you all posted as to whether it works! 😉
It's been an interesting (ocasionally challenging) exercise for an
old-programmer (during lockdown)  - If nothing else! 😛

Edited by Macavity
  • Like 1
Link to comment
Share on other sites

Hey it works! Or at least the prototype with an with 8-bit, 5 Volt, 16MHz Teensy 2.0++ does. 😎

Prototype.JPG.5f518b4a09c70e872f6006908b72796f.JPG

But I then LOSE two of the eight interrupts to the (needed) I2C display bus (top right)
and two more are quasi-inacessible 0.05" spaced holes in the middle of the board! 😛

But all in not lost! I decided to bite the bullet and buy a Teeny LC ("low cost") board...
That has a total of 18 interrupts - So each of eight encoders can have one for each pin!

TeensyLCsmall.jpg.23ca6911091bf40029b01c0b0702c07e.jpg

OK, the "LC" is a 3.3V system, so I will now have to be careful to use 3.3 to 5V level
translators for I2C. The Teensy LC can be seen at lower right with TWO of the latter! 🥳

However (again! lol). I LOSE one interrupt pin to the "LED pin"... leaving 17! And then
there is (again) the I2C bus... leaving 15? (Ideally I would like 16)! BUT WAIT: This time
there is a second I2C bus on two non-interrupt pins? But I still have to *test* that out!

But at least it will fit (lower right) into the increasing confusion of the entire project! 🤣

Progress.JPG.e01576e87d66ac550ed6d95c626dd763.JPG

If in doubt, throw in another CPU? lol. But I don't feel TOO badly. The Teensy LC is
not too pricey (even in the UK) - We live in the time of the "internet of things"? 😁

ANYWAY I now know how to read a reasonable number (2+) of Rotary Encoders!
https://www.pjrc.com/teensy/td_libs_Encoder.html

P.S. There are others solutions... Using (say) the MCP23017 I2C port expander:
https://github.com/maxgerhardt/rotary-encoder-over-mcp23017 🤔

GITHUB is a wonderful resource replete with work of [IMO] hugely talented
programmers! But I sense a lot of projects die... Software is unsupported etc.
Hey, programmers (sometimes even Astronomer) need REAL LIVES too?!? 😛

Edited by Macavity
  • Like 1
Link to comment
Share on other sites

  • 5 months later...

Glad to see you got it working. I use the same library for my esp8266 encoder dome tracker. All gpio s on that chip bar one can be used as interrupts. 

It's quite hard to use the i2c expander to do this but there are dedicated chips to do this which you can interrogate via i2c and I believe the teensy has two internal encoder interfaces built in for free. 

But I use the same interrupts to directly measure pulse frequencies up to 200khz . 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. By using this site, you agree to our Terms of Use.