Logitech G25 / G27 Pedal and Shifter Adapter on STM32
Formulation of the problem
In connection with the need for self-improvement and the need to take something up between the routine at work, I decided to make some further progress in studying electronics. From what I find interesting as a hobby, this article mentions about:
Simraising
Microcontroller Programming
PCB layout and production
Electronics assembly
Manufacture of electronics enclosures on a 3D printer
Where to put the collected fees
All pictures and the story that came out of it - under the cut. A lot of reasoning and very little code.
In more detail, what and why was I going to do
So, I spent some part of my life on simraising. This is when a person is sitting at a computer and imagines himself to be cool. Simraising is different from playing “gonochki” such as nidoforspid, grid and others in that in the simulator much less attention is paid to bonuses and visual entertainment in favor of a more accurate simulation of the car's behavior, road conditions and the driving process itself. Accordingly, the equipment for the "game" in simulators is also required quite serious. Often in the construction of a racing cockpit money tumbles almost like a real car. If for arcade racing games a gamepad or unpretentious steering wheel is often enough for several thousand rubles, for simulators something like Logitech G27 is the minimum requirement, and serious riders prefer Fanatec products or direct drive designs based on industrial servomotors.
But we will not climb so deep into the wilds and consider a situation where a person has a Logitech G25 or G27 and its capabilities are a bit lacking. For example, the G25 has only two buttons on the steering wheel, and if there is a desire to hang a “formula” steering wheel there - there is simply no other button to take additional buttons. Another jamb of Logitekov steering wheels is a loud knock that helical gears emit when changing the direction of rotation of the motors, providing feedback effects. To heap also the backlashes, reducing the information content of the steering wheel. In addition to the deep modding of the steering wheel (for example, modifications under the belt drive), there is also a more radical approach to the issue - changing the steering wheel to the same Fanatec, top models of Thrustmaster or OpenSimWheel with direct drive. Often, there are unused Logitech pedals, which are not so bad with progressive springs or a mod mounted load cell. You can also try using the Logitech shifter (which I don’t like in terms of ergonomics and tactile sensations, but there are those whom it suits). ')
To solve these problems, there are adapters from Leo Bodnar or Derek Speare, which these problems solve less. I will not give links, you will find yourself if interested. They have several disadvantages. In addition to the high price, the DSD adapter also got a joint with periodic delays in updating the status of the axes:
This is just an enchanting fale, when the pilot has already thrown gas and is pressing the brake, and the car continues to accelerate confidently. For Toyota, this ended in disaster with human casualties and lawsuits. In simracing, the consequences are far less fatal, but somehow I don’t really want to finish the race in the fence because of the glucan controller. So, it is decided, we will build our controller, with all the whistles and fakes, but quite expensive.
The beginning of a big way
What are we going to do? Usually joysticks are made from teensy. Conveniently, beautifully, quickly, threw a sketch in the style of arduino - ready, let's go! But not cheap. It is not clear why, but Teensy is worth quite a lot. In addition, I have long wanted to solder my board so that all the connectors on it were already installed, no wires, no mounted installation. Therefore, Teensy floppy, take a cheap STM32 and go:
Scary prototype on STM32F103
As a development environment - CooCox CoIDE v2 beta, we draw a USB HID skeleton using STM32CubeMX, add a poll of potentiometers in the pedals, a poll of potentiometers in the shifter and a poll of buttons through the shift registers, let's go. In the process of working on the firmware, completely hellish glitches were found, after several days of studying the situation, a reason was found - a bunch of CoIDE and GNU ARM GCC gave out some kind of hellish thrash that worked incomprehensibly as it could when adding a completely innocent line to the code to generate something unimaginable. I was not interested in understanding why it works this way, so I had to crawl to the free version of Atollic TrueStudio. Yes, it is even more inhibitory (Eclipse on the not very powerful tablet with Atom, to put it mildly, it works slowly), but the firmware is more or less problem-free, if there are any glitches - only mine.
After everything more or less earned, the next question arose how to pack all this into a beautiful case. I did not want to leave the debug board, I wanted to make exactly the adapter board in the form of a finished end device. Well, maybe then sell a few things ... If you're lucky ... There was a task to make the board cheaper. The minimum controller of the STM32 family that has hardware USB and enough legs to enable SPI is STM32F042. The cheapest and easiest soldering option is in the TSSOP20 package. Select the version where more available memory. Total controller turned out STM32F042F6P6. In addition, he has such a mega useful feature as uploading firmware via USB (DFU). There is no such thing in the STM32F103, although kolkhoz ways to update the firmware without ST-LINK exist ... Quickly I added a board to DipTrace:
Looking ahead, I will say that there were no serious jambs with this board, well, except that external quartz is completely redundant, the HSI48 in STM32F042 works fine, one could do without them ... It’s good that the linear regulator has set such a healthy and powerful debugger the STM32F103 board sags the voltage when pressing the buttons on the shifter, and with such a bandura everything is stable and it is easy to solder it. But with the standard size of conders and resistors, I got excited, 0603 is harsh for a beginner, I did not immediately learn how to do it beautifully. The boards ordered at Seeed Studio are cheap and good.
After soldering it turned out something like this:
Porting the firmware from STM32F103 to STM32F042 turned out to be easy, except for a few interesting points, for example, the STM32F042 has a slower ADC, it is impossible to set ranks when converting several channels sequentially, converting a 12-bit value at the maximum frequency is about 13 cycles. Again, nafig no need for external quartz ...
Several pictures of the workflow
Result
Tests of the prototype in Assetto Corsa (the fastest was to run :-))
After that, the question arose of what to block the case. There was a 3D printer at hand, after several attempts something more or less acceptable came out:
Prototype
And relatively final result:
At the moment, some improvements are planned in the firmware, nothing is supposed to be done for the hardware. I will not post code examples here, they are bigger than Arduino sketches. Everything lies on the githaba: code, diagrams, gerberas, body model, some specs and much more. Project page:
To the question "Where to put the collected boards" - well, I'll leave one for myself, for experiments. For example, for a long time I wanted to try to combine several devices in one piece of iron (composite device), you can make soft buttons depending on the telemetry, for example ...
PS: by the way, I also copied the shifter circuitry to organize more buttons on the G27 / G25 steering wheel without additional controllers, such a small board turned out:
Now you can make a formula steering wheel with 14 buttons on the G25 and c 18 buttons on the G27 ...