As a big fan of both Euro Truck Simulator 2 and American Truck simulator I wanted to build a physical dashboard that not only controlled the game but received real-time telemetry data back from the game.
The final build uses both a Raspberry Pi Zero to read the server data from the game and an Adafruit Clue to act as the Human Input Device. I chose the Clue as I wanted to utilise the screen to see when buttons were pressed and to help with debugging.
The case was designed in Fusion 360 and 3d printed before being covered in felt for that authentic dashboard feel. I used a retro font making app to produce the fake labels.
The project build design could easily be adapted and changed for any configuration of buttons.
The project started by attaching a Pimoroni Four letter pHAT to the Raspberry via 5V, Ground, GPIO2 and GPIO3 using jumper cables. This would then later get mounted on the front panel.
Every dashboard needs a significant number of LEDs so I attached various coloured LEDs to GPIO 21,20,16,19,26, 18,15,14,6,13,5,11,9,10,22,27,17 and 4. The ground pins from each LED were soldered to a common ground on the Raspberry Pi.
Push buttons were mounted to the front facia. Some of these were going to be connected to the Raspberry Pi and others to the Adafruit clue. One pin on each push button was connected to the following GPIO pins 25, 24, 23, 12, 17
To connect the buttons to the Adafruit Clue I used a micro:bit pin:bit connector which broke out these digital pins 1,2,5,8,11,13,14,15,16,19,20 3V and Ground. To these were connected the various push buttons which would act as the HiD to control the game. Whilst other options are available to use for the HiD I decided to use the Clue as I could have information displayed on the screen. Mounting the Clue through the front of the case means that it can be removed if wanted and the USB cable can be attached and detached easily.
It was a very simple task to adapt the example CircuitPython code to include the pins and output buttons I wanted to use. The final code can be found here.
Receiving data from the game was relatively easy on the Raspberry Pi and started with downloading the files from https://github.com/Funbit/ets2-telemetry-server onto the PC running the game. The setup and installation guide was very well documented and after following the instructions I was running the server app and sending game data.
Turning to the Raspberry Pi side of the program I used wget http://localhost:25555/api/ets2/telemetry to receive the latest telemetry data. It then became a simple job to open the data in Python and to look for values of different properties and use many nested if statements to control the action. There is a very useful reference page here.
I have included a copy of my final project code here
You will notice from the video that there is a 0.4 second delay in the loop. This happens each time the data is fetched. I did consider a different approach using either threads or downloading the data in a second script and I will probably update to this later.