Hi, i'm trying to build a control unit for my home cockpit.
After some planning on paper i realised i need at least 32 pushbuttons and at least 6 rotary encoders and 2 LCD displays. Probably 32 outputs for control lights showng various system states.
Arduino Uno(nano) + port expanders or Arduino Mega as a the main MCU. The two LCD has i2c backpacks.
What the project should achieve: one control at a time should be moved, no need for combinations.
Response time is not a priority (within sane limits) non bouncing controls are.
Communicatios with my PC thru usb serial.
My questions or where i need some advice:
would the Arduinos processing power be adequate for debouncing that many inputs if i want to use interrupts and still handle the displays and the comms with the pc.
Do i need to consider an external power supply or the usb should do?
Is there a library for reading rotary encoders via a serial port expander? like the mcp23017.
Processing power for just reading those inputs is no problem, the question is: what does the Arduino have to do with the readings?
I'm sure it'll be the easiest to use a Mega instead of Uno + port expanders. Debounce can be done in hardware, just add a small capacitor (around 100 nF will do, value is not critical) parallel to the button. No need to burden the Arduino with that, even though it doesn't take much processing power.
First of all my apologies for the late answer but life came and have had no time for this...
The Arduino only has to send the states of controls to the PC and recieve some limited data via serial and thats about it.
The 100nF capacitor seems to work fine but i still have problems and a i would not want to commit before they are solved or proven unavoidable.
So here is what i found out:
I set up an encoder with two 100nF caps parallel, 2 10K pullups and a logic analyser. Seemingly perfect, not glitch or bounce. The filtering in the analyser software is turned off so i get raw input.
If i hook the encoder up to the Arduino using the internal pullups i do get some bounce every now and then. Why?
Should i put the caps close to the encoder or the Arduinos input pins?
Printing a counter on an lcd i get about 80% reliability.
The internal pull-ups are pretty weak, about 30k. Try adding 10k external pull-ups instead. I have no personal experience with encoders, but you mentioned it seems to work fine on your logic analyser with 10k pull-up resistors.
Changed to external pullups with no real difference. At slow speeds there are no bounces, at high there are a few but still wouldn't account for the data loss.
If i turn 10 clicks at a really moderate speed i can count 10 negative pulses on the analyser.
On my LCD i count 5-8. Thats 20-50% data loss.
My code must be really inefficient or just faulted.
piel:
Changed to external pullups with no real difference. At slow speeds there are no bounces, at high there are a few but still wouldn't account for the data loss.
If i turn 10 clicks at a really moderate speed i can count 10 negative pulses on the analyser.
On my LCD i count 5-8. Thats 20-50% data loss.
My code must be really inefficient or just faulted.
Your encoders are switches with an "OPEN" between detent position.
How fast are you turning the encoder? With slow speeds this code can work. But if you are turning the encoder very fast at all then it is often necessary to use interrupts to catch all the transitions. Here is some example code that handles encoders from an interrupt using direct port reads to be sure to catch everything:
The shortest negative pulse is 12.45ms at this speed, it missed 4 out of ten steps. I would not say this is fast.
I count only one transition not the complete movement because i need one step per click. In case it wasn't clear i want to use it to change radio frequency or the altutide setting for the autopilot etc.
The reason i wanted to write my own code is i need at least 6 possibly 8 encoders and interupt pins are scarce. I had success with a found example with interrupts.
My two questions: can you explain to me WHY my code is too slow (even when there is nothing else in the loop)
If i need that many encoders what design options i have? I have a few ideas but so far lucked out and would be nice to hear from someone more experienced.
Leobodnar boards (www.leobodnar.com) come in various sizes and characteristics (to build a joystick, button boards of 32 and 64 buttons, etc) and use another type of SW where there is no programming needed.
You can look for both solutions on youtube and you will see there are no issues with the bouncing.
Leobodnar boards (www.leobodnar.com) come in various sizes and characteristics (to build a joystick, button boards of 32 and 64 buttons, etc) and use another type of SW where there is no programming needed.
You can look for both solutions on youtube and you will see there are no issues with the bouncing.
Hope it helped!
My first idea was along the same lines but i realised that i don't want a custom game controller but a two way system. I knew about the mmjoy but not the leobodnar stuff. At least i know now where to buy a dual encoder.
Thank you for the links i'll save them till later.
I still would like to roll my own which is half the fun.
I am aware that there are a lot of ready made stuff available for cockpit builders but i'd like to make my own.
Thank you for the links. The reference design is really interesting. The others seem to be too expensive for my project.
Found a small board with LS7366R but it costs 30$ a piece, i might need to look at some other solution.
I have read you asked about a library that reads rotary encoders with MCP23017 ic.
I have been working on the same type of project, and had the same problem, and took a lot of time to solve that problem. I made a topic for that which you can find here.
I am using MCP23S17 in my project which is almost the same, but uses SPI instead of I2C which is a quicker interface.
Sorry, at the moment i don't have time to read the whole topic, so this problem for you might have already been solved, but if not, i hope my post will help you a little bit.