Multiple Rotary Encoders on an STM32F103C8T6

Rotary encoders are useful for many things.  Here is what they look like (with and without the button):

Rotary EncoderRotary Encoder with Button

They have 5 connections (Power, Ground, Data, Clock and Switch). The button can be turned (continuously in any direction) and it can also be pushed down .





The switch connection monitors the button push whereas the data and clock connections are used to monitor the direction and turn of the button.  There are many tutorials on how these ‘encoders’ work, for more information check this link.

Multiple encoders are needed for the MIDI2LR  project that was posted here. In order to test multiple encoders , this sketch called ‘Multiple Rotary Encoders on an STM32F103C8T6’ was created:

The pins are set up in an array so that the code can quickly ‘scan’ through them and not miss any state changes.

Notice that the switch (button press) pins are set up as INPUT_PULLUP.  If they go ‘LOW’ then the button was pushed.

Here is what the wiring looks like:

STM32F103C8T6 Multiple Rotary Encoders

Get the code for that wiring graphic here (so it can be modified if needed).

Leave a Reply

Your email address will not be published.