ESP8266 + MCP23017 + Rotary Encoder

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
vahithosan
Posts: 19
Joined: Wed Jul 26, 2017 5:15 pm

ESP8266 + MCP23017 + Rotary Encoder

Post by vahithosan » Mon Sep 16, 2019 7:50 pm

Hi,

I want using rotary encoder over mcp23017 i/o expander. But esp8266 freeze.
I use those libraries:

Rotary encoder:
https://github.com/BramRausch/encoderLib
MCP23017:
https://github.com/ShrimpingIt/micropython-mcp230xx

Code: Select all


import mcp
import encoderLib
io = mcp.MCP23017()
io.setup(8,mcp.IN)
io.setup(9,mcp.IN)
e = encoderLib.encoder(io.input(8),io.input(9))
when i write "e = encoderLib.encoder(io.input(8),io.input(9))" after freeze.

MCP23017 pin output state "True" or "False",

Code: Select all

>>> io.input(8)
False
>>> io.input(9)
False
>>> io.input(8)
True
>>> io.input(9)
True

How can use rotary encoder over mcp23017.

Thanks

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: ESP8266 + MCP23017 + Rotary Encoder

Post by jimmo » Mon Sep 16, 2019 10:07 pm

EncoderLib expects to be passed something that it can use with machine.Pin.

You might need to modify encoderlib such that it just uses the pins passed to the constructor directly (without making them into machine.Pins first).

Let me know how that goes, I can provide more details if you want.

vahithosan
Posts: 19
Joined: Wed Jul 26, 2017 5:15 pm

Re: ESP8266 + MCP23017 + Rotary Encoder

Post by vahithosan » Tue Sep 17, 2019 10:57 am

I have no more pins on esp8266. I used it for SPI. so I want to run the rotary encoder via mcp23017.

I will try EncodeLib modify like this and I will share the results

Code: Select all

from machine import Pin
from machine import Timer

class encoder:
    # Init variables
    encoder_clk_prev = False
    i = 0

    def __init__(self, clk_pin, dt_pin):
        # Configure the rotary encoder pins and interupt
        self.clk = Pin(clk_pin, Pin.IN, Pin.PULL_UP)
        self.dt = Pin(dt_pin, Pin.IN, Pin.PULL_UP)

        tim = Timer(-1)
        tim.init(  # Timer to run self.update every 5ms
            period=5,
            mode=Timer.PERIODIC,
            callback=self.update
        )

import mcp
io = mcp.MCP23017()
self.clk = io.setup(clk_pin, mcp.IN)
self.dt = io.setup(dt_pin, mcp.IN)

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: ESP8266 + MCP23017 + Rotary Encoder

Post by OutoftheBOTS_ » Tue Sep 17, 2019 9:08 pm

another easy fix you might want to consider is switching to a ESP32 as it has more pins :)

Post Reply