How to create a Controller Map on Raspberry Pi
Updated 20/03/2025
I’ve since discovered since I got a Raspi 5 that the install-tools are no longer built and included when you install SDL2 which means controllermap used in this article isn’t easily available.
However the source code is available (and all the tests) and only needs a bit of tweaking to build it on a Raspberry Pi.
I will add a tutorial to build it and will link to it once done.
— Rest of article —
I’ve been working on my 2nd eBook and adding a GamePad is a thing I need to explain. You can see them in earlier blog posts:
But I want readers of the book to be able to generate their own controller maps. I cannot assume that everyone has access to Windows.
What I didn’t know back then is that SDL comes with a game controller map generator application called (subtle this!) controllermap that you can run on your Pi or Linux computer.
I had to use the File Manager Find file facility to locate it. It’s in the installed-tests folder for SDL2 or more precisely /usr/lib/aarch64-linux-gnu/installed-tests/SDL2 on my Raspberry Pi running 64-bit Raspberry Pi OS.
On my VM Ubuntu I found it in /usr/lib/x86-64-linux-gnu/installed-tests/SDL2
I did a bit of experimenting with a clean Raspberry Pi OS setup and then I installed libsdl2-dev and saw the installed-tests/SDL2 folder installed, so that’s what you need. So install the dev files as per New tutorial on installing SDL on Linux.
Plug in a gamepad and on your Pi, cd into that folder (the Pi one not the Ubuntu one!) and in a terminal run ./controllermap

It will open with your B button highlighted. Press your B button. In the picture above it’s the circle on the right hand side that is the lowest of the four or the yellow button in this picture of my controller.
It will then go through every possible button. Just press the corresponding button or space key if you haven’t got that. Compared to the main picture, mine lacks the two bottom joysticks, the buttons between the Stop and Start buttons and the two trigger buttons at the top. For each of those just press the space bar. Eventually it will loop back to the B button. Just press it and it will finish and output the gamepad control map.
It outputs two copies of this. You can send one to a text file in your home folder by doing
./controllermap >~/gamepad.txt
but you will have to press all the buttons etc. again. This is what my Pi gave.
030000001008000001e5000010010000,usb gamepad,platform:Linux,a:b2,b:b1,x:b3,y:b0,back:b8,start:b9,leftshoulder:b4,rightshoulder:b5,leftx:a0,lefty:a1,
And that is what you use in SDL2 code.


This assumes that you have the version 2004 of Windows 10. Run the command Winver (open a command line then type winver) to see what version you have.
Just click it and your Ubuntu (or whatever) Linux will open at a terminal prompt like this.
About twelve years ago I came across WOAS (= Wiki on a Stick). It was a single HTML file notebook with built in JavaScript and you opened it in a browser. It showed a simple interface and you could switch it into edit mode and start adding in text in markdown format. It was very easy to create links to pages in the document and add new pages.
As the picture shows, no one has ever accused me of being artistic! Hey I can’t be good at everything (sometimes it feels like anything but it passes!) and I’ve long ago accepted that I never will be an artist.
Sometimes you just need to view or maybe a binary file and here I’ve done that on the compiled file for asteroids.
At some time or other you are going to need a binary editor, to let you look in files and see what they contain.
Normally I wouldn’t mention it, as there’s nothing really outstanding about the update (accessibility improvements, Timeline view, Better quick open for files etc.) You can read all about it
Clang is very easy to install. Open a terminal and issue this command: