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): 49 комментариев

  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

        Нравится

      3. hi,
        is it possible to use an A1302 hall sensor, instead of the potentiometer, without editing your firmware?
        I want to use the hall sensor for the pedal control.

        thanks in advance 🙂

        Нравится

      4. Yes, I think it should works. Try to power it by +3.3V at first, if it will not work or axis will not show full range, then try to power from +5V.
        In general, any analog sensor can be used, MCU doesn’t bother (or even know) the type of device signal is coming from

        Нравится 1 человек

    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.

      Нравится

    1. Hi, I didn’t try this switch yet, but for what I see from datasheet it doesn’t required any special support from the fw, because its basically some combination of rotary encoders and buttons. Anyway I’m going to buy this switch and play with it, so I’ll say more specifically about it

      Нравится

  3. Hello

    Congratulations for your project, it’s fantastic

    I have a little problem with the encoders. I program them well, but for some reason that I do not know, they are very late.
    There is some solution for this ….
    regards

    Нравится

  4. Hi, That’s a really good project. I’ve got a really quick question about OSH software I’m struggling to understand how to run it. Could you give more info about it? Which file do I have t run and how to. Thanks a lot

    Нравится

    1. Tried in all USB ports, and another pc and nothing. The only thing that works well are the push buttons

      A while back with version 0.10 went well, but it seems that something is wrong with the STM32 that I currently have.

      Can you recommend a store to buy?

      regards

      Нравится

      1. I almost always bought in the store I already linked in the article. BTW, can you try to reflash old 0.10 version to the board and see how encoders will behave? Maybe something wrong with encoders but not MCU. Also if you have some kind of EMI generator (like OSW) its always good idea to ground everything and hang ferrite core filters at USB cables.

        Нравится

      1. Can’t say anything about AC, better to ask on AC forums how to calibrate/use 3rd party controllers. From windows point of view its just some type of joystick, so if AC is able to support 3rd party joysticks (I think it should) then it should be standard process

        Нравится

  5. Hi

    Can you add a delay function to rotary switches? So that it ignores the change for 1 second before activating, this way if you want to move more than one places without activating buttons in between, this can be done.

    Regards,
    Jonathan.

    Нравится

  6. hi,

    I flashed the 0.14 .hex version on my stm32 board, using stlink. then I connected the stm32 board with usb cable but OSHStudio didn’t see the board.
    what is the problem?

    thanks,
    alex

    Нравится

    1. Hi!
      Short answer is such load cell amplifiers based on hx711 (or similar producing digital output) are not supported yet. I can consider it for adding such support in future releases. You can however make simple amplifier based on ina125 (look here for example https://chippedwood.wordpress.com/2015/07/20/noisy-diy-load-cell-when-used-with-dd-wheel/), so you can connect analog output of this amplifier as standard analog input for the board

      Нравится

  7. Thanks for your answer and link . After further researchs, I’m going to try to scale the load cell/hx711 on the input of an analog pin of an arduino and then use the output of the arduino to control the potentiometer of my brake pedal. I’m a noob in arduino code but I’m gonna try.

    Нравится

    1. I’m not sure how you are going to control the pot of brake pedal. Usually when doing load cell mods people replaced that pot by load cell + amp. So you should make some construction when your brake pedal will push against load cell. Then (one of variants) you can connect output of amp and pots from 2 other pedals to the stm32 board as analog inputs. In such way you completely replaced you original pedal controller by the board and your pedals will be standalone device in PC. However you can loose console support this way.
      Another variant just replace brake pedal’s pot by load cell + amp, but keep your original controller. In this way you should just connect output of amp instead of brake pot to your controller. But there is no guarantee this will work because it depends how original controller was developed.

      Нравится

  8. Hi!
    I guess it was not very clear 😉 but I start with electronic, code and it’s not so easy.
    First, it’s obvious I need to mod the brake pedal in order to place the loadcell nicely to bend the loadcell correctly when I push on it.
    Example : (https://chippedwood.files.wordpress.com/2015/07/20150604_184036.jpg).

    Secondly, I would like to use the loadcell and HX711 to send signal to my arduino. After a good calibration of the loadcell in the arduino , the idea is to send an Arduino output between 0V and 5V to the original potentiometer wiring of the brake pedal. So, I don’t have extra USB device but my pedal send a signal which come from the loadcell and not the pot anymore.

    Does it seem right to think like that?

    Thanks!

    Gégé

    Нравится

    1. Hi!
      Yes, it’s possible. You can define custom part of device name in the Tuning tab. For example you can define «rim1» for one board and «rim2» for another and they will be shown as OSH PB Controller (rim1) and OSH PB Controller (rim2) in the devices and printers. Every board has its own unique serial number, so windows can distinguish them by s/n

      Нравится 1 человек

  9. Hi, I’ve managed to make it works and I was wondering if is possible to also use it to control 8 rgb less for the rpm though Simhub or if I need an external arduino to do that and if so is there anyway I can connect the arduino to the stm32 and use just one cable?
    Thanks

    Нравится

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

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

Логотип WordPress.com

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

Google+ photo

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

Фотография Twitter

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

Фотография Facebook

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

w

Connecting to %s