Pedal & Button Controller (eng)

During building my pedals, I decided to make my own pedal controller using cheep and affordable components. Already having some  experience with Arduino boards, I know their capabilities and decided to route a STM32 way this time (mostly to learn something new though).

Here is the comparision of Arduino Leonardo (which is a most likely candidate for our goal) and STM32F103C8T6 (which I used)

Arduino Leonardo STM32F103C8T6
Flash 32KB 64KB
SRAM 2.5KB 20KB
EEPROM 1KB Absent
Architecture 8-bit ATMEL AVR 32-bit ARM CORTEX-M3
Frequency 16MHz up to 72MHz
GPIO pins 20 26
PWM 7 12
Timers 1x 16-bit, 2x 8-bit 3x 16-bit, 1x pwm
Peripheral 10-bit ADC (6 channels)
1x I2C
1x SPI
1x UART
USB
2 x 12-bit, 1 μs A/D converters (7 channels)
7-channel DMA controller
3x USART
2x I2C
2x SPI
CAN
USB

As you can see, specs for stm32f103c8 are not so bad. And it’s cheaper than Leonardo!

One big drawback is that you need additional external programmer. But its not expensive also, total price for mini board + programmer is still comparable with Arduino clones.

 

 

I bought both items on aliexpress.com, search for «STM32F103C8T6 Minimum System Development Board» and «ST-Link v2 mini», for example this and this. Also there is another version of the board called BlackPill — link. It has less available pins, but has mounting holes.

Schematics for the dev board: STM32Mini

Or here in pdf

Pinout in pdf — The-Generic-STM32F103-Pinout-Diagram

Black_Pill_Schematic

So, after some time, I programmed simracing-oriented firmware for the device.

Device capabilities are:

  • 6x 12-bit (4096 steps) axises
  • rotary encoders support
  • rotary switches support
  • matrix buttons support
  • single buttons support
  • axises calibration
  • analog inputs as buttons
  • 1kHz exchange rate with PC, which means 1ms maximum latency for axises

It can be used for DIY buttons boxes, button rim plates, pedals, hand brakes, gear shifters, etc, etc — everywhere you need joystick/gamepad interface with PC.

Here is pinout you get after flashing the firmware first time:

             STM32F103C8T6
	   -------------------
	- |3VB		 +3.3V| -
  	- |C13		   GND| -
  COL1	- |C14		   +5V| - 
  COL2	- |C15		    B9| - ROW6
  ADC0 	- |A0		    B8| - ROW5
  ADC1 	- |A1		    B7| - ROW4
  ADC2	- |A2		    B6| - ROW3
  ADC3	- |A3		    B5| - ROW2
  ADC4	- |A4		    B4| - ROW1
  ADC5	- |A5		    B3| - COL4
  ADC6	- |A6		   A15| - ROT11
  COL5	- |A7		   A12| - 
  ROT1	- |B0		   A11| - 
  ROT2	- |B1		   A10| - ROT8
  ROTA	- |B10		    A9| - ROT7
  ROTB	- |B11		    A8| - ROT6
	- |R		   B15| - ROT5
	- |+3.3V	   B14| - ROT4
	- |GND		   B13| - ROT3
	- |GND		   B12| - COL3
	   -------------------

Also I programmed small PC-based app named OSHStudio, which allows you to choose a function for each pin. Pins’ functions can be selected in the «Pins Configuration» tab, also here you can choose your board type. Here is how the initial pinout looks in OSHStudio, when you click «Get Config from Device»:

pins_tab

 

Buttons

When buttons wired in matrix, columns have to be connected to Button Matrix COLUMNS pins, rows — to Button Matrix ROWS pins. Single separate buttons (not matrix), can be connect to «Single Button +3,3V» or «Single Button GND». If you connect button to «Single Button +3.3V» than connect the other side of button to +3.3V, if you connect button to «Single Button GND» than connect it to GND. Here is an example of matrix wiring:

buttonMatrixDia_bbYou can test your buttons in the «Buttons» tab of OSHStudio:

button_tab

In this tab you can also configure POV Hat switches. When activated first Hat Switch used first 4 buttons of matrix, 2nd Hat Switch — from 2nd 4 buttons and so on.

Also here you can tune threshold of analog inputs, after that buttons press will be registered (for Analog to Button pin types)

 

Rotary Encoders

The firmware supports full step, half step and quarter step encoders. Rotary encoders can be wired in «chained» or «single» configuration. Chained config means you wire side encoders’ pins (PINA & PINB) together and central pin become «control» pin. Central pin identified your encoder type — 1/1 (full step), 1/2 (half step) or 1/4 (quarter step). You can wire different type encoders in one chain.

Schematics:

RotariesChainedDia_bb

Also encoders can be connected in single configuration. In this case you should configure side pins according to the type of encoder and central pin have to be connected to +3.3V.

Schematics:

RotariesSingleDia_bb

If necessary you can remap encoders pins on the «Single Encoders Config» tab.

sgl_enc_tab

Encoders can also be tested in the «Buttons» tab.

 

Rotary Switches

Virtual button is «clicked» when shaft is changing position.

SwitchesDia_bb

Axises

Analog pins ADC0 — ADC6 used to connect potentiometers or other analog inputs. Also you can calibrate axises in OSHStudio, and calibration values in this case will be stored in MCU itself. After calibration an axis is «expanded» by the controller, so PC always sees axis as 4096 steps. There is also a possibility of AutoCalibration of axes.

As you can see, there is also «Combined axis» function. It means you can combine 2 analog inputs in one axis. The function is mainly intended for rims with 2 clutch paddles. There are 2 possible modes:

  • cooperative work — in this mode results from both analog inputs are summarized. You can choose weight of each input by slider.
  • each on his own — each analog input works independently but for one axis. For example you can short calibrate an one input (paddle) for fast gear changes and an other calibrate as normal axis — for starting.

axis_tab

Notes

I recommend set to «Not used» all unused pins 🙂

Source code in my github project.

Available firmware:

Version 0.14 — Autocalibration axes, Analog2Button pin type and combined axis added

Version 0.13 — Single Encoders Config tab added

Version 0.12 — Tuning tab added

Version 0.11 — Single encoders support added

Version 0.10 — base version

 

If you wonder how to flash firmware to the board you can check this post — How to flash firmware to STM32Fx

Реклама

Pedal & Button Controller (eng): 12 комментариев

  1. Hi,

    I’ve managed to flash the firmware (tried versions 0.1 to 0.4) but I’m having some trouble with OSHStudio. When I click «Get Config From Device» the application hangs and I have to force close it.

    Any ideas?

    David

    Нравится

    1. Hi
      The 1st rule is always use same versions of FW and app.
      The 2nd try to make full chip erase (through st-link utility) and reflash FW. It makes default FW config — maybe it’ll help
      And the 3rd it seems there is some bug with USB communications. Some people reports the app is closing as far as a board is connected. I’m investigating it currently. Anyway, it seems newer versions of windows have fewer problems, so try to use win10 if you can

      Нравится

      1. Hi,

        Thanks for the reply. I’ve tried all versions of the application, always with the correct firmware / OSHStudio combination. I always erase the whole chip before flashing.

        I am using Windows 10 64-bit. I have tried with Anti-Virus enabled and disabled.

        I might have a hardware problem so am going to try ordering a different unit. My final design will use a blackpill, rather than bluepill, so I might as well order one now.

        Does OSHStudio write any kind of log file that might show where the problem lies? I was going to try building the QT Creator project and debug from there but if there is already some logging present I won’t bother.

        I’ll report back.

        David

        Нравится

      2. There are not so much to log, from sniffing USB traffic I noticed that the app doesn’t catch every USB packet send to host. So in that «hang» moments the app just waiting USB packet while MCU sending them diligently.
        As a last resort I can make FW with your custom default config, so you’ll not need to configure it at all

        Нравится

    2. @opensimharware.

      That is very kind of you to offer. I’m going to try the new Black Pill units when they arrive. If that doesn’t work then I’m fairly confident I can hex edit the flash file to do what I need. I can see that the default button configurations are in:

      https://github.com/OpenSimHardware/PedalButtonController/blob/master/Src/periph_init.c and
      https://github.com/OpenSimHardware/PedalButtonController/blob/master/Inc/periph_init.h

      and I can see the corresponding entries at the end of the flashed image. I could probably get away with the default config but I’d like to switch off the unused pins, as you recommend. Changing the pintype to 0 for each unused pin should do that, yes?

      I’ve also started setting up the development environment, just in case hex editing doesn’t work or I need to make more changes. Is the project fairly easy to build with the default environment?

      Thanks for all your help by the way. I’ll make sure to put something into your donation jar!

      David

      Нравится

      1. >>Changing the pintype to 0 for each unused pin should do that, yes?
        Yes, exactly!

        >>Is the project fairly easy to build with the default environment?
        I’m using Atollic TrueStudio, so I believe if you install it then the project should build without any issues

        >>I’ll make sure to put something into your donation jar!
        Thanks you very much, very appreciated! 🙂

        Нравится

      2. I have the project building in TrueStudio now, it worked pretty much out of the box. A comparison of the source build and the released 0.4 hex shows they are different but I assume that is because you’ve made changes since the release.

        My blackpills should arrive tomorrow so I’m going to test them first. If that doesn’t work I’ll create my own build with the settings how I want. Out of interest, do you use 32-bit or 64-bit Windows? I’m wondering if that is a factor somehow.

        David

        Нравится

  2. Ok, I found something on german Amazon. Peaople are saying that often there is a missing pull-up resistor for the reset (or a wrong one). You fix it bu using a 1 to 1.5K resistor otherwise the board gets stuck in reset mode permanetly.
    Maybe this can help. You have to google «STM32 missing resistor» or wrong resistor.

    Нравится

    1. Thanks for that suggestion. I’ll take a look.
      I’m not sure my board is stuck in Reset though, as I can connect to the board in OSHStudio, I just can’t get or set the configuration from it. I’ve ordered a couple of Black Pill units from a different vendor, just to see if they behave differently.

      Нравится

Добавить комментарий

Заполните поля или щелкните по значку, чтобы оставить свой комментарий:

Логотип WordPress.com

Для комментария используется ваша учётная запись WordPress.com. Выход / Изменить )

Фотография Twitter

Для комментария используется ваша учётная запись Twitter. Выход / Изменить )

Фотография Facebook

Для комментария используется ваша учётная запись Facebook. Выход / Изменить )

Google+ photo

Для комментария используется ваша учётная запись Google+. Выход / Изменить )

Connecting to %s