Main Restorations Software Audio/Jukebox/MP3 Everything Else Buy/Sell/Trade
Project Announcements Monitor/Video GroovyMAME Merit/JVL Touchscreen Meet Up Retail Vendors
Driving & Racing Woodworking Software Support Forums Consoles Project Arcade Reviews
Automated Projects Artwork Frontend Support Forums Pinball Forum Discussion Old Boards
Raspberry Pi & Dev Board controls.dat Linux Miscellaneous Arcade Wiki Discussion Old Archives
Lightguns Arcade1Up Try the site in https mode Site News

Unread posts | New Replies | Recent posts | Rules | Chatroom | Wiki | File Repository | RSS | Submit news

  

Author Topic: Cygun - diy lightgun written in Python  (Read 1253 times)

0 Members and 1 Guest are viewing this topic.

Cynob

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 4
  • Last login:February 09, 2025, 09:09:08 am
  • I want to build my own arcade controls!
Cygun - diy lightgun written in Python
« on: January 07, 2025, 12:07:13 pm »
Hello,
I was sent over here by reddit to start a thread. They think it would be a good idea.
So I'm in the process of building and programming a lightgun. The whole thing is open source and get published on github.
Before I change my mind, I thought I'd start a thread here to document the whole development and add any tips or other information.

As already mentioned, the whole thing is written in Python. It's not exactly economical with the CPU - but it's fun!

A rough overview of what you need:
- 3D printer for the Lightgun
- a USB webcam that delivers at least 60 FPS at 1280x720. (The more the better)
- Arduino with buttons for the fire and other buttons

I am currently designing the Lightgun in Fusion360 and it is currently nothing more than a frame model. I want to finish designing it before I present it.
A detailed parts list is also still to come.

So far it runs on Windows and comes with its Python environment, so you don't have to install anything.
The plan is to support two players/lightguns later on.

I would like to cover various possibilities for position detection:
- with a frame on the display as like the Sinden Lightgun
- with the help of one or more Aruco markers which you can either display as an overlay or print out and hang up.

But first I'll concentrate on the software solution with the frame on the screen. There are still a few other things to do.


The setup in a nutshell:

All you really need is a USB webcam and an Arduino as well as a few buttons to equip your own gun.
Not everything works automatically yet. But I have created several scripts which help with the setup. You just have to run them one after the other so that you have created all the settings and written them to the configuration file.

First you flash the Arduino with the enclosed code and solder the 5 buttons to it.

Then you can plug the webcam into your PC and start the first script. This recognizes all connected webcams, lets you select the correct one, tests the selection and informs you of the possible FPS at which resolution is possible. Now you can save the values that seem to make the most sense.

The next step is to determine the displayed frame size, or more precisely its circumference. To do this, start the next script which, after it tells you that you should point the cam at the TV in the approximate playing/shooting position that you will take later, starts to draw an increasing rectangle on the screen. When the rectangle covers the entire screen, the value is determined and is also saved in the configuration file.

To align the webcam to the corner points, there is a button that you can assign later to be able to call up the function at any time (also ingame). But that's all you have to do with the camera for now.

Now connect the Arduino to the PC via USB and start another script. This searches for the possible connections and lets you select one. The script then tests the Arduino to see if it is the right one. If everything runs successfully, the necessary settings are also saved.

Since the software still needs to know which buttons should be pressed and when, there is also a script that guides you through the mapping.

And that's it. Once you have chewed through all the scripts, you can start the actual program and the cam takes over the mouse and keyboard.

I'm still working on the Github repo. As soon as it's online I'll attach the link here.

Best regards and see you soon!

Cynob

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 4
  • Last login:February 09, 2025, 09:09:08 am
  • I want to build my own arcade controls!
Re: Cygun - diy lightgun written in Python
« Reply #1 on: January 10, 2025, 09:55:44 am »
So here is the link to github: https://github.com/Cynobs-repo/cygun

Any suggestions?

Fursphere

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1246
  • Last login:Yesterday at 08:50:11 pm
Re: Cygun - diy lightgun written in Python
« Reply #2 on: January 10, 2025, 01:16:02 pm »
What are the pro/con's of choosing this solution vs. GUNIR / Sinden / RetroShooter / Blamcon / (other lightgun solution I haven't mentioned) ?

You already mentioned that python is non-optimal for cpu performance (con). 

Cynob

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 4
  • Last login:February 09, 2025, 09:09:08 am
  • I want to build my own arcade controls!
Re: Cygun - diy lightgun written in Python
« Reply #3 on: January 12, 2025, 12:20:50 am »
Hello @Fursphere
I don't think I have to justify myself to you here. You can read the source code to deduce for yourself what is better or worse than your preferred lightgun.

If a moderator reads this:
The forum is dead and the only thing you can do here is justify yourself to some randoms from the internet. You are welcome to delete this thread. I'm not putting any more work into it.
Thanks for the great forum you offer here.

Fursphere

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1246
  • Last login:Yesterday at 08:50:11 pm
Re: Cygun - diy lightgun written in Python
« Reply #4 on: January 12, 2025, 01:33:55 am »
-sigh-

You say you need a 3d printer, but you don't provide STLs (or even links to reference STLs in the usual places).
You say you need a webcam, but you don't provide a reference model (this has been tested with blah hardware).

You did provide the Arduino sketch, so that was cool.

Your wiring diagram didn't mention the resistors normally used when connecting buttons to an arduino.   So I was left with questions there. 
Your solution appears to require running two separate usb cables from the 'gun' to the PC, one for the arduino, the other for the webcam.  Little clunky.   But since you don't even have a reference build, I guess you hold the camera in one hand, then the ardunio and buttons in the other? 

Good luck with your project.   

Cynob

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 4
  • Last login:February 09, 2025, 09:09:08 am
  • I want to build my own arcade controls!
Re: Cygun - diy lightgun written in Python
« Reply #5 on: January 12, 2025, 01:57:08 am »
if you had read the thick colored info at the top of the readme in github that there is still a lot to do, your questions would answer themselves.

About the circuit diagram for the Arduino: If you had taken a look at the .ino you might have noticed that I use the internal resistors. Yes, that actually works and you can read about it here: https://docs.arduino.cc/tutorials/generic/digital-input-pullup/

And on the subject of USB: There are such nice little USB hubs with soldering pads that are just a few millimeters in size and fit into the light housing.... I don't know how else you imagine the thing?
 Well, find another topic where you can try to badmouth what's on offer, you don't have to use it or read anything about it if you don't like it.