Pages

Thursday, September 14, 2017

HOW-TO: N64 Controller Setup With Micro's N64 PCB Converter And Mayflash USB Adapter

I decided to upload this here from my RetroPie forums post on the same thing, just so it has another chance to be found on a random Google search.

I'm not sure how many people are actually running N64 games on their RPis or actually using the original controllers, or if anyone even knows about this PCB in general, but I wanted to post about it so if someone needs help down the road like I did, hopefully they will find this thread. This is the result of hours and hours of Google searching and trial and error. I know a lot of people use the Mayflash adapter but in the event that you have something else like Raphnet's adapter for example, these same principles will work.

NOTICE: I'm also running RetroPie 4.2

--------------------------------------------------------------------------------------------------------------------------

N64 Controller with Micro's PCB Converter and Mayflash USB Adapter

What is it?

It's a PCB made to replace GameCube style joystick replacements. If you've ever replaced the original joysticks and were tricked into buying a GC-style replacement, you know how bad they truly are for accuracy in games. The stepping is very imprecise, meaning no dash-dancing in SSB, no spin attacks in Zelda, and certainly no precision platforming in Mario...

This PCB that comes with the GC-style joystick really sucks...

micro's PCB Converter board not only fixes all of that by adding a more accurate potentiometer and faster micro-controller, but adds a few features that are really handy such as being able to calibrate the joystick on startup, and inverting the joystick controls with the flick of an onboard switch! Keep in mind, I am using V3.0 of that PCB located at the end of that thread, but the same principles apply.

Why am I posting this here? 

Well, I had originally been using the GC-style joystick replacement, and it worked after tweaking the AnalogPeak and DeadZone values in InputAutoCfg.ini but it was way to sensitive. You can imagine my surprise when I installed the new PCB and it had gotten worse. Yeah, worse. Even adjusting the values again couldn't make Mario run full speed.

OK, well how do I fix it?! 

It's easy! First thing you should do after installing the new PCB is to calibrate the controller and test its values with sanni's Controller Test ROM. If you have a real N64 then you will need a flashcart, otherwise you will need a MESS Emulator. The controller enters calibration mode the second it has any power. That means if you are using a real N64, calibration starts upon powering the system. If you are emulating, it starts as soon as you plug in your USB adapter. I'm using the Mayflash 2-port USB adapter, but I assume it works with any adapter. It only needs power to calibrate!

Calibration:

Calibration of the joystick is easy with this PCB. The VERY first time you provide power you will be in calibration mode. If you screw up and need to re-enter calibration mode, you have two choices depending on how you soldered the PCB:

IF YOU SOLDERED THE L/Z COMBO PADS- Just hold L and Z while you power on the console/USB Adapter and re-do your calibration.

IF YOU DID NOT SOLDER L/Z COMBO PADS- You are going to have to open the controller and joystick assembly again. Flip the calibration switch on the PCB, and plug your controller into the console/USB Adapter. Power on and wait 2 seconds, then power off. Flip the calibration switch back to its original position. Next time you power up, you will be in calibration mode.

Now spin the joystick around, like you would playing a game. Do this for about 4 seconds so the micro-controller can program the stick's values. Now power off the system, or un-plug your USB adapter. Plug it back in/power on, and load the Controller Test ROM. Check to make sure you have full range on each axis. If you do not, re-calibrate the controller as explained above. Then re-check your values. If everything is good, move on to the next step!

RetroPie and mupen64plus - Troubleshooting buttons and analog range:

This is where you will either be fine, or not fine at all. First thing to do is to configure your controller in Emulation Station, then load up a game. I always choose Super Mario 64, but Zelda is a good candidate as well. Make sure you have full range in all directions, and make sure it is not too sensitive! Make sure if you are playing Zelda, that you can do spin attacks with ease. If you are good on all fronts, then great! Most likely however, you will not be done yet. You most likely will not have proper range, and your buttons will be mapped wrong. So what now? We need to edit some config files.

Button Mapping:

First, let's make sure our buttons are all mapped correctly. Mupen64Plus automatically configures controllers, but it's very hit or miss and often assigns two buttons to the same button. Exit back to RetroPie, and plug in a keyboard. Hit F4 to enter command line. We're looking for three files in particular: InputAutoCfg.ini,  autoconf.cfg and mupen64plus.cfg.  First, open up autoconf.cfg in nano:

sudo nano /opt/retropie/configs/all/autoconf.cfg

Look for a line that says mupen64plus_hotkeys and change it's value to 0. Now we have to open mupen64plus.cfg:

sudo nano /opt/retropie/configs/n64/mupen64plus.cfg

Scroll down to the [Input-SDL-Control] block, and find this line:

# Controller configuration mode: 0=Fully Manual, 1=Auto with named SDL Device, 2=Fully automatic
mode = 2

Change mode to 0. THIS NEEDS TO BE DONE. This turns off auto configuration of the controls, which is necessary so we can configure the proper controls ourselves without them being overwritten every time. You can do this for the rest of the input devices if you are using more than one controller. Press Ctrl+X, then Y to save changes, and Enter to overwrite the file with our changes. Now we need to get our joystick values and buttons. RetroPie has jstest installed by default I believe, so now run:

jstest /dev/input/js0

You will see a table with Axis' and Buttons, and what device we have plugged in. What you want to do here is to press all your buttons and axis' and write down what they correspond to, their values, and write down the name of the device. For example, my Mayflash adapter registers as HuiJia USB GamePad. The C Buttons use axis controls, so C Left might be -3, while C Right is +3. The L trigger might be button 6. Whatever values you get, make sure you write them down, and don't forget to mark down whether they are positive or negative! After you have all your buttons and axis' written down and the device name, we have to apply them to InputAutoCfg.ini. So open it up:

sudo nano /opt/retropie/configs/n64/InputAutoCfg.ini

You will see all the controllers that Mupen64Plus has stored. We're looking for our device name. If it is not there, we will have to create one ourselves. Here is an example of a pre-defined controller:

;USB gamepad            CONFIG START
[USB gamepad]
plugged = True
plugin = 2
mouse = False
AnalogDeadzone = 4096,4096
AnalogPeak = 32768,32768
Mempak switch = 
Rumblepak switch = 
C Button U = axis(2-)
C Button D = axis(2+)
C Button L = axis(3-)
C Button R = axis(3+)
R Trig = button(5)
Start = button(9)
Z Trig = button(4)
A Button = button(2)
DPad U = hat(0 up)
DPad D = hat(0 down)
DPad R = hat(0 right)
DPad L = hat(0 left)
B Button = button(3)
Y Axis = axis(1-,1+)
X Axis = axis(0-,0+)
;USB gamepad            CONFIG END

Again, if you do not see your controller in this .ini file, copy this block and enter it at the end of the .ini file. Replace all the buttons and axis values with the ones you wrote down earlier. Also, you need to make sure that you replace the "USB gamepad" fields with your device's name. Do not change the AnalogPeak or Deadzone values yet. Ctrl+X and save your changes. Test your controls in a game. You should now have properly configured buttons, but if not just go back and make sure you have the correct values for your buttons and axises. Make sure your analog stick is working correctly as well.

Analog Troubleshooting:

If for some reason you still do not have correct analog range, then we will have to use jscal to re-calibrate the joystick. Go into command line with F4, and type:

jscal -c /dev/input/js0

It will now calibrate the joystick. Your input will be required, so pay attention. It will ask you to do minimum, center, and maximum values for all axises. For minimum, you want to have the lowest value you can get on an axis. For example, doing left and right on the analog stick, my minimum was all the way left. Center is self-explanatory; just keep the joystick centered. Maximum was all the way to the right. C Buttons are axises as well, so again in my case C Left was the minimum, no buttons pressed is center, and C Right was maximum. Your mileage will vary, but these are general guidelines to follow for any joystick. After it is done, try a game out again, and you should have the correct analog values.

Last Resort Tactics:

If you still do not have the correct values, try running jscal as is. That ended up being my solution after all of this. You can also solder the Range Extender pad on the PCB to try extending the analog ranges. That requires a bit of soldering to the joystick PCB as well as the N64 controller PCB, so be careful!!!! If all else fails, make sure you have properly soldered everything, and if THAT fails you can try mapping your N64 controller as a Xbox 360 controller or this slightly intimidating guide using some commands in Linux. Good luck!

--------------------------------------------------------------------------------------------------------------------------

Hopefully this is useful for some people seeking help with their controller setups. If someone has anything to add, please let me know! Happy gaming!