A library for reading rotary encoders (ESP-8266 and Pyboard/stmhal)

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
User avatar
dhylands
Posts: 2565
Joined: Mon Jan 06, 2014 6:08 pm
Location: Shuswap, BC, Canada
Contact:

Re: A library for reading rotary encoders (ESP-8266 and Pyboard/stmhal)

Post by dhylands » Wed Jan 18, 2017 6:40 am

Interrupt callbacks can be class methods. This is a pyboard example, but see here:
https://github.com/dhylands/upy-example ... eat_irq.py
heartbeat_cb is an interrupt callback (and it's bound to the Heartbeat object created on line 19)

mattyt
Posts: 41
Joined: Mon Jan 23, 2017 6:39 am

Re: A library for reading rotary encoders (ESP-8266 and Pyboard/stmhal)

Post by mattyt » Wed May 24, 2017 1:22 pm

I just wanted to give a shoutout to SpotlightKid for submitting his Rotary Encoder library; I just cloned it, deployed it to my ESP8266 and it worked great! Admittedly not perfect debouncing but pretty decent and more than good enough for my use.

In the space of a night or so I now have a working(ish) LED strip light where the brightness is controlled by a rotary encoder - pushing it turns the strip on/off (with a fade). Less than 50 lines of hacky python code. Much appreciated @SpotlightKid!

evidlo
Posts: 5
Joined: Tue Jul 04, 2017 5:47 pm

Re: A library for reading rotary encoders (ESP-8266 and Pyboard/stmhal)

Post by evidlo » Fri Jul 07, 2017 3:51 am

[quote="pythoncoder"]Given the observed rates of contact bounce events and the simplicity of the ISR this strikes me as improbable and I didn't observe it in testing.[/quote]

I believe this is happening to me. I looked at one of the encoder channels on my scope and saw that my pulses are about 600μs wide.

[img]http://i.imgur.com/vB9ofHb.png[/img]

I measured the callback routine time in both pythoncoder and SpotlightKid's encoder classes and got around 800μs for both.

[code]
import time
from machine import Pin
from encoder import Encoder
enc = Encoder(Pin(4, Pin.IN), Pin(5, Pin.IN), False, 1)
a = time.ticks_us()
enc.x_callback(_)
b = time.ticks_us()
print(b - a)
[/code]

I was able to get around the issue by stepping up my clock rate to 160MHz, but I think encoder pulse widths that are too short may not be so uncommon.

User avatar
pythoncoder
Posts: 2157
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: A library for reading rotary encoders (ESP-8266 and Pyboard/stmhal)

Post by pythoncoder » Fri Jul 07, 2017 4:58 am

See my response here viewtopic.php?f=6&t=1735&start=10.

tl;dr The problem is almost certainly the dire interrupt latency on the ESP8266.
Peter Hinch

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

Re: A library for reading rotary encoders (ESP-8266 and Pyboard/stmhal)

Post by OutoftheBOTS_ » Fri Nov 24, 2017 8:50 pm

I am using a quadrature motor encoder, it is a magnetic encoder with 11 pairs of poles poles attached to a motor and the motor has a 31:1 gear box so I get a very resolution per rotation. I have tried both writing my own routines and using the great 1 written by spotlightkid. I have found them to work perfectly for freq with less than about 900 signals per second but at any higher speeds it starts to miss ticks.

Have others found this problem??

I am maybe looking at adding a LS7366 like suggested by dhylands but it would be great if I can getaway without this extra expense, hassle and size on my PCB

User avatar
pythoncoder
Posts: 2157
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: A library for reading rotary encoders (ESP-8266 and Pyboard/stmhal)

Post by pythoncoder » Sat Nov 25, 2017 9:16 am

I'm not surprised if you're using an ESP8266. The chip suffers from latency issues because there is an underlying RTOS handling the WiFi. It's not great at responding quickly to real time events.
Peter Hinch

fzixsc
Posts: 1
Joined: Sun Nov 26, 2017 11:12 am

Re: A library for reading rotary encoders (ESP-8266 and Pyboard/stmhal)

Post by fzixsc » Sun Nov 26, 2017 11:36 am

[quote="pythoncoder"]See my response here [url]viewtopic.php?f=6&t=1735&start=10[/url].

tl;dr The problem is almost certainly the dire interrupt latency on the ESP8266.[/quote]Hi. this is beginner of micropython

This has nothing to do with discussing but...

May I ask you some questions?
I'd like to ask about micropython-async.

Tapatalk を使用して私の HUAWEI P7-L10 から送信


SpotlightKid
Posts: 297
Joined: Wed Apr 08, 2015 5:19 am

Re: A library for reading rotary encoders (ESP-8266 and Pyboard/stmhal)

Post by SpotlightKid » Sun Nov 26, 2017 3:47 pm

fzixsc wrote:
Sun Nov 26, 2017 11:36 am
This has nothing to do with discussing but...
Then why do you post here? Use the personal message function if you want to ask somebody something non-publicly.

If you want to address all forum users and have questions on a topic unrelated to this thread, please open another thread in an appropriate section of the forum.

User avatar
pythoncoder
Posts: 2157
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: A library for reading rotary encoders (ESP-8266 and Pyboard/stmhal)

Post by pythoncoder » Sun Nov 26, 2017 6:13 pm

@fzixsc I would prefer a public discussion. I think it's in your interests too, as others can contribute their own know-how. Also others can gain from any shared wisdom we might generate ;)

If there is some overwhelming reason why this is a bad idea, then send me a PM explaining.
Peter Hinch

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

Re: A library for reading rotary encoders (ESP-8266 and Pyboard/stmhal)

Post by OutoftheBOTS_ » Mon Nov 27, 2017 8:21 pm

This leads to other questions about the RTOS and WiFi.

Obviously I have chosen the ESP chipsets family because of its WiFi ability. Is there a way to adjust priority level of the wifi and how much resources it consumes. Does running its own access point consume more resources than being connected to my router?

Does the ESP32 run the RTOS on the second core to split off this process?

Post Reply