Everybody needs some recreational activities. From time to time I play Trackmania with friends, a quite competitive racing game. You compete on user created tracks for the best times, which are logged and shown on a worldwide leaderboard for each map.
The goal is simple, but the game itself is not. What makes it special for me, is the user-generated part, which is a great display of creativity in many cases. All tracks are made by players themselves and the game is made such that it even allows importing custom models from 3D modelling software like blender, with some stunning results.
Why analog?
Since the original Trackmania release in 2003, the game has been played with different input devices. Keyboard and Gamepads like the XBox-controller are the most popular, but there also are people playing in high ranks on steering wheels, joysticks and even with the mouse.
Smooth steering
Among many others, there is a game mechanic called "smooth-steering". Nobody is really sure whether it was intended by the developers or a bug that got made into a feature by the players. This is a common theme of the game, people get pretty creative to squeeze out the last few milliseconds by finding cuts and figuring out obscure behaviors of the physics engine. It is all part of the fun.
Smooth-steering refers to holding a specific steering percentage without starting to drift which would lose speed. The exact steering value is dependent on various factors such as the speed you are driving at and the surface you are driving on. It's not easy to get good at it, in practice it means holding your controller's stick at a specific angle during turns consistently or tapping the direction key at a specific rhythm if you play on keyboard, which requires a good knowledge of the game.
This mechanic has gotten even more powerful during the last big update, which introduced a second car that gains even more speed from it. The update was received with mixed feelings, as keyboard players where put at a disadvantage.
Input devices
Another change in how the game is played came from the appearance of analog keyboards like the wooting. These keyboards don't have regular digital switches, but analog ones, which allow pressing and registering a key halfway. For the game this keyboard appears as an XBox-controller with joysticks capable of intermediate, analog input values.
Even more powerful, you can set a custom response curve in the companion software of the keyboard. Say you want to play a track where 60% left steering is the perfect angle to gain optimal speed, you could set the curve to top out at 60% easily or make it at least much easier to hold that specific value. There are in-game special keys that can be bound to do something similar (called "action keys"), but they are not quite as powerful.
Dedicated input device
At this point I started thinking about what would actually be best input device, if I were to build one. Steering wheels are very precise, but slow when doing sharp turns. Also, they are very bulky, and I don't want one screwed to my table at all times. A wooting is a decent choice, but I really don't need all those keys and already have a custom keyboard which I want to keep using. They are pretty costly and not something anyone would be able to buy. I feel like the settings are very generic and limiting, if you only want to use it for Trackmania.
Analog Switch
Luckily, you can get replacement keys for wooting keyboard and other compatible ones. The switches are called Lekker switches and surprisingly simple devices. The whole switch is not much more than a magnet suspended on a spring that gets pushed towards a hall sensor.
The PCB below it has a hall sensor measuring the magnetic field from it, which increases when the switch is pressed. The switch has a travel of 4 mm and the hall sensor can calculate the exact position from it. Here is a teardown of it showing the inner parts.
Hall sensor
A bit of investigation lead me to the SS49E Linear Hall Effect Sensor. It is not the one used on the wooting keyboards, but looked like a perfect match: It has a linear, analog output, is cheap and readily available. Furthermore, it works with 5V, which makes it easy to be used from common microcontrollers.
Microcontroller
The last past of the puzzle is a microcontroller. I went with the Waveshare RP2040-Zero because it has some features that I'm looking for apart from being a popular choice with many code examples:
- It can act as HID (Human input device)
- It is small and cheap
- It has a USB-C port
- It has 4 Analog input pins
The device is well-supported by the MicroPython firmware, which is also a plus since I have been meaning to try it out, and it should make reconfiguring the firmware a lot easier for users that might not be experienced with C and flashing chips.
Next steps
I have ordered some sensors and a microcontroller to do some proof of concept testing before starting to design a PCB. This will be the content of the next post, which is already in the making.
Stay tuned for the second part!