Rotary encoder with blue pill

Post here all questions related to LibMaple core if you can't find a relevant section!
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Rotary encoder with blue pill

Post by ag123 »

i'd need to play with rotary encoders, but that if it is one of those 'cheap' (and not so cheap) encoders
https://www.aliexpress.com/wholesale?ca ... hText=EC11
i'd try to write a sketch that does digitalRead() on the output pins say at 1-10 ms intevals, kind of a rather crude 'logic analyzer'
and try to turn the knobs observing the waveforms
i'd suspect some of them may not be very well made and possibly give incorrect encoding sequences
the 'originals' would likely give better results for their somewhat premium value i'd guess
https://www.bourns.com/products/encoder ... g-encoders
https://www.bourns.com/docs/product-dat ... pec11r.pdf
ilium007
Posts: 1
Joined: Mon Feb 15, 2021 6:35 am

Re: Rotary encoder with blue pill

Post by ilium007 »

I’ve used this state machine based encoder library for years with all sorts of brands / quality of encoders. I don’t use any other library.

https://github.com/mathertel/RotaryEncoder
sigi
Posts: 57
Joined: Mon Sep 28, 2020 3:17 pm

Re: Rotary encoder with blue pill

Post by sigi »

try mine (I do not like interrupts by the way)
Attachments
RotaryEncoder.rar
(28 KiB) Downloaded 406 times
taximan
Posts: 1
Joined: Mon Sep 06, 2021 5:46 pm

Re: Rotary encoder with blue pill

Post by taximan »

The first encoder Sketch that works for me at F103; but don't forget PullUps! (internal or external)
Levitate
Posts: 1
Joined: Thu May 26, 2022 6:54 pm

Re: Rotary encoder with blue pill

Post by Levitate »

I have tried to add pins to Paul's encoder library but when I properly setup the pins it gives me errors that should not occur. And I was using an Nucleo-H743ZI2. I thought I would reply even though this post is a few months old since last post.
deanalee
Posts: 2
Joined: Thu Jun 02, 2022 5:23 pm

Re: Rotary encoder with blue pill

Post by deanalee »

I was not familiar with the systick interrupts and it took me a minute to realize that STM core was different from Roger Clarks.
Arduino STM32" but adding "systick_attach_callback &encoder1_read" in setup made it run perfectly on my blue pill running Roger Clarks "Arduino STM32" core.
sigi
Posts: 57
Joined: Mon Sep 28, 2020 3:17 pm

Re: Rotary encoder with blue pill

Post by sigi »

HI
Im playing with the included example about hardware timer as encoder .. location is:
"Sketchbook\Hardware\Arduino_STM32-master\STM32F1\libraries\A_STM32_Examples\examples\Sensors\HardTimerAsEncoder"

I use this small code mod to show the issue:

Code: Select all

#include "HardwareTimer.h"
HardwareTimer timer(4); //(PB6 and PB7)

void setup() {
pinMode(D2, INPUT_PULLUP); 
pinMode(D3, INPUT_PULLUP);  

timer.setMode(1, TIMER_ENCODER); 
timer.pause();
timer.setPrescaleFactor(1); 
timer.setOverflow(10); 
timer.setCount(0);       
timer.setEdgeCounting(TIMER_SMCR_SMS_ENCODER1);
timer.resume();     
}

void loop() {
Serial.println(timer.getCount()); 
}
it seems to be great BUT when it reaches the edges (o or the overflow) the first time it starts to count different... in this case counts 2x the units... did somebody knows why???
All u need to do first is go forward so u see the "normal" counting process... then u go bellow 0 and forward again and the 2x issue appears...
I try everything BUT it always happen, I think it is a bug on the core...
ANother issue is that at the begining there is no upper limit... u can go way up than the Overflow limit... 10 in this case...
i998
Posts: 9
Joined: Wed Feb 23, 2022 2:14 am

Re: Rotary encoder with blue pill

Post by i998 »

FYI - I made this one https://github.com/i998/ClickEncoder_STM32 for my MapleMini project, worked ok for me.
Hope it helps.

Regards, i998
sigi
Posts: 57
Joined: Mon Sep 28, 2020 3:17 pm

Re: Rotary encoder with blue pill

Post by sigi »

Thanks!!!
just works for me like a charm initially using "stepsPerNotch = 4"
will look for a way to setup it using:

- a float increment
- low and high limits

thanks!

PD: Maybe it will be a great addition to setup what to do with the button on Press, PRessAfter, Release, etc etc In the same way this library does with multiple buttons...
https://www.arduinolibraries.info/libra ... lti-button
In fact I just chain the encoder button with the other button on my projects.... it works very well.

I know u already write the code for that ... but it is a litle difficult to use it modding the cpp and .h file...
Thanks again.
i998
Posts: 9
Joined: Wed Feb 23, 2022 2:14 am

Re: Rotary encoder with blue pill

Post by i998 »

Glad it worked... Not sure I understand the requests... Button functionality is separate from the encoder one, so you can use the encoder without a button and https://www.arduinolibraries.info/libra ... lti-button completely separately.

Or do you want the encoder library to handle more button scenarios?

Also
- a float increment
- low and high limits

can be configured in your main code/loop outside of the encoder library, I could help with that if you provide a bit more description of how that should work...

Regards,
i998
Post Reply

Return to “General discussion”