I need to use a couple of rotary encoders on my project but I am running out of pins in my ESP32 so I don't have any other choice that connect both encoders to the MCP23s17.
The problem is that all encoder libraries can't handle I/O expansor and I don't know enough to modify them.
I am looking at https://www.gammon.com.au/forum/?id=11130 which explains how a rotary encoder works but I don't know how to modify the sketch to make it work with my MCP23S17.
Which encoder are you using? The wiring is different depending on the type of encoder.
What else are the ESP pins used for? It may be easier to use them through the MCP23s17.
Without a better picture of your project we're all just guessing.
OK, well without the code your not going to make to much headway.
I have a doubt about using all the pins on the ESP32. That doubt centers around their being 2 ports on the ESP32. portA and portB. There are some limitations to using portB and I'm betting you don't know of them. And without your code, you may never know.
Oh, did you know the ESP32 has 2 SPI ports and can take 3 devices per SPI port? There is a trick to using HSPI over VSPI but once the trick is addressed one can hook up 6 SPI devices to the ESP32, again the code would be nice.
All working very well with no issues. I want also to connect a couple of encoders EC11 but I have only 2 free pullup pins on my ESP32 so I can only connect 1 encoder by now.
Problem A)
I am using ESP32Encoder library and I can wire the encoder to GPIO 21 and 22 which are the free pins.
encoder.attachSingleEdge(21, 22);
What happens is that I can only pass an int (pin number) and the library does all the job setting the pullup, etc.
It gets too complicated and messy to edit the library to make accept an MCP23s17 pin.
This happens with OneButton library too, I can only pass a board pin but not an expansor pin. I read that I could use the expansor to trigger an interruption on the board but I was not able to figure out how to.
Problem B)
The other thing I have experienced is that encoders at least the simple ones with push button aren't accurate with ESP32 and according to this and other forums is an issue with ESP32. In my experience if I turn the encoder 10 steps to the left I will get at least one read that goes to the right like non accurate. I had to implement a function that only moves if the last two read goes the same direction( i need to move two steps to turn once but it is a lot more accurate. Is this normal ? like I have to create my own system to make it accurate or it should be accurate out of the box with that libraries?
mesihas:
Ok, I have my ESP32 connected to and SPI TFT and touch (VSPI) and a MCP23S17 also connected to (HSPI).
All working very well with no issues. I want also to connect a couple of encoders EC11 but I have only 2 free pullup pins on my ESP32 so I can only connect 1 encoder by now.
Cool!
mesihas:
Problem A)
I've no experience with the expander thingy.
I got a project where i ran out of GPIO_NUM_X pins. The project uses 3 ESP32's. The brain sends and receives serial from the other 2 esp32's.
mesihas:
Problem B)if the last two read goes the same direction( i need to move two steps to turn once but it is a lot more accurate. Is this normal ? like I have to create my own system to make it accurate or it should be accurate out of the box with that libraries?
I've not used encoders. I'm sure for the best results its a write your own thing to do. I've written several libraries when the off the shelf did not do.
I tend to do my searches for libraries with the word ESP32 included; like "esp32 encoder library" which gives results of encoder libraries written to be used by an ESP32.
mesihas:
I don't know how to modify the sketch to make it work with my MCP23S17.
Any ideas would be highly appreciated.
A good answer would depend on knowing your level of expertise. Fundamentally, you would decouple the functionality of the encoder logic from the input read logic used to read processor pins, and apply the same logic to the input read logic used to read MCP pins. That is what I would do. The decoupling depends on understanding how the encoder driver code works, so that is a good starting point. But we can't explain the code for an entire library for you.
All working very well with no issues. I want also to connect a couple of encoders EC11 but I have only 2 free pullup pins on my ESP32 so I can only connect 1 encoder by now.
Is it because you only have 2 free pullup pins that is causing your problem.
If so, use pins that do not have internal pullups and fit them externally.
Going trough the comments made me think that I need to focus in other areas that are more important for this project rather than having to modify a library which requires a lot of expertise and time.
I like the idea of using pins that do not have internal pullup and fit them externally. Not sure how to achieve this.. I've been looking at expressif site but I couldn't find good info.
mesihas:
I like the idea of using pins that do not have internal pullup and fit them externally. Not sure how to achieve this.. I've been looking at expressif site but I couldn't find good info.
Can you please tell us your electronics, programming, arduino, hardware experience?
Thanks for diagram, I don't have a lot of experience with Arduino, I did a water irrigation controller 6 year ago, first version with Arduino Mega, second with ESP8266 MCULUA and finally the same but with ESP32. When migrate from Arduino Mega to ESP I had to add the expansor. The reason for the migration was being able to read/write on Firebase and the WIFI options was perfect for that. So the system is still working and controlling two pumps and 10 electro valves and a couple of sensors, If I have a closer look I always discover mistakes or things that could be done in a better way but it has been working very well from day 1 and encourages me to more things.
The current project is based on the same hardware but the functionally is about controlling a software running on my pc though WEBSOCKETS. I use a TFT to display a list of options and an encoder let me navigate over them. The idea all together works but needs more work with the encoder as it is not very accurate.
I need to investigate more about Encoders as they come in different shapes like EC11 or with a module that has diodes and resistors added like KY-040. So some libraries like the one posted on #7 uses KY-040.. while I am using simple EC11. I would like to understand the benefits of the Encoder module and how it can help me.
At programming level I am learning Arduino programming language c/c++ as I go. I work with C# and JavaScript.
My questions here are more related to the ESP32 side which has input pins 14-16-17-18-19-21-22 with internal pullup. (all used) So could I use 13-25-26-27-32-33-36-39 pins by adding a 10k resistor.?