Raspberry Pi Setup Guide

Introduction
To get started with Sinden setup on RPi it is recommended you use a fresh, Lightgun dedicated image.

BareBones - The Recommended Image
A Pre Configured Retropie Image for the Sinden Lightgun on the Raspbery Pi4 OG Creator: HarryDog BB8 Creators: cheeky8555, LutherGond, prince_rakeen, wiggy808 BareBones Website

DIY - Custom Image
If you want to integrate the Sinden lightgun into an existing RetroPie build or your own RetroPie build please read the written Setup Guide below

Game Compatibility
Compatibility List

BareBones Basic v7 (by Titchgamer)
https://youtu.be/y62BhziMQPE

Barebones v8 (by Wiggy808)
https://youtu.be/or94oTj1Kyw

2 Player Troubleshooting
For 2 player issues check out Wiggy808's video for pointers:

https://youtu.be/wsP3dMZeBAM

  Sinden Lightgun setup on RetroPie Preface This guide is intended for people who want to set up the Sinden gun(s) in a “mixed” mode, having both lightgun and non-lightgun games on the device. It is also intended to preserve the bezels from e.g. The Bezel Project for non-lightgun games, so we’ll take some extra steps to only add the white borders etc. to the games that need it. The instructions here should get you 100% of the way in most cases, and 90% of the way in the rest, at least for the more common and well supported emulators, i.e.,  ,   (with slight tinkering in the RetroArch’s  here and there),   and  ).  It is highly recommended to learn a bit about RetroArch and how it handles controls  first and take a look at how RetroArch configurations work, as we'll be editing those quite a bit.  Important hint If you have trouble with a particular game, also make sure to check out the Barebones compatibility list. Even though you might not be using that image, it uses the same basic system, so any “go/no-go” and notes will apply to your setup in many cases, too. And some of the hints there are great!  ATTENTION: If you’ve already got a working RetroPie setup or a pre-made image running, feel free to skip to “Copying &amp; Installing the Sinden software”. Things you will need  A Raspberry Pi - This is a credit card sized single board computer. In this tutorial I will be using a Raspberry Pi 4 with 4GB of ram. A micro SD card - This is a small memory card that will be used for storage. A keyboard - There is some typing to do, so a USB or Bluetooth keyboard is very convenient. A Sinden Light Gun (or two) - Although it is possible to set up the system without the gun, you will need one to test it. A game controller (optional but recommended) - RetroPie is designed to be navigated with a game pad. You can configure it to be navigated with keyboard controls, but it is not as intuitive. A PC running Windows with an SD card reader - There are ways of setting the pi up without this, but to make things a simple as possible you’ll need a PC.</li> </ul> <h2 id="downloading-the-drivers">Downloading the drivers First, download the the latest Sinden software version <h2 id="setting-up-retropie-lightgun-drivers-and-basic-calibration">Setting up RetroPie, lightgun drivers and basic calibration <h3 id="preparing-the-sd-card">Preparing the SD Card Now after downloading the latest RetroPie image for your pi model from the RetroPie page, it is time to set it up. Extract the file, and use Win32DiskImager or Raspberry Pi Imager (or some other software) to write the  file to your SD card. Once the process is complete, remove your SD card from your windows PC and pop it in your Pi. Note that if you flash RetroPie as a "Custom Image" in Raspberry Pi Imager, after selecting the image and the target drive, you can use   to open a hidden menu where you can turn on SSH and your configure your hostame and wifi connection. <h3 id="configuring-the-raspberry-pi">Configuring the Raspberry Pi Connect power and your display, game controller, keyboard, and power up your Pi. The first screen you see after loading will tell you a gamepad is connected, and you need to configure it. Follow the instructions on screen. Remember your hotkey, I always set it to the central XBox button on my controller, or the “coin” button on arcade cabinets. The next step is to connect your pi to the internet. You can do this by setting up the inbuilt Wi-Fi on the pi, or you can just pop a network cable in the Pi and the other end into your router. Then we need to give the Windows PC remote access to the Pi: <ul> Select Retropie from the main Emulation Station screen (it’s the only option) and then select </li> Select option 3 </li> Enable option 2  and exit the menu.</li> </ul> In this config tool, you can also configure your wifi connection, for easier access later. Once that is done return to your Windows PC and install WinSCP. This is a file transfer software that will let us drag and drop files from our Windows PC to the Pi (if they are on the same network). <h3 id="copying--installing-the-sinden-software">Copying &amp; Installing the Sinden software Make sure you have the latest version of the Linux Sinden software at hand and extract it. Load WinSCP and start a new session: <ul> Hostname </li> Username </li> Password </li> </ul> You might get a security warning as this is the first time you connect. Accept the information to continue. The screen should now show your PC’s file system on the left and the Pi’s on the right. Copy the folder called  from the Sinden beta folder to the   directory on the Pi. Return to the RetroPie. Strangely, we need to install a game before we do anything else. Let’s use Tyrian. This is needed to create a  directory on the Pi. Go to  in the main Retropie menu, navigate to. Install the game, exit, and restart the Pi. You should now have two options in the main menu:  and. On the main  screen press   on your keyboard. This will take you to a command prompt. Press  after each command below (please type exactly as given here, including capitalization). We will set execution permissions on the scripts and run them. cd Lightgun chmod +x setup-lightgun.sh ./setup-lightgun.sh This might take a couple of seconds/minutes. Then do the same with the ‘’‘retropie-setup.sh’’’ file: chmod +x setup-retropie.sh ./setup-retropie.sh And finally: emulationstation Now you should be back at your nice graphical interface. Go into   and start. Follow the on-screen instructions to calibrate your gun for Player 1. Do the same for, if you have a second gun. Manual Calibration Note: If you want tight control of the calibration, you can also adapt it manually. You'll need to enter offset values for that: For example if you look down sight and the crosshair is to the left of it, you need to increase your x axis value. You can do this buy loading up WinSCP again and editing the  for Player 1 and   for Player 2. Just double click on the file and you can edit it within WinSCP. The lines you need to edit are: Pop a number between the quotes, save, restart the Pi, start SINDENLIGHTGUNTESTP1 and launch a game to see how much the sight is off, repeat until you are happy with the results. There’s no quick way of doing this I’ve found. Player 1 and Player 2 order: If the guns are in the wrong order (e.g. you want a red for P1 and a blue gun for P2, but they show up the other way around), just switch the USB plugs and their ports around or to see the boot order for the Pi4 see this video. Before we start gaming, we still need to do a couple of more things. And that is updating/patching retroarch, as the stock version that comes with RetroPie has issues with Lightgun support. <h3 id="patchingupdating-retroarch">Patching/Updating RetroArch First, we need to start  once more, and select. Exit RetroPie-Setup after the update completes. Now, to install the patched version of RetroArch 1.9.9, you can use the  and   files provided by Discord User @LutherGond#7287. I packaged them into a ZIP. They are based on cmitu’s github fork of Retroarch and can be downloaded here. Download and unzip the file. Copy the file  into , and run   on it. Copy the other files into the   subfolder in that same directory. Overwrite any files that may be already present and add any files that are not (specifically,  is new and contains the main lightgun workaround). Then, start  (run  ), go to. it and then. This will take a while, as you’re now building and installing RetroArch from scratch, while applying cmitu’s patches. Alright, now you have a version of RetroArch that can handle lightguns properly. <h2 id="creating-a-basic-mapping-for-the-lightgun">Creating a basic mapping for the lightgun While working for multiple “mouse”-based devices (such as our lightguns), it seems that retroarch (and maybe other programs, too) don’t differentiate between keypresses from multiple keyboards. To get the guns to send non-conflicting keypresses, we may need to reconfigure some of the buttons on it. Do this by editing the mapping. What follows is the recommended keymaps for players 1 and 2. These have been made to conform as closely as possible with standard MAME key for in order to reduce the aount of manual adjustment you may need to do later on (with the exception of Player 1 coins, which is "5" in mame, but we will use Left-Alt) (the   indicates that there is text between those two blocks to edit that you don’t need to touch): &lt;add key="ButtonTrigger" value="1" /&gt; &lt;add key="ButtonPumpAction" value="3" /&gt; &lt;add key="ButtonFrontLeft" value="3" /&gt; &lt;add key="ButtonRearLeft" value="2" /&gt; &lt;add key="ButtonFrontRight" value="9" /&gt; &lt;add key="ButtonRearRight" value="7" /&gt; &lt;add key="ButtonUp" value="74" /&gt; &lt;add key="ButtonDown" value="75" /&gt; &lt;add key="ButtonLeft" value="76" /&gt; &lt;add key="ButtonRight" value="77" /&gt; ... &lt;add key="ButtonTriggerOffscreen" value="3" /&gt; &lt;add key="ButtonPumpActionOffscreen" value="3" /&gt; &lt;add key="ButtonFrontLeftOffscreen" value="3" /&gt; &lt;add key="ButtonRearLeftOffscreen" value="2" /&gt; &lt;add key="ButtonFrontRightOffscreen" value="9" /&gt; &lt;add key="ButtonRearRightOffscreen" value="7" /&gt; &lt;add key="ButtonUpOffscreen" value="74" /&gt; &lt;add key="ButtonDownOffscreen" value="75" /&gt; &lt;add key="ButtonLeftOffscreen" value="76" /&gt; &lt;add key="ButtonRightOffscreen" value="77" /&gt; This will set the d-pad to use the  keys and the right buttons to use the   &   keys for Start and Select/Coins, respectively, for gun 1. Similarly, modify  to read like this: &lt;add key="ButtonTrigger" value="1" /&gt; &lt;add key="ButtonPumpAction" value="3" /&gt; &lt;add key="ButtonFrontLeft" value="3" /&gt; &lt;add key="ButtonRearLeft" value="2" /&gt; &lt;add key="ButtonFrontRight" value="10" /&gt; &lt;add key="ButtonRearRight" value="14" /&gt; &lt;add key="ButtonUp" value="61" /&gt; &lt;add key="ButtonDown" value="49" /&gt; &lt;add key="ButtonLeft" value="47" /&gt; &lt;add key="ButtonRight" value="50" /&gt; ... &lt;add key="ButtonTriggerOffscreen" value="3" /&gt; &lt;add key="ButtonPumpActionOffscreen" value="3" /&gt; &lt;add key="ButtonFrontLeftOffscreen" value="3" /&gt; &lt;add key="ButtonRearLeftOffscreen" value="2" /&gt; &lt;add key="ButtonFrontRightOffscreen" value="10" /&gt; &lt;add key="ButtonRearRightOffscreen" value="14" /&gt; &lt;add key="ButtonUpOffscreen" value="61" /&gt; &lt;add key="ButtonDownOffscreen" value="49" /&gt; &lt;add key="ButtonLeftOffscreen" value="47" /&gt; &lt;add key="ButtonRightOffscreen" value="50" /&gt; This will set the d-pad to use the  keys and the right buttons to use the   &   keys for Start and Select/Coins, respectively, for gun 2 Both players use mouse buttons 1 for trigger, 2 for back-left and 3 for pump, front-left and offscreen trigger. In order to have a clean central place to configure the lightgun inputs for RetroArch, I created a file  in , with this content: config_save_on_exit = false
 * 1) Never save-on-exit after an override config
 * 2) or the override will make into the core config.

input_player1_mouse_index = "0" input_player1_gun_trigger_mbtn = "1" input_player1_gun_offscreen_shot_mbtn = "3" input_player1_gun_aux_a_mbtn = "3" input_player1_gun_aux_b_mbtn = "2" input_player1_gun_start = "num1" input_player1_gun_select = "alt" input_player1_gun_dpad_up = "up" input_player1_gun_dpad_down = "down" input_player1_gun_dpad_left = "left" input_player1_gun_dpad_right = "right"

input_player2_mouse_index = "1" input_player2_gun_trigger_mbtn = "1" input_player2_gun_offscreen_shot_mbtn = "3" input_player2_gun_aux_a_mbtn = "3" input_player2_gun_aux_b_mbtn = "2" input_player2_gun_start = "num2" input_player2_gun_select = "num6" input_player2_gun_dpad_up = "r" input_player2_gun_dpad_down = "f" input_player2_gun_dpad_left = "d" input_player2_gun_dpad_right = "g"

This maps most lightgun inputs (except for the left rear button) to the standard gun inputs of RetroArch to the buttons we’ve configured our lightguns to send. This is good news! Now all emulators will receive the “correct” inputs! <h2 id="how-to-map-individual-games">How to map individual games These steps might vary slightly from emulator to emulator, and sometimes even for games. I found they work mostly verbatim for,   and  , and other emulators follow a similar mode. works with a bit of tinkering. It also works mainly in, but the gun’s buttons are hard-coded to the mouse button inputs. This is fine for most games, but e.g. for Resident Evil: Survivor, the mapping did not suit me at all. So I used  instead, which worked fine right out of the gate, but does not support two lightguns at the same time. Some tinkering in the  menu of RetroArch might be required here and there, e.g. for gun offsets, crosshair toggling/colors/models/enabling lightgun input, but mostly things work fine out of the box, as far as I’ve tested it. <h3 id="border-overlay-and-override-files">Border overlay and override files Start the game you like to configure, get into, press  to get into the RetroArch menu. Go to, make sure the overlay is enabled, and select   (you might have to exit a couple of folder levels if you have The Bezel Project or other bezels installed). Note: If you feel that the gun is acting jittery (can happen if you’re in a bright room or standing quite close to the screen), then you can also opt to use     instead, which is a bit broader. Exit the overlay menu. Note: This is also the place where you can setup the 4:3 screen ratio or any shaders you might want to use for this game. I recommend choosing the shaders on a case-by-case basis, as e.g. barrel distortion can lead to the aim being off, and resource intense shaders might impact the game’s performance. Go to Overrides and select  (if you have not configured any game for this core yet, just to create a file) and. Exit the game (usually ). If you’ve already set up the controllers as lightguns (see below), you absolutely need to restart the game, because for some reason retroarch loses the gun mappings after saving the remap/override. Note: You could also create a config file with e.g. the overlay and your shaders, and  it for each lightgun game’s override instead. I just set it individually when starting the game for the first time, while testing everything out in it. <h3 id="lightgun-mappings"> Lightgun mappings If this is the first game for this core, go to the newly created core override config file, e.g.  for Flycast. Delete all of its contents (yes, you read that right) and replace them with just: Note: Some games require special mappings/configs. For those, take a look at the BB8 compatibility list. Duck Hunt for NES is one of them (so actually not ideal to start with). It requires the gun to be in Port 2. If you have two guns, no problem, just use the second one. If you only have one, you can add this to the game override you created earlier for the border (depending on your rom and core, this will have a path similar to or to map it in all NES emulators you can use  ), which will map your gun to Port 2 instead of Port 1 (and vice versa, for that matter) for that particular game: input_player1_mouse_index = "1" input_player2_mouse_index = "0"
 * 1) include "/opt/retropie/configs/all/retroarch/config/lightgun.cfg"
 * 1) Switch mouse

input_player1_select = "num6" So much for Duck Hunt. What we've set up will now load our lightgun input settings each time the core is loaded. This is needed, as the main retroarch config is overwritten by EmulationStation on each button remapping in the EmulationStation controller setup, and not all cores require our gun mappings. This way you can still use that way of configuring your controller in EmulationStation, but also add your lightgun mapping. Now, start the game again. Go into the RetroArch menu as before, go up one level, and go to  and open Port 1. Scroll down and make sure the gun mappings are loaded. Do the same for Port 2. Now, go back to. Go into Port 1 and select  (or similar, e.g.   for PSX,   for NES) - unless it is e.g. Duck Hunt on NES (see the note above). Do the same for Port 2 (if you have two lightguns or if you have mapped your gun to Port 2). Then select. Exit the game (after this configuration, the lightgun input mappings tend to get lost temporarily), and start it again. Now you should be able to play it! Congrats! <h2 id="some-convenience-and-pretty-stuff">Some convenience and pretty stuff <h3 id="pretty-entries-for-lightgun-utilities-in-emulationstation">Pretty entries for Lightgun utilities in EmulationStation To make the utility entries in the EmulationStation frontend a bit prettier, I downloaded this image from the Sinden homepage, named it  and copied it to  Then edit   and add the following snippet at the bottom: &lt;game&gt; &lt;name&gt;Sinden Lightgun Test P1&lt;/name&gt; &lt;image&gt;~/.emulationstation/downloaded_images/ports/SindenImage.jpg&lt;/image&gt; &lt;desc&gt;Sinden Lightgun Test for Player 1&lt;/desc&gt; &lt;path&gt;./SindenLightgunTestP1.sh&lt;/path&gt; &lt;name&gt;SindenLightgunTestP1&lt;/name&gt; &lt;/game&gt; &lt;game&gt; &lt;name&gt;Sinden Lightgun Test P2&lt;/name&gt; &lt;image&gt;~/.emulationstation/downloaded_images/ports/SindenImage.jpg&lt;/image&gt; &lt;desc&gt;Sinden Lightgun Test for Player 2&lt;/desc&gt; &lt;path&gt;./SindenLightgunTestP2.sh&lt;/path&gt; &lt;name&gt;SindenLightgunTestP2&lt;/name&gt; &lt;/game&gt; &lt;game&gt; &lt;path&gt;./SindenLightgunStartP1.sh&lt;/path&gt; &lt;name&gt;Sinden Lightgun Start P1&lt;/name&gt; &lt;desc&gt;Sinden Lightgun Start for Player 1&lt;/desc&gt; &lt;image&gt;~/.emulationstation/downloaded_images/ports/SindenImage.jpg&lt;/image&gt; &lt;/game&gt; &lt;game&gt; &lt;path&gt;./SindenLightgunStartP2.sh&lt;/path&gt; &lt;name&gt;Sinden Lightgun Start P2&lt;/name&gt; &lt;desc&gt;Sinden Lightgun Start for Player 2&lt;/desc&gt; &lt;image&gt;~/.emulationstation/downloaded_images/ports/SindenImage.jpg&lt;/image&gt; &lt;/game&gt; &lt;game&gt; &lt;path&gt;./StopSindenLightgun(s).sh&lt;/path&gt; &lt;name&gt;Sinden Lightgun Stop&lt;/name&gt; &lt;desc&gt;Sinden Lightgun Stop for both Players&lt;/desc&gt; &lt;image&gt;~/.emulationstation/downloaded_images/ports/SindenImage.jpg&lt;/image&gt; &lt;/game&gt; Restart EmulationStation, and now under  your entries should look a lot nicer. <h3 id="run-lightgun-drivers-automatically">Run Lightgun drivers automatically If you want your lightguns to start when you start a game, and stop them afterwards, you can use this method. Create a file  and add this content: "/home/pi/RetroPie/roms/ports/SindenLightgunStartP1.sh" "/home/pi/RetroPie/roms/ports/SindenLightgunStartP2.sh" Set  on the file to make it executable (i.e. run  ). Similarly, create a file, and add this content: "/home/pi/RetroPie/roms/ports/StopSindenLightgun(s).sh" Also set  on the file to make it executable. Now the lightgun software is started before your emulators are launched, and stopped afterwards. <h2 id="patched-lr-mame2016">Patched lr-mame2016 Newer mames seem to have issues with lightgun support. works fine, but it does not support as many games as, e.g. . There is a patched version by MrLightgun. Edit  and find this snippet function sources_lr-mame2016 { gitPullOrClone } Change it to read like this: function sources_lr-mame2016 { # gitPullOrClone gitPullOrClone "$md_build" https://github.com/MrLightgun/mame2016-libretro.git } Now, as before with RetroArch, start   (run  ), go to. it if required, then´Install from source´. This will take quite a while. Afterwards, lightgun support for  should be patched. More info on how to use this can be found in  which comes with the latest stable download from the Sinden page (see above). I personally have it patched, but I got all arcade games I wanted working with either ,   or  , so I’m not using it currently. <h2 id="in-closing">In closing That was quite a ride! Hopefully, you could follow the instructions here without too much hassle. I’m not sure they work for every use-case. But they worked for mine. Thanks a lot, to the nice people helping in the Sinden Lightgun Discord’s raspberry-pi-help who I’ve bothered quite a bit in recent weeks. But this guide might be giving some of it back in a extensive but condensed format, so others don’t have to :-) Happy shooting!
 * 1) Map the front right button to trigger "select" on controller in port 1, for choosing game mode
 * 1) !/bin/bash
 * 1) !/bin/bash

DC/Naomi/Atomiswave
For Dreamcast / Naomi / Atomiswave setup for your Pi4 check out this page:

https://sindenlightgun.miraheze.org/wiki/Flycast