Hello,
I am a beginner and French so sorry for the Google translation.
I realize a thermostat project and I need to be able to adjust the time manually with buttons or a rotary encoder but I can not find information on the web. can you help me please.
Clock with encoder
Re: Clock with encoder
Hi,
For a rotary encoder, you might find this library useful -- https://github.com/miketeachman/micropython-rotary
For a button, you need to connect the button to a pin on the ESP32 (with the other side of the button connected to ground). Then enable a pull-up on the pin, and you can read the value
You can enable a falling edge irq on the pin to have a function called when the pin is pressed. http://docs.micropython.org/en/latest/l ... e.Pin.html
You might want to read about "button debouncing" though.
For a rotary encoder, you might find this library useful -- https://github.com/miketeachman/micropython-rotary
For a button, you need to connect the button to a pin on the ESP32 (with the other side of the button connected to ground). Then enable a pull-up on the pin, and you can read the value
Code: Select all
import machine
p = machine.Pin(26, mode=machine.Pin.IN, pull=machine.Pin.PULL_UP)
...
if p.value() == 0:
# button is pressed
You might want to read about "button debouncing" though.
Re: Clock with encoder
Thanks
for the physical part and gpio it goes.
I have trouble converting the encoder signal into time.
I thought to make a script to change each value one after the other.
00:00 I change the first value I valid changes the second ... to get the current time.
for the physical part and gpio it goes.
I have trouble converting the encoder signal into time.
I thought to make a script to change each value one after the other.
00:00 I change the first value I valid changes the second ... to get the current time.
Re: Clock with encoder
Providing you are using the library proposed by jimmo you need to declare a rotaryIRQ() object.
This object handle all the interaction with the encoder you just have to read the value method.
You define the min and max value. When you turn the knob the value is increased/decreased.
You should look at the example. If you put 0 as min, 59 as max and replacing the print function to a call to your own display function you'll have the minutes adjustment. When you detect a push on the button you switch to hour adjustment by changing max to 23 instead of 59.
This object handle all the interaction with the encoder you just have to read the value method.
You define the min and max value. When you turn the knob the value is increased/decreased.
You should look at the example. If you put 0 as min, 59 as max and replacing the print function to a call to your own display function you'll have the minutes adjustment. When you detect a push on the button you switch to hour adjustment by changing max to 23 instead of 59.
Re: Clock with encoder
thank you very much I will try this
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Clock with encoder
There is also an encoder solution in this repo (encoder_portable.py).
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.