PJ – Troubleshooting Controls

Overview:

On the PJ JAMMA adapter board, a joystick event is detected when the COMM LED stops flashing and stays on. The LED should stay lit when a joystick is pushed, a switch is activated or a button is pressed, and resume blinking when it’s released.

If the LED continues to flash and is not staying ON when a button is held, the PJ board is not detecting the button press. If the LED stays on with no buttons or switches being active, you may have a stuck switch, a short in the wiring, or the adapter’s input section may be bad.

Try using the adapter in a different cabinet. Check your wiring. Check the four 74(HC)165 ICs on the PJ board. These chips normally stay cold to the touch. If one or more appear unusualy warm, it’s a dead giveaway that one of the chip’s inputs got blown. If found faulty, replace the four socketed ICs.

During initial start up, the COMM LED on the adapter flashes quickly, off and on approximately twice per second. Once the OS drivers are loaded and successful communication with the Raspberry Pi is estabilished, the flashing will slow down to approximately once per second.

If the speed of the LED flashing doesn’t change after Linux fully boots, please ensure that the PJ adapter drivers are loaded. If loaded, either the GPIO on the Pi, or the MSP430 microcontroller on the PJ board may be faulty.

Check to logs in /var/log/debug

Input Event Chain

Once the pjjoy driver is loaded, the udev driver manager loads the necessary joydev (standard linux) and evdev (event) driver modules. The SDL library which emulationstation and retroarch uses, reads events from the evdev driver, assuming the evdev device is a joystick / gamepad. Here’s how the control events are passed from the drivers to the emulators.

pjjoy (joydev linux driver) <-> evdev (event driver) <-> SDL2 (media library) <-> emulationstation (retropie front end)

Reading the state of the joystick, button and switch controls:

The joydev driver module pjjoy provides standard joystick interface devices for use in Linux. The best way to troubleshoot these controls it to use the joystick test utility jstest against device driver files /dev/input/js0 (player 1) and /dev/input/js1 (player 2). These device files will not be present unless j4b and pjjoy modules are loaded (in that order).

To monitor the state of the controls run:

sudo jstest /dev/input/js0 (or js1)

You should get something that resembles what is below:

Driver version is 2.1.0.
Joystick (PJ 2-axis 12-button digital controls) has 2 axes (X, Y)
and 12 buttons (BtnSelect, BtnStart, BtnMode, Btn1, Btn2, Btn3, Btn4, Btn5, Btn6, Btn7, Btn8, ExtraBtn).
Testing ... (interrupt to exit)
Axes:  0:     0  1:     0 Buttons:  0:off  1:off  2:off  3:off  4:off  5:off  6:off  7:off  8:off  9:off 10:off 11:off

The evdev device can be tested using the evtest test utility:

sudo evdev /dev/input/event0 (or event1)

You should get something that resembles what is below:

Input driver version is 1.0.0
Input device ID: bus 0x6 vendor 0x4147 product 0x5046 version 0x101
Input device name: "PJ Arcade Controls"
Supported events: ...

Finally, the controls can be tested from SDL, the way the emulator would receive them. For that the utility sdljoytest has been provided. The utility can be found in /home/pi/utilities/sdljoytest and may need to be compiled (run “make clean“, then “make” as usual). The following example retrieves joystick info, with other options the utility can display controller events.

/home/pi/utilities/sdljoytest –t 0

You should get something that resembles what is below:

 
Note: using sdljoytest –l will return joystick properties from the PJ drivers:
Found 2 joystick(s)
 
Joystick Name:     'PJ arcade controls'
Joystick GUID:     06000000474100004a50000000010000
Joystick Number:    0
Number of Axes:     2
Number of Buttons: 12
Number of Hats:     0
Number of Balls:    0
GameController:
  not a gamepad
 
Joystick Name:     'PJ arcade controls'
Joystick GUID:     06000000474100004a50000000010000
Joystick Number:    1
Number of Axes:     2
Number of Buttons: 12
Number of Hats:     0
Number of Balls:    0
GameController:
  not a gamepad
 

The GUID from the SDL joystick definition must match the GUID in the emulationstation es_config file. If joystick doesn’t show up in SDL but exists as a linux and as a evdev device, check if ID_INPUT_JOYSTICK=1 property is set using udevadm.

Simulating joystick events using the keyboard:

It’s possible to insert joystick and button events using joytest utility. This can be used for troubleshooting the driver and emulation configuration by passing the controller hardware on the PJ.

Compile the utility:

cd /home/pi/utilities/joytest/
make clean
make

Run the joytest utility as follows:

cd /home/pi/utilities/joytest
sudo ./joytest /dev/j4binput0

The utility should display the following control options. Either player 1 or player 2 controls can be tested by selecting the appropriate joystick device (/dev/j4binput0 or /dev/j4binput1).

Using queue: /dev/j4binput0
Press ~ to quit
Use W,S,A,D for UP,DOWN,LEFT,RIGHT
Use I,O,P,J,K,L for BUTTON 1,2,3,4,5,6
Use Z,X,C,V for SELECT,START,EXTRA,MODE
ch = 0032 ' ', val = 0000, msg = 8.0.0.0, wrote = 1
Press "~" to quit the utility.