charcole / LCDZapper

Device for making light gun games playable on LCD TVs
Other
155 stars 18 forks source link

PSX Cable (using Arduino Nano) #22

Open dekkit opened 3 years ago

dekkit commented 3 years ago

Initial instructions on how to build an adapter cable to connect your Wii mote to your PS1/PSX using a LCDGunverter.

What you'll need:

Optional - Arduino prototyping /breadboard wires. Multimeter to test connections.

Note: You should be able to build this without soldering and using just cable/wire joiners (if your nano comes with pins already soldered on)

Setting up the Ardunio Nano Download and install the Arduino software (IDE), found at https://www.arduino.cc/en/Main/Software Connect nano to pc Open IDE Go to "Tools" > "Board:" select Arduino Nano As per following 20210512_222122

Check also the 'port:' (it can change each time you unplug and plug in nano to pc ..ie port 3 or port 4).

You should now be ready install the 'active cable' firmware to you nano.

The original can be initially downloaded from https://github.com/charcole/LCDZapper/blob/master/Firmware/ActiveCables/PSXGun.ino

Although check here for updates as there a few changes required for the code (see main discussion issue for details).

Scroll down for guncon45 version attached to the bottom of this post

Compile and upload .ino to Nano Connect nano to pc and open the arduino IDE Open PSXGun.ino Click on the verify button Click in the upload button

Your nano should now be ready for wiring the connection.

Creating custom cables

There are 2x parts to wiring

I used a cable from a broken ps2 controller and soldered then to a breadboard/ protoyping cables.

[UPDATE 6/6/2021]- old ps2 controlpad cables were a bad idea and caused so much wasted time. Suggest to open the male psx sockets and solder new wire!]

Original attempt (see other recent posts for better examples) 20210513_204945

This cable proved to be too long and resulted in strange issues (gun would only register in some parts of the screen).

For the RJ45 cable, i cut a cat5 network cable and stripped the wires and connected to breadboard style wires.

20210513_204830 Note: wire colors on the rj45 pic were different to my wiring diagram (as its the only colors i had left)

Make sure you test contuinity with a multimeter to ensure your wires correspond with the intended pins.

Wiring Arduino to LCDGunverter This part should be straight forward - simply connect the cable pins to the nano.

118137473-95467600-b448-11eb-8258-371efc77384a Correction 1: VCC on nano should use the 5v pin not the 3.3v pin to the rj45 (this is needed to pull up the tx signal to the nano otherwise it wont detect controller)

20210513_210217

images (36)

20210513_223125 Note:

Setting up LCDGunverter to use adapter Once connected and plugged in to psx and LGV, power on all devices.

In LGV, set to 'custom' cable and press A on wii mote. Press Home on wii mote to bring up LGVmenu and use arrow keys to select IO Type.

You should notice an smd led on the nano will turn on to indicate it is receiving data from the LGV.

Testing the results This cable is still very much in development, so you may need to use another psx controller to get thru game menus as not all not all buttons from wii mote were working.

Initial signs are promising... 20210515_120911_HDR

20210515_121546_HDR

Updated - got it working great! (6/6/2021) - this .ino file worked for me! Includes some additional commentary in case anyone would like to make further modifications. PSXGun_GUNCON45_ArduinoNano.ino.txt

Wiimote buttons layout

Dpad LEFT = guncon A Dpad RiGHT = guncon B Trigger (B) = guncon trigger

dekkit commented 3 years ago

@charcole Can you recall what is happening at the following lines of code with the x and y gun position?

Screenshot_20210516-184025(1)

Im wondering if there is a pal/ntsc issue with how many lines the nano guncon45 is responding back to the psx.

Also can you recall how many wii remote buttons are being communicated through to the io serial (assuming just A and B?)

dekkit commented 3 years ago

Further testing...

The Wii mote's Dpad LEFT and RIGHT function as the guncon's A and B button.

Useful to get through game menus.

Was able to get the arduino nano to provide debug info (via adding serial print lines to the .ino filr) and viewing via the Arduino IDE serial terminal window on PC. Outputs to ps1 seem to be correct from probing the reply outputs.

I still cant explain why the X and Y doesnt seem to work well at all (seems to be certain large chunks of screen area which dont register). This results in the screen flashing as if a normal guncon is pointed away from the screen.

Ill need to probe further with adding further debug lines to my .ino. I hope the arduino isnt introducing a delay that is throwing out possible video timings but too early to say.

charcole commented 3 years ago

It shouldn't be a timing issue. GunCon guns do the timing internally which is why they need the composite input (only Konami gun games needs the timing circuitry of LGV). The Arduino sketch just needs to tell the console the coordinates of the cursor. The "Serial" mode on LightGunVerter just sends the coordinates it gets from the Wiimote and the GunX/GunY math converts it to what the PSX expects. From memory I think the Wiimote returns coordinates are 0 to 1024 (X) and 768 (Y) while PSX will expect a time delay for X and a line number for Y. The LGV could return the exact line number, that's what I did for the GunCon 2 cable, but in this version I just did some maths.

X axis is flipped (1023-X). Then scaled ((FlippedX*3)>>8). >>8 (half 8 times) is same as divide by 256 so scaling is 3/256. Then 0x4D (77 in decimal) offsets it left and right. Similarly for Y 11/52 scaling plus 32. This would have been done on PAL so the Y will definitely be wrong as PAL has more lines. X should still be close but might need some tweaking.

Hope that helps.

PS. The button bit flags are shown in https://github.com/charcole/LCDZapper/blob/master/Firmware/main/esp_wiimote.h. You should get everything but the Home button.

dekkit commented 3 years ago

Awesome thanks for the additional insights, its been a great learning experience working arduino, spi, and seeing how button switches polled and then get encoded. Hopefully documenting as i go will help others too.

dekkit commented 3 years ago

Finally success for GunCon45!

Added the . ino that works for me to the first post.

Actual wiring used (updated diagram) PSX_Wiring Diagram_GUNCON45

Shortened cable, completely removed old control pad wire.

The bad cable was causing all sorts of weird effects. The benefit however was really understanding how your code works and learning how the ps1 communicates with its control pads via SPI.

Thanks @charcole - it works great now!

dekkit commented 3 years ago

Example of the working cable 20210605_215050

Exposed socket, cut wire, and soldered in wires to connect to nano! 20210605_174430

Point Blank 3 still so much fun! 20210605_220836_Burst01