Close
0%
0%

EncoderLib

Micropython library to handle a rotary encoder

Similar projects worth following

EncoderLib is a library to handle a rotary encoder in MicroPython.

Direct download link (zip)

Functions:

encoder(clk, dt)

The encoder function initializes the library and it takes two parameters:

1. clk = pin number clk pin

2. dt = pin number dt pin

Example:

e = encoderLib.encoder(clk, dt)
getValue()

The getValue function returns the current rotary location.

example:

import encoderLib

last = 0
e = encoderLib.encoder(12, 13) # Initializes the library with pin CLK on 12 and pin DT on 13

while True:                    # Infinite loop
  value = e.getValue()         # Get rotary encoder value
  if value != last:            # If there is a new value do
    last = value
    print(value)               # In this case it prints the value

  • 1 × Rotary encoder
  • 1 × ESP8266
  • 1 × Serial to USB adapter

  • Update: Timers and interrupts

    bram08/28/2016 at 14:06 0 comments

    There is a new version of the library available that uses a timer instead of a non-blocking delay. This has no affect on the function of the library but makes the code simpler to understand and read.

    I have also been working on using pin interrupts instead of checking the pins every 5ms. There is some code in the dev branch on github but it doesn't work yet. The code gives a memory error on pin interrupts.

  • Remote rotary encoder (part 2, software)

    bram08/22/2016 at 18:52 0 comments

    The code of the remote uses the UDP protocol to send the number of rotations to the client. The python code of the server(send.py) should be edited so line 4 has the IP of the client and the code of the client (recv.py) should be edited so line 7 has the IP of the ESP8266 that is running the client code.

    The client has a neopixel stick with 8 neopixels connected at pin 12. Here is a video of the remote dimming the neopixels:

  • Remote rotary encoder (part 1, hardware)

    bram08/19/2016 at 19:24 0 comments

    For the remote rotary encoder I use a spare board that I designed for another project. The board has the size of a normal flash drive and on board are: a ESP8266-03, a 3.3v regulator and a capacitor. And there are a few connections broken out: 2x GPIO, UART, Bootloader button and a second pair of power connections.

    This board is perfect for this project because every necessary connection is available. On board is a bootloader button but I connected another button to is so I could access it without opening the case. The rotary encoder used in this project is a simple breakout from china like this one and is easy to wire up. It has 5 pins:

    1. CLK --- Clock
    2. DT --- Data
    3. SW --- Switch (On my module I had to solder on a 10k resistor)
    4. VCC --- Power
    5. GND --- Ground

    Wiring:

    • GPIO 12 --- CLK
    • GPIO 13 --- DT
    • SW --- Not connected
    • VCC --- 5v
    • GND --- GND

View all 3 project logs

Enjoy this project?

Share

Discussions

de∫hipu wrote 08/23/2016 at 11:26 point

Nice to see a new library! Have you considered making the code pep8-compliant, so that it fits the rest of the python libraries better?

Also, perhaps using pin interrupts would make it more robust?

  Are you sure? yes | no

bram wrote 08/23/2016 at 12:46 point

The code is now PEP8 compliant. And I will take a look at pin interrupts.

Thanks for the feedback :)

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates