I know this is really old now but I just learned that you can play the NES Light Gun games on modern LCD screens. A few things are required to make this happen. There is a patch that must be applied to the game ROM. They make devices read your NES games and create ROMs and these could be patched and with a proper flash cartridge these patched games can be played on the original gaming system. I didn't want to shell out for one of these game cartridges so I tried to modify the light gun (Original NES Zapper) to no longer have the 15K filter and to also be able to plug into a USB for Emulation on a PC or RaspBerry Pi. I have referenced at least a dozen websites trying to get this to come together. My dilemma the digisparks boards I tried to get twice from Amazon but they canceled my orders twice. I then opted to get a board based off the same micro controller. So instead of a digispark or teensy 2.0 I was able to get my hands on a Pro Micro Arduino. In Arduino IDE 2.3.4 it registers as a Arduino Micro but from what I can tell this is ok. I have a sketch file that I have been trying to compile but it is not happy. I get the feeling that it has something to do with
"You must select Joystick from the "Tools > USB Type" menu" that I cannot seem to find this option They commented this out in the code so must be part of my problem but cannot find it. They were using Arduino IDE 1.8.9 so i thought fine I will go get that. It still wasn't there. My sketch file looks like this
#include <Joystick.h>
Joystick_ Joystick;
/* Basic USB Joystick Example
Teensy becomes a USB joystick
You must select Joystick from the "Tools > USB Type" menu
Pushbuttons should be connected to digital pins 0 and 1.
Wire each button between the digital pin and ground.
Potentiometers should be connected to analog inputs 0 to 1.
This example code is in the public domain.
*/
// Pin 13 has an LED connected on most Arduino boards.
// Pin 11 has the LED on Teensy 2.0
// Pin 6 has the LED on Teensy++ 2.0
// Pin 13 has the LED on Teensy 3.0
// give it a name:
#define LED B0
// https://golem.hu/article/pro-micro-pinout/
#define D0 3
#define D1 2
void setup() {
pinMode(D0, INPUT_PULLUP);
pinMode(D1, INPUT_PULLUP);
// initialize the digital pin as an output.
pinMode(LED, OUTPUT);
Joystick.useManualSend(true);
}
void loop() {
// read analog inputs and set X-Y position
//Joystick.X(analogRead(0));
//Joystick.Y(analogRead(1));
// read the digital inputs and set the buttons
int d0 = digitalRead(D0);// trigger
int d1 = 1 - digitalRead(D1);// light
// set "buttons" state
Joystick.button(1, d0);
Joystick.button(2, d1);
digitalWrite(LED, d0 ? HIGH : LOW); // turn the LED on (HIGH is the voltage level)
Joystick.send_now();
}
I get the error code exit status 1
Compilation error: 'class Joystick_' has no member named 'useManualSend'
I can't for the life of me figure out how to resolve this. Any help would be greatly appreciated. If you see any other glaring mistakes then let me know. I am no expert when it comes to the Arduino.
Thank you!
Mark
It works for me. Have you installed the Teensy boards URL? Here it is in case you missed that step. Attached is a pic of it working. NOTE IDE has to be at least 2.0.4 or later for Teensy 4.1. I would use IDE 2.3.4 for whatever Teensy you have.
(https://www.pjrc.com/teensy/package_teensy_index.json)
BTW, for future reference, use verbose and post entire error log in code tags just like your code for similar reasons.
Do I do this even if I do not have a teensy board. I have the Arduino Pro Micro or Arduino Micro as it shows in the Arduino IDE. I can do that but was afraid this would cause an issue but I am game to try anything at this point. I can grab the entire code next time. Thanks for taking a look.
Sorry the topic was long winded but tried to explain the end goal of using the Arduino and the code.
The code was for a teensy but stated could be adapted to any board still using the ATmega32u4 microcontroller. I will add the URL and see if that gets me going. I did try to order another arduino board with better compatibility but Amazon has been hit or miss of late on what they can actually deliver when they say. Unfortunately not many or any brick and mortar stores I can walk into to get stuff like this these days. I will let you know momentarily if this gets me going. I will feel dense for not doing this.
There is no such thing as an Arduino Pro Micro anymore, that board is now made by SparkFun in 3 flavours, an ESP32C3 which has no support for what you need, but the RP2040 and 2350 do have something, but you will be a lot better off with the AT
Here are the 3 Pro Micro boards
Here are the USB choices for the 2040 and 2350 (NOTE these are Raspberry Pi boards but supported under the Arduino IDE as well)
and here are the much richer choices under the Teensy 4.1. Here is the boards URL
https://www.pjrc.com/teensy/package_teensy_index.json
Here is the website of the board maker
https://www.pjrc.com
And these are your choices with this board. This is a VERY powerful, and feature rich board, check out the website for details.
Do what?
BTW, is your board a Mini or Micro? The Arduino Pro Mini is retired. Sparkfun makes Pro Micro in 3 flavours, esp32c3, rp2040 and rp2350. The last two are Pi boards.
I did have to remove the first few lines of code for it to compile. I understand the problem as with my Arduino Micro AVR board selection I do not get those options. I don't think I can select the Teensy AVR board and this work either as how the pins are mapped differ to my understanding. I don't understand how to make this work with what I have. I did try to overnight some digispark ATTINY85 but I am unsure if these are truly a teensy board or not. I did try to buy the exact ones mentioned in the walkthrough teensy 2.0 but those failed to show up twice. My soiree into arduino is proving more challenging than I originally hoped. hacking the original NES Zapper was easier than loading the sketch code into the Arduino. I did break down and buy a NES controller to usb adapter for almost $20 as a fail safe. I want to get duck hunt working on my LCD screen and then try it on my 100" Projector. With the amount of money I have thrown at this I may as well buy the Everdrive flashable cartridge and just play this on the original console and not worry about trying to make a 30+ year old light gun work in the modern era. It has been educational at the very least. I prefer to try and do things on the cheap which usually end up costing almost as much in money and vastly more in time but I don't learn as much just throwing money at the problem. I wonder how tiny of a screen this could work on. I may try it on the entertainment system in my SUV. The clicking of the controller might be a bit much but I saw a video on how to fix that although I saw it as a plus or at least a throw back to how it originally worked so long ago.
Sorry for the rant.
Amazon Listing for the "Pro Micro" I bought
This actually shows up as an Arduino Micro when connected to Arduino IDE 2.3.4
I will try to see if this behaves any differently now that I have added the teensy boards
I tried to Upload it by manually selecting teensy 4.1 but got this message in the output
Memory Usage on Teensy 4.1:
FLASH: code:9620, data:4152, headers:8752 free for files:8103940
RAM1: variables:5696, code:6928, padding:25840 free for local variables:485824
RAM2: variables:1312 free for malloc/new:522976
Teensy should be selected from "teensy ports" rather
than "Serial ports" in Arduino's Tools > Port menuNo Teensy boards were found on any USB ports of your computer.
Please press the PROGRAM MODE BUTTON on your Teensy to upload your sketch.
Not sure if that is considered code or not but got warned last time I pasted my sketch
Arduino 2.3.4 says this board is an Arduino Micro. I am unsure how or if this will be able to do what I am trying to do with it. I got three of them but I may try and return them as these were obviously not correctly labeled from the Amazon description. At a loss on how to make this work. There is likely a way but I don't think it will be easy.
I also do not have a program button to press.
I can't try to compile your OP code as I don't have the Joystick.h file (and library) If you want me to try, give me a link to the library.
they did not give me a link to the library for Joystick as this is handled differently with a teensy or digispark board but I will send you the Joystick Library I was trying to use.
GitHub Repository
Link to Library
Link I used to MOD the Zapper and where I got the sketch
I really appreciate your help!
Mark
Board Pinout
I did find this and they all it a Pro Micro but I am at a loss. This does look like my board. This is Why I was trying to use or Map Pin 2 as D1 and Pin 3 as D0 the led was very confusing and although it would be nice if I cannot control the LED I can live with that. I do have this wired up complete with 4.7k ohm resistor. I carried out a separate mod to the light sensing diode board in the NES Zapper but that should not matter to the Arduino.
Sorry, the Joystick library is dependent on other libraries and I don't have time right now to track all that down. Since the only board that will work is the Teeny4.1 and it is out of stock at least until the other company that is now selling them has inventory, I have other things to do. Good luck.
Thanks anyways. I will try the Attiny85 that is supposed to be here in an hour or 2. It is not a teensy but they had a video on it as Alexey in that video ised a digispark. Hopefully that works. If not I will try the USB to NES Controller adapter that should be here on Saturday. One way or another I will get this to work.
Do you have the missing libraries? Changing boards won't help if your sketch is bad. Have you ever got a clean compile?
So the attiny85 digispark boards are a whole different animal but I managed to get my code to compile but I had to hack my way through creating my own library as the one I needed was deprecated. There might be an easier way to do this but I managed to get my code to compile and also written to the Attiny85 board. I now plan to do the soldering part.
#include <DigiJoystick.h>
// Digispark Light Gun
// by r57zone
const int buttonPin = 0;
const int lightPin = 2;
byte buttons;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(lightPin, INPUT_PULLUP);
DigiJoystick.setX((byte)127);
DigiJoystick.setY((byte)127);
}
void loop() {
buttons = 0x00;
if (digitalRead(buttonPin))
buttons |= 0x01;
if (digitalRead(lightPin))
buttons |= 0x02;
DigiJoystick.setButtons((byte)buttons, 0x00);
DigiJoystick.update();
}
to hack the DigiJoystick.h library i found it but was not sure how to add it properly and it was deprecated. but this is what the code was written for. I took the newer library called ArduinoJoystickLibrary-master.zip and put the older stuff I had to painstakingly download 1 file at a time from this github Repository
Once I got it so I could include the library by adding a zip file I got a slew of error but they were mainly asking me to put a const in front of my of my variable and integers in my DigiJostick.h, usbdrv.c, and usbdrv.h files. this took some time to figure out but once it was all done. I got it to compile successfully. These attiny85 are weird you have to click upload then plug it in within a few seconds. Now when I plug it in it registers as a DigiKey which is what it is supposed to do. Cheers! This pushed my comfort level but now to go fire up the soldering iron and see if I can get this gun working tonight. I might save the soldering for tomorrow as I am wore out and I will solder better when fresh. I might see about creating my own github but all this code was someone else's code. I just had to tweak it a little. My understanding is it is all in the Creative commons lic. I will take a closer look at that tomorrow.