[Tutorial] How to compile and upload code to the keypad

arduino
keypad
tinkering
#1

I decided to change the buttons layout of my cpi, from XY AB to AB XY because I felt more confortable that way and the thumb is in a better resting position, also I am really used to a Gameboy Color position
image

And found out that there is a bit of lack of information at plain sight (There is information, but you need to check the schematics) so I decided to make this guide to save you time for such a straightforward task that took me longer than I expected.

First things first.

If we don´t have it already, we need arduino ide. There is a portable version but I recommend you to install it.

As many arduino clones, they don´t come with the same usb chip as the genuine arduino uno, they come with its chinese counterpart CH340 we need to install the driver in order to use USB to serial and get to see the COM port on Arduino IDE.

We can download it from the manufacturer website: http://www.wch.cn/download/CH341SER_EXE.html

Direct links:

Almost there

Now we need to download the UsbKeyboard library from github and the code of the keypad from here

After we got the UsbKeyboard folder, we need to zip it and include it to our Arduino IDE from Sketch -> Include library -> Add .zip library

image

Note: You can also install the library by pasting the uncompressed folder in Documents/Arduino/libraries but for the sake of simplicity I explained the other way around.
image

Now we are ready for the fun part

Connect the keypad via usb to your computer and check on Arduino IDE if it recognises the COM port.

image

Now that we are here lets configure our board.

Board: Arduino Nano
Processor: ATmega168
Port: Chose the arduino comp port, it should be set automatically when recognised.

Programmer: leave it default, should be AVRISP mkII

Now we are set

You can open now the code on the IDE and change what we want. We can hit Upload and watch the flashy lights on our board while we wait.

image

A succesful upload should look like this:

Happy hacking :man_mechanic:

7 Likes
How to change LightKey binding?
Can keymaps be changed?
Keypad not working
Change A/B and X/Y button mappings globally
Interface Speed
#2

Ok, how would the changed code look like for the Nintendo Layout (A and X button on the right)?

#3

Changing these lines:

#define KEYPAD_Y      KEY_K
#define KEYPAD_X      KEY_J
#define KEYPAD_A      KEY_U
#define KEYPAD_B      KEY_I

Take a look at this image

The original position of buttons is

X= KEY_U Y= KEY_I A = KEY_J B =KEY_K

The code above is for how I have it, i inverted the buttons, my AB are on top and XY on bottom.

So I guess what you want to archieve is like this:

The code for that would be:

    #define KEYPAD_Y      KEY_Y
    #define KEYPAD_X      KEY_I
    #define KEYPAD_A      KEY_K
    #define KEYPAD_B      KEY_J
2 Likes
#4

You can easily make this change in Settings->Buttons Layout and set it to SNES Compatible. Don’t forget to select “UpdateRetroArch” to make the changes to RetroArch’s configuration file.

1 Like
#5

My understanding is that what Petrais/Pixelpunker want to achieve is that changing the key layout on whole system level, not only in Retroarch.

#6

Yes I changed the layout on a hardware level

#7

Noob here. I am unclear on how to do this:

I have 2 questions:
Where is the code that I need to start with?
How do I know what code my keypad is already running?

Thanks in advance.

EDIT:

I just found it, but to install the library, I had to pull the “UsbKeyboard” folder out of the zip and place it in the Documents/arduino/libraries folder. I then loaded the .ino file from another copy of the contents of the zip file.

#8

Has anyone tried doing this do change the update loop from 1 second to a lower number? Did it work?

#9

Yes, another user in another topic changed it to and his gameshell worked like before.