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 fritzing.org code for that wiring graphic here (so it can be modified if needed).

2 comments

    • Victor Gabriel Gonzalez Martinez on August 22, 2021 at 12:09 pm
    • Reply

    Great project. I was searching for this. I’m new with arduino and I want to use this as a VTS Plugin controller. For that propuse I need to use MIDI. I saw the other project that you made with buttons instead of the encoders but I have no idea on how change the code to use midi with this configuration. Any help will be apreciated.

    Thanks in advance!

      • earl on August 23, 2021 at 7:49 am
        Author
      • Reply

      Check out the other posts where I use the STM32F103C8T6 with midi software.

      https://microcontrollerelectronics.com/an-stm32f103c8t6-based-midi-controller-for-midi2lr-updated/

Leave a Reply

Your email address will not be published.