Recalbox Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • recalbox.com
    • Gitlab repository
    • Documentation
    • Discord

    GPIO ONOFF Powerswitch / Resetbutton Problem

    GamePad/GPIO/USB encoder
    gpio onoff powerswitch resetbutton
    5
    35
    10920
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • lackyluuk
      lackyluuk Translator last edited by

      @unik314r On my second build I also have no ON OFF RESET scripts active but the RPi still reboots if I try to plug in a USB controller..
      Not sure what it causes there.

      NintendoRS | Nintendo Adapter Box | Cardboard Recalbox

      unik314r 1 Reply Last reply Reply Quote 0
      • unik314r
        unik314r @lackyluuk last edited by

        @lackyluuk Indeed... Well, I don't know ^^

        1 Reply Last reply Reply Quote 0
        • megakoni
          megakoni last edited by

          well if they are really working on it right now, that would be so great. This would make my build almost perfect. I'm looking forward to it, especially now that the updates are more frequent

          1 Reply Last reply Reply Quote 0
          • lackyluuk
            lackyluuk Translator last edited by

            @megakoni @unik314r
            This issue does not seem to be recalbox related. Obviously if you plug in a USB device it causes a sudden pike in current demand to turn the usb device on and due to this the supply current drops and this is like plugging the RPi out and back in.
            Please try a USB extension cable. This could solve your problem because of the extra resistance of the cable to reduce the current pike.

            https://raspberrypi.stackexchange.com/questions/3634/raspberry-pi-reboots-on-plugging-in-a-usb-device

            NintendoRS | Nintendo Adapter Box | Cardboard Recalbox

            megakoni 1 Reply Last reply Reply Quote 0
            • megakoni
              megakoni @lackyluuk last edited by megakoni

              @lackyluuk ok i try to connect an usb extension cable between my usb hub and the pi (because the hub is already glued into place), i hope that works, thanks,

              But what if i enable higher current for the usb outputs? wouldn't that avoid the sudden pike, because the needed current is there? I saw somewhere a function to enable it in the config file.

              EDIT: Ok unfortunately the max_usb_current=1 command didn't change a thing. so i just buy one usb extension for between the hub and the pi. I report back after trying

              1 Reply Last reply Reply Quote 0
              • lackyluuk
                lackyluuk Translator last edited by lackyluuk

                @megakoni Is your hub powered by the USB port or does it have a seperate supply? This could help as well.

                There is a fuse which regulates the current to the pi. So it does not matter if you enable more current I think

                NintendoRS | Nintendo Adapter Box | Cardboard Recalbox

                1 Reply Last reply Reply Quote 0
                • megakoni
                  megakoni last edited by

                  @lackyluuk it's powered by the usb. I think it has a port for a seperate power supply but can't find any fitting cable for that. I try to find out what type of cable i need and if the usb extension doesn't fix this i hope that i can find the cable to buy.

                  1 Reply Last reply Reply Quote 0
                  • megakoni
                    megakoni last edited by

                    so i bought the cables, and unfortunately they didn't help. Bought one 1 meter long one and one cheap and short . Even used both together, no luck.
                    And even without using any hub, plugging in something into the original usb ports of the pi also triggers a shutdown.
                    Hell even when i plug another device (tried my ps4) to the power supply extension they both share, it shuts down xD

                    for the hub i couldn't find a fitting power supply, but i think it wouldn't change anything anyway.

                    Thanks for the help anyway, i'll have to avoid this issue by plugging in before booting and just live with that.
                    Even if its not recalbox related, maybe they can solve this some day. I mean only the shutdown command comes from recalbox, it's just the signals that are interfered with that current pike. Ignoring micro short signals (maybe) could help.

                    supernature2k 1 Reply Last reply Reply Quote 0
                    • supernature2k
                      supernature2k @megakoni last edited by

                      @megakoni

                      Hi, this is a known problem. A timer has been added to the script (need to push button for more than 1 second).

                      This script should be updated in next release.

                      Pi powered NES | Gameboy HD | RecalStation | RecalDrive
                      Upvote messages if it has been useful ;)

                      megakoni 1 Reply Last reply Reply Quote 0
                      • megakoni
                        megakoni @supernature2k last edited by

                        @supernature2k does this fix on/off switches too? Or just the momentary button (in my case reset)?

                        1 Reply Last reply Reply Quote 0
                        • lackyluuk
                          lackyluuk Translator last edited by

                          @megakoni Sad to hear that it does not work..
                          Are you sure it's a recalbox command which triggers the reboot? Maybe it's a RPi function to shutdown/reboot if VCC drops a certain level? I don't know..
                          Because my shutdown / reboot scripts are not active

                          NintendoRS | Nintendo Adapter Box | Cardboard Recalbox

                          megakoni 1 Reply Last reply Reply Quote 0
                          • megakoni
                            megakoni @lackyluuk last edited by

                            @lackyluuk well, if i turn off the shutdown and reset scripts provided by the recalbox config, that issue dissappears. But i still want to use these buttons so i just have to wait and see if the next update can fix it

                            supernature2k 1 Reply Last reply Reply Quote 0
                            • supernature2k
                              supernature2k @megakoni last edited by

                              @megakoni here is the script if you want to test:

                              import RPi.GPIO as GPIO
                              import time
                              import os
                              import thread
                              import datetime
                              import socket
                              import sys
                              import argpa**e
                              from datetime import datetime
                              from configgen import recalboxFiles
                              # this last one retrieves emulators bin names
                              
                              pa**er = argpa**e.ArgumentPa**er(description='power manager')
                              pa**er.add_argument("-m", help="mode onoff or push", type=str, required=True)
                              args = pa**er.pa**e_args()
                              
                              mode = args.m
                              
                              IPADDR = "127.0.0.1"
                              PORTNUM = 55355
                              # IP and port for retroarch network commands
                              
                              POWERPLUS = 3
                              RESETPLUS = 2
                              LED = 14
                              
                              GPIO.setwarnings(False)		# no warnings
                              GPIO.setmode(GPIO.BCM)		# set up BCM GPIO numbering 
                               
                              GPIO.setup(RESETPLUS, GPIO.IN, pull_up_down=GPIO.PUD_UP)
                              # GPIO on pin 3 is the GPIO 2 in BCM mode
                              #to Reset+
                              
                              GPIO.setup(POWERPLUS, GPIO.IN, pull_up_down=GPIO.PUD_UP)
                              # GPIO on pin 5 is the GPIO 3 in BCM mode
                              #to Power+
                              
                              GPIO.setup(LED, GPIO.OUT)
                              GPIO.output(LED, True)
                              # GPIO on pin 8 is the GPIO 14 in BCM mode
                              #to LED+
                              
                                
                              # Define a threaded callback function to run in another thread when events are detected  
                              def button_pressed(channel):
                              	if channel == POWERPLUS:
                              		speed=0.15
                              		shutdownstring="shutdown -h now"
                              		nwcommand="QUIT"
                              		
                              	elif channel == RESETPLUS:
                              		speed=0.05
                              		shutdownstring="shutdown -r now"
                              		nwcommand="RESET"
                              		
                              	timer = 0
                              	flag = True
                              	while flag:
                              		if GPIO.input(channel) == False:
                              			timer += 1
                              			print "Button pressed"
                              		elif GPIO.input(channel) == True:
                              		
                              			print "Button released"
                              			print timer
                              		
                              			#timer adds 1 each 0.1 seconds if timer = 10, button is pressed for 1s
                              			if (timer > 10):
                              				offreset(speed, shutdownstring)
                              				print "shutdown"
                              			elif (timer >1):
                              				retroarch(nwcommand)
                              				print "retroarch"
                              				killthats**t(channel)
                              				
                              			timer = 0
                              			flag = False
                              		time.sleep(0.1)
                              		
                              	
                              #	on power short press, trying to kill all listed emus 
                              def killthats**t(channel):
                              	if channel == POWERPLUS:
                              		for bin in recalboxFiles.recalboxBins:
                              				print bin
                              				proc = os.path.basename(bin)
                              				print proc
                              				os.system("killall -9 "+proc)
                              
                              # 	on long button press clean stop	of ES then shutdown -h or -r		
                              def offreset(speed, shutdownstring):
                              	thread.start_new_thread( blink, (speed, ))
                              	flag=True
                              	pids = [pid for pid in os.listdir('/proc') if pid.isdigit()]
                              	os.system("/etc/init.d/S31emulationstation stop")
                              	while flag:
                              		flag = False
                              		for pid in pids:
                              				try:
                              					print pid
                              					commandpath = open(os.path.join('/proc', pid, 'cmdline'), 'rb').read()
                              					if "emulationstation" in commandpath:
                              						flag = True
                              				except IOError:
                              					continue
                              	os.system(shutdownstring)
                              
                              # threaded blinking function for LED	
                              def blink(speed):
                              	while True:  
                              			GPIO.output(LED, False)
                              			time.sleep(speed)
                              			GPIO.output(LED, True)
                              			time.sleep(speed)
                              
                              
                              # 	sending network command to retroarch (only exit and reset atm)		
                              def retroarch(nwcommand):
                              	try:
                              		s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
                              	except socket.error:
                              		print 'Failed to create socket'
                              		sys.exit()
                              	s.sendto(nwcommand, (IPADDR, PORTNUM))
                              		
                              
                              GPIO.add_event_detect(RESETPLUS, GPIO.BOTH, callback=button_pressed, bouncetime=2)
                              GPIO.add_event_detect(POWERPLUS, GPIO.BOTH, callback=button_pressed, bouncetime=2)
                              while True:
                              	time.sleep(0.2)
                              

                              Pi powered NES | Gameboy HD | RecalStation | RecalDrive
                              Upvote messages if it has been useful ;)

                              megakoni 1 Reply Last reply Reply Quote 0
                              • megakoni
                                megakoni @supernature2k last edited by megakoni

                                @supernature2k how do i implement that? I've never done that. Is here a tutorial for that in the forums?
                                And i'm curious about the network commands. Does power/reset only work if my wlan or lan is connected to my network?

                                supernature2k 1 Reply Last reply Reply Quote 0
                                • supernature2k
                                  supernature2k @megakoni last edited by

                                  @megakoni

                                  it works without network as we use the localhost loop (127.0.0.1)

                                  Pi powered NES | Gameboy HD | RecalStation | RecalDrive
                                  Upvote messages if it has been useful ;)

                                  megakoni 2 Replies Last reply Reply Quote 0
                                  • megakoni
                                    megakoni @supernature2k last edited by

                                    @supernature2k
                                    couldn't get the script to work on startup. It just didn't do anything for me. I used this tutorial step by step https://github.com/recalbox/recalbox-os/wiki/Add-your-own-startup-script-(EN)

                                    1 Reply Last reply Reply Quote 0
                                    • megakoni
                                      megakoni @supernature2k last edited by

                                      @supernature2k so i got the new update, but nothing changed. Or is it coming in the next update?
                                      I didn't change the recalbox config, is there a new default one?

                                      supernature2k 1 Reply Last reply Reply Quote 0
                                      • supernature2k
                                        supernature2k @megakoni last edited by

                                        @megakoni what is your issue?

                                        Pi powered NES | Gameboy HD | RecalStation | RecalDrive
                                        Upvote messages if it has been useful ;)

                                        megakoni 1 Reply Last reply Reply Quote 0
                                        • megakoni
                                          megakoni @supernature2k last edited by

                                          @supernature2k i still get the power button triggered with pluging something into usb or audio jack and it shuts down. This only happens when the system.power.switch=PIN356ONOFFRESET script is enabled. So i was wondering if there is a new script for power and reset function since the new update

                                          supernature2k 1 Reply Last reply Reply Quote 0
                                          • supernature2k
                                            supernature2k @megakoni last edited by

                                            @megakoni no sorry, the fix is ready and should be in the next release.
                                            Meanwhile, you can try the script posted above.

                                            Pi powered NES | Gameboy HD | RecalStation | RecalDrive
                                            Upvote messages if it has been useful ;)

                                            megakoni 2 Replies Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Want to support us ?

                                            79
                                            Online

                                            99.6k
                                            Users

                                            28.1k
                                            Topics

                                            187.1k
                                            Posts

                                            Copyright © 2021 recalbox.com