Just another Pi in a NES
-
The Nes draws 895ma, but did you use a Mattel nes? Those are rare :s
-
@k-bert question for you. Did you wire up only the red and yellow "composite"? (not component :) ) i used the white rca jack from the rf on the back as the white left audio when i did my buddies nes.
-
I like what you did with the relais, do you mind sharing us how you did it and what you modified in the code?
-
Sorry, I have been away from home for a bit.
cyperghost - I used a laptop power supply from work that was being thrown out. The regulator is a DE-SWADJ 3A Adjustable Voltage Regulator I had that was destined for a project that never came to be.
XVO - Mattel NES are not rare here. Mattel was the original distributor for the NES in Canada.
edmaul69 - You mean composite and component aren't interchangeable? :-P. I set it up to run as the original NES did, so the red and yellow represent sound and video. As all the ROMs I have loaded are mono I didn't bother making it a stereo system. Unfortunately the RF adapter can not be used in the current set up (and I have no intention of changing that).
XVO - I will share what I did when I get to the computer that the code and circuit diagrams are on. I'm afraid it is clumsy and amateurish, but I have no problem showing what I did.
Cheers,
K-bert -
@k-bert yeah the rf is unuseable so i used the white rca for audio. A lot of flatscreens dont support mono correctly so you only get audio out of one of the speakers. If you want better sound even if its mono i would change that. Also component is "red, blue, green, white, red".
-
Alright so here is what I did. I should have used mosfets instead of relays, but I didn't have any spares kicking around whereas I have many relays left over from Arduino 12 volt projects.
The only part I needed to purchase what the female header for the GPIO connection. The NES controllers are wired up as the Gamecon driver suggests. My board simply connects the GPIO to screw terminals to make connecting the wires trivial.
My goal was to have the power button, the reset button and the LED act as they would on the original NES, but I also needed it to safely shutdown and reboot the Pi. I did this with two python scripts that are called at startup.
There are two relays being used. One is the power control relay. This switches power on and off to the voltage regulator. The other is the power button detect relay.
The power comes from my repurposed laptop power supply through the bridge rectifier. The negative DC output of the rectifier is connected to the ground for everything from here on. The positive output of the rectifier is connected to both relay coils. It is also connected to pin 30 of the power control relay. Pin 87 of the power control relay is connected to the voltage regulator such that when the relay is turned on power from the bridge rectifier is sent to the voltage regulator input. The output of the regulator is set to 5V and is connected to the 5V pins on the GPIO.
The side of the coil that is not connected to the positive output of the rectifier on the power control relay is connected to a NPN transistor as well as to the power switch through a diode. The other side of the power switch is connected to ground. So when the power switch is "on" is grounds the relay through the diode and turns on the relay. Alternatively when the transistor is turned on by applying 3.3V to it it grounds the relay through the transistor's emitter, again turning it on. The base of the relay is connected to GPIO 26 which is set to high in my python script. So as soon as the power button is turned on the relay comes on and provides power to the Pi. The Pi boots and then holds the relay on through the transistor. At this point the power button can be turned off and the Pi will remain on.
The power button detect relay's negative side of the coil is connected directly to the power button. Pin 30 of this relay is connected to GPIO 2. Pin 87a is connected to ground and pin 87 is connected to the Pi's 3.3V output. When the relay is turned on by the power button GPIO 2 is connected to 3.3V or a digital Hi according to the Pi. When the relay is turned off it connects GPIO 2 to ground or a digital Low according to the Pi. My script calls the shutdown routine when GPIO2 detects a falling edge.
I found that GPIO26 would go low before the Pi finished shutting down so I added a capacitor to the circuit to hold the transformer on long enough for the Pi to finish shutting down.
Of course I found out after the fact that there is another pin on the GPIO that goes high when the Pi is on and off after the Pi has shutdown which would have made this simpler, but it was too late for me at this point.
Here is the script that does what I described above:
#!/bin/python
#Simpler script for power controlimport RPi.GPIO as GPIO
import time
import os#Use the Broadcom SOC Pin numbers
#Setup the Pin with the Internal Pullups enabled and PIN in reading mode
GPIO.setmode(GPIO.BCM)
GPIO.setup(2, GPIO.IN, pull_up_down = GPIO.PUD_UP)GPIO.setup(26, GPIO.OUT)
GPIO.output(26, 1)#The function that will execute
def Shutdown(channel):
os.system("sudo shutdown -h now")#Add our function to execute when the event happens
GPIO.add_event_detect(2, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)#Now wait
while 1:
time.sleep(1)Now the other part of the equation is the reset button. I was a little unsure how I was going to tackle this. There is the "run" header that many have claimed is a safe reboot for the Pi. I tried it a few times and although it seemed successful it didn't fill me with confidence about being a safe reboot. So I connected a screw terminal block for the reset switch with one side connected to ground and the other connected to a jumper. One side of the jumper would connect the reset switch to the run header and the other to GPIO17. This way if I am ever convinced that the run jumper is the best way to reset I can set it up to do so. I wrote another script very similar to the shutdown script and have it called at startup as well:
#!/bin/python
#Simple script for rebootimport RPi.GPIO as GPIO
import time
import os#Use the Broadcom SOC Pin numbers
#Setup the Pin with the Internal Pullups enabled and PIN in reading mode
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, pull_up_down = GPIO.PUD_UP)#The function that will execute
def Reboot(channel):
os.system("sudo reboot")#Add our function to execute when the event happens
GPIO.add_event_detect(17, GPIO.FALLING, callback = Reboot, bouncetime = 2000)#Now wait
while 1:
time.sleep(1)There are a few other components on the board in the form of voltage regulator capacitors and kickback diodes on the relays, but that is pretty much it.
Cheers,
K-bert -
Sorry found and error above. Where it says "...base of the relay..." it should be "...base of the transistor..."
-
Awesome, thanks.
-
@k-bert
The "run" header in my opinion is not a safe reboot at all! It's nothing more than a power interrupt.
I am using it for my builds however, but it's only a last resort to reset the Pi if it crashes. I reboot via the RetroPie menu. Wiring it through your GPIO and calling reboot events is a much more elegant way to reboot your Pi. It's just that i wouldn't know how to, or else i would not use the "run" header myself. -
Feel free to use the method I described above to run a reboot button. All you need to do is install python, use the python code above and edit the rc.local file to call the python code at startup.
Cheers,
K-bert
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.