I2c and interrupts for Sega Saturn light gun replacement for LCD TVs

Hi, this is my first post here. I am fairly new to Arduino and electronics in general. I have messed about with some simple stuff (LED blinker) but am now working on a small project to get a Sega Saturn light gun working on a modern LCD TV. I know there is another recent project out there but the creator appears to want to go down a commercial route and it will support other consoles too. I want to put this in the public domain. What follows is a lengthy explanation of how it works. My question is in the last couple of paragraphs.

I am working on replacing the insides of an official Sega Saturn light gun with an Arduino based solution so that I can use the gun with a modern LCD TV. Once I have a working version I will post more details somewhere for others to copy and/or improve it.

So far I have successfully wired an Arduino Nano to a Saturn controller cable and can issue 'Fire' and 'Start' button actions. By having the button actions controlled by the Arduino I can use the buttons for gun calibration without messing with the running game. I envisage it will also make it easy to add rapid fire and auto reload in future.

I use an IR positioning camera in a similar style to the Wii controller to establish where the gun is pointing. In tests it is fairly accurate although it currently doesn't support being move in relation to the TV or being rotated (for those gangsta type shooters). This can be improved but I will deal with that later.

I use an LM1441 to get the vsync and hsync from the composite TV signal and this allows me to create a signal that mimics the old scan-line detection when the screen flashes white. By counting the hsync signals for vertical positioning and using a timer for the horizontal position I can send a signal and it 'fires' at a given position on the screen. I will use the positional information from the camera to adjust when to fire this signal.

Timing is crucial here as even a microsecond can throw the position off enough to ruin the experience. I used two interrupt pins to detect the vsync and hsync. This gives me very accurate vertical positioning. I use a hardware interrupt timer with a 0.5 µs pre-scaler configuration to get the horizontal positioning. Each horizontal timing occurs between hsync interrupts (64 µs on PAL signal) so the is no conflict there.

The problem is with reading the IR camera position. The camera uses I2c. I have timed it using an oscilloscope and it takes 23 µs. Since the first 6 scan-lines are not visible I tried adding the IR read to occur after the first hsync after a vsync. In theory there is plenty of time to take the reading and still be able to fire the 'fire' signal at the right time (location). However, the I2c doesn't seem to work from within the hsync interrupt. I understand that this is due to interrupts being disabled while it is processing an interrupt. My question, finally, is what would be a good way around this? My only possible solution is to set a volatile variable in the first (after vsync) hsync interrupt and check for this in the loop and run the IR read in the loop. As I am still new to Arduino I want to know if there is there a better way?

One final question, where is the preferred place for publishing Arduino projects? I don't want to set up my own webpage or blog for this.

set a volatile variable in the first (after vsync) hsync interrupt and check for this in the loop and run the IR read in the loop.

That is the way that it is done, as far as I know. ISRs should have minimum code, anyway.

preferred place for publishing Arduino projects?

I don't know preferred but, there is the [Exhibition/Gallery section](http://preferred place for publishing Arduino projects?) of the forum.

Thanks. It seems to work well.

What's an LM1441? Google doesn't recognise it...

Thanks. It seems to work well.

Do you have an example for this? I'm trying to emulate a megadrive controller and seem to be running into a similar timing issue.