Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GPIO...
#11
i'm not used db9, my schematic is very simple. see attachments.
 all your buttons are defined in "start - config. input"?
I did so - started - genesis (retroarch) - ran the menu - options - input - where there is an item there - input 1 (or 2) bind config (or something, my OP is temporarily unavailable, I can precisely name this menu a little later) - bind all - in this config you can reassign your buttons and see their real code for retroarchy - after that I saved my shared config under a different name - cut out part of it with joystick buttons (input_player1_b_btn = "3" ........) and inserted it into the original retroarch.cfg
-----
for using this schematic, you need modify python script, and .fex file on the SD\emmc card.
---
I will update the instruction if it does not work


Attached Files Thumbnail(s)
   
Reply
#12
Ok thanks a lot, I'll give a try tomorrow (it's a little late here).

But one thing I realized is that the diagram for tzgames driver here:
https://github.com/retr0rangepi/RetrOran.../README.md

...does not fit at all with what I have on my pi pc.

I tested every GPIO pin manually in ES and I get these GPIO pin numbers for controller one: 3 - 8 - 10 - 12 - 16 - 18 - 19 - 21 - 22 - 27

And for controller two: 5 - 24 - 26 - 28 - 32 - 35 - 36 -37 - 38 - 40


- So number 7 11 13 and 15 gives me no input (suppose to be controller one on the diagram).
- Same for 23 29 31 and 33  (suppose to be controller two on the diagram)


Is there an updated diagram for retrorangepi?
Reply
#13
if we are talking about the same thing about what you want to use the tz_gamers driver, here are your steps:
Look at the green contacts.
- go to the desktop, label retropy
- / home / pi / RetroPie / retropiemenu / RetrOrangePi / GPIO / drivers
- open the file: tz_gpio_controller.py
- modify it according to the connected contacts.
- the most important thing. some gpio conclusions are occupied by the periphery (comport, spi, twi, etc). On the desktop there is a config - open it - find the item -system - fexedit - in this config, find:

[uart3]
used=1
...
...
if you see that uart3 uses your gpio contacts, post used = 0
I see according to the picture for example, that uart2 on your board uses gpio contacts: PA0, 1, 2, 3. Put it in used = 0. And so on.
(I think you can safely turn off: twi0, uart1, uart2, uart3, on your board)
Do not turn off what is not sure and what is not in the GPIO table of contacts.

- you should use pull-up resistors according to my scheme

Here is my file, I remove gamepad 2 and many buttons:
Code:
#!/usr/bin/env python


__author__ = "Erick Tarzia"
__copyright__ = "Copyright 2016, TZ Games SP"
__credits__ = ["Erick Tarzia - tzgamessp.com.br"]
__v__  = "1.0"
__license__ = "GPL"
__version__ = "2.0"
__maintainer__ = __author__
__email__ = "ericktarzia@gmail.com"


import evdev
import uinput
from time import sleep
from evdev import InputDevice, KeyEvent, UInput, AbsInfo, ecodes as e
from pyA20.gpio import gpio
from pyA20.gpio import port
from pyA20.gpio import connector

#sleep(10)

events = ([
        uinput.BTN_JOYSTICK,
        uinput.BTN_0,
        uinput.BTN_1,
        uinput.BTN_2,
        uinput.BTN_3,
        uinput.BTN_4,
        uinput.BTN_5,
        uinput.BTN_6,
        uinput.BTN_7,
        uinput.BTN_8,
        uinput.ABS_X + (0,255,0,0),
        uinput.ABS_Y + (0,255,0,0),
    ])

gamepad = uinput.Device(events,"TZGamesSP Controle #1",0x00)

gamepad.emit(uinput.ABS_X, 128, syn=False)
gamepad.emit(uinput.ABS_Y, 128)
#print device1.capabilities()
'''
devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()]
for device in devices:
    print(device.fn, device.name, device.phys)
    if device.name == "TZ Arcade Joystick 0":
        gamepad = InputDevice(device.fn)
    if device.name == "TZ Arcade Joystick 1":
        gamepad2 = InputDevice(device.fn)
    
'''
#--------------- define botoes -----------------
    # ---- PLAYER 1 ---------#  

                    # <---LOOK!

bt_up_p1 = port.PA6
bt_down_p1 = port.PA12
bt_left_p1 = port.PA11
bt_right_p1 = port.PA14

bt_l_p1 = port.PA0

bt_x_p1 = port.PA3
bt_y_p1 = port.PA1

bt_r_p1 = port.PA7

bt_b_p1 = port.PA13
bt_a_p1 = port.PA2

bt_select_p1 = port.PA18
bt_start_p1 = port.PA19


#--------------------------------Initialize module. Always called first
gpio.init()

gpio.setcfg(bt_up_p1, gpio.INPUT)
gpio.pullup(bt_up_p1, gpio.PULLUP)

gpio.setcfg(bt_down_p1, gpio.INPUT)
gpio.pullup(bt_down_p1, gpio.PULLUP)

gpio.setcfg(bt_left_p1, gpio.INPUT)
gpio.pullup(bt_left_p1, gpio.PULLUP)

gpio.setcfg(bt_right_p1, gpio.INPUT)
gpio.pullup(bt_right_p1, gpio.PULLUP)


gpio.setcfg(bt_l_p1, gpio.INPUT)
gpio.pullup(bt_l_p1, gpio.PULLUP)

gpio.setcfg(bt_x_p1, gpio.INPUT)
gpio.pullup(bt_x_p1, gpio.PULLUP)

gpio.setcfg(bt_y_p1, gpio.INPUT)
gpio.pullup(bt_y_p1, gpio.PULLUP)

gpio.setcfg(bt_r_p1, gpio.INPUT)
gpio.pullup(bt_r_p1, gpio.PULLUP)

gpio.setcfg(bt_b_p1, gpio.INPUT)
gpio.pullup(bt_b_p1, gpio.PULLUP)

gpio.setcfg(bt_a_p1, gpio.INPUT)
gpio.pullup(bt_a_p1, gpio.PULLUP)

gpio.setcfg(bt_select_p1, gpio.INPUT)
gpio.pullup(bt_select_p1, gpio.PULLUP)

gpio.setcfg(bt_start_p1, gpio.INPUT)
gpio.pullup(bt_start_p1, gpio.PULLUP)

    
_bt_up_p1 = False
_bt_down_p1 = False
_bt_left_p1 = False
_bt_right_p1 = False
_bt_a_p1 = False
_bt_b_p1 = False
_bt_x_p1 = False
_bt_y_p1 = False
_bt_l_p1 = False
_bt_r_p1 = False
_bt_select_p1 = False
_bt_start_p1 = False

print gpio.input(bt_a_p1)

while True:
    #------ player 1 -----------#        
#bt a =====================
    if (not _bt_a_p1) and (gpio.input(bt_a_p1) == 0):
        _bt_a_p1 = True
        gamepad.emit(uinput.BTN_0, 1)    
    if (_bt_a_p1) and (gpio.input(bt_a_p1) == 1):
        _bt_a_p1 = False
        gamepad.emit(uinput.BTN_0, 0)    
#bt b =====================

    if (not _bt_b_p1) and (gpio.input(bt_b_p1) == 0):
        _bt_b_p1 = True
        gamepad.emit(uinput.BTN_1, 1)    
    if (_bt_b_p1) and (gpio.input(bt_b_p1) == 1):
        _bt_b_p1 = False
        gamepad.emit(uinput.BTN_1, 0)    

#bt x =====================

    if (not _bt_x_p1) and (gpio.input(bt_x_p1) == 0):
        _bt_x_p1 = True
        gamepad.emit(uinput.BTN_2, 1)    
    if (_bt_x_p1) and (gpio.input(bt_x_p1) == 1):
        _bt_x_p1 = False
        gamepad.emit(uinput.BTN_2, 0)    
#bt y =====================

    if (not _bt_y_p1) and (gpio.input(bt_y_p1) == 0):
        _bt_y_p1 = True
        gamepad.emit(uinput.BTN_3, 1)    
    if (_bt_y_p1) and (gpio.input(bt_y_p1) == 1):
        _bt_y_p1 = False
        gamepad.emit(uinput.BTN_3, 0)    
#bt l =====================
    if (not _bt_l_p1) and (gpio.input(bt_l_p1) == 0):
        _bt_l_p1 = True
        gamepad.emit(uinput.BTN_4, 1)    
    if (_bt_l_p1) and (gpio.input(bt_l_p1) == 1):
        _bt_l_p1 = False
        gamepad.emit(uinput.BTN_4, 0)    
#bt r =====================
    if (not _bt_r_p1) and (gpio.input(bt_r_p1) == 0):
        _bt_r_p1 = True
        gamepad.emit(uinput.BTN_5, 1)    
    if (_bt_r_p1) and (gpio.input(bt_r_p1) == 1):
        _bt_r_p1 = False
        gamepad.emit(uinput.BTN_5, 0)
#bt select =====================
    if (not _bt_select_p1) and (gpio.input(bt_select_p1) == 0):
        _bt_select_p1 = True
        gamepad.emit(uinput.BTN_6, 1)    
    if (_bt_select_p1) and (gpio.input(bt_select_p1) == 1):
        _bt_select_p1 = False
        gamepad.emit(uinput.BTN_6, 0)    
#bt start =====================
    if (not _bt_start_p1) and (gpio.input(bt_start_p1) == 0):
        _bt_start_p1 = True
        gamepad.emit(uinput.BTN_7, 1)    
    if (_bt_start_p1) and (gpio.input(bt_start_p1) == 1):
        _bt_start_p1 = False
        gamepad.emit(uinput.BTN_7, 0)
####DIRECTIONS P1 ###########################

#bt up =====================
    if (not _bt_up_p1) and (gpio.input(bt_up_p1) == 0):
        _bt_up_p1 = True
        gamepad.emit(uinput.ABS_Y, 0)    
    if (_bt_up_p1) and (gpio.input(bt_up_p1) == 1):
        _bt_up_p1 = False
        gamepad.emit(uinput.ABS_Y, 128)
#bt down =====================
    if (not _bt_down_p1) and (gpio.input(bt_down_p1) == 0):
        _bt_down_p1 = True
        gamepad.emit(uinput.ABS_Y, 255)    
    if (_bt_down_p1) and (gpio.input(bt_down_p1) == 1):
        _bt_down_p1 = False
        gamepad.emit(uinput.ABS_Y, 128)
#bt left =====================
    if (not _bt_left_p1) and (gpio.input(bt_left_p1) == 0):
        _bt_left_p1 = True
        gamepad.emit(uinput.ABS_X, 0)    
    if (_bt_left_p1) and (gpio.input(bt_left_p1) == 1):
        _bt_left_p1 = False
        gamepad.emit(uinput.ABS_X, 128)
#bt right =====================
    if (not _bt_right_p1) and (gpio.input(bt_right_p1) == 0):
        _bt_right_p1 = True
        gamepad.emit(uinput.ABS_X, 255)    
    if (_bt_right_p1) and (gpio.input(bt_right_p1) == 1):
        _bt_right_p1 = False
        gamepad.emit(uinput.ABS_X, 128)
    

    sleep(.02)

to test the script and the correctness of the GPIO instruction - go to the root terminal:

cd /home/pi/RetroPie/retropiemenu/RetrOrangePi/GPIO/drivers

python tz_gpio_controller.py start

you should see "1" in the console, or an error if gpio is not correctly installed

------------------
I also looked at nes_controller.py, there are used:
PIN_DATA1 = port.PA12
PIN_DATA2 = port.PA11
PIN_DATA3 = port.PA6
PIN_DATA4 = port.PG7

PIN_CLOCK = port.PA9
PIN_LATCH = port.PA20

if these ports are busy in the * .fex file, free them.
------------------ off topic------------------------------------
I think, once this script tz_gpio_cobtroller turns in memory and works well it can be modified to exit roms \ off and other functions, blinking LED?)). I'm not strong in the python, especially in its syntax and especially in Linux. This should be something like this:

import os
....
# check my buttons, for example this button
if (not _bt_a_p1) and (gpio.input (bt_a_p1) == 0):
_bt_a_p1 = True
gamepad.emit (uinput.BTN_0, 1)
...

if gamepad.emit (uinput.BTN_0, 1) = True
os.popen ("./ test.sh 1")
....

I think the script in the loop should keep track of how the process is now running, retroarch or dosbox or any other emulator, and at the push of a button perform an output in ES, as an example.


Attached Files Thumbnail(s)
   
Reply
#14
Lightbulb 
Thanks for your crystal clear explications, @indevor. It did help me to understand the inner working of the GPIO and I am sure it will help some others as well.

I finally get it to work using the diagram I made in attachment. And since I only want to use my GPIO joysticks for commodore 64 and that I have to remap the joystick in the emulator anyway, it ends up working pretty well while the mapping settings are being save for the next session. So I finally don't have the problem you have mentioned the first post. BTtW a big shout out to the TZ games driver creator!!

After all, basic games are meant to be played with basic joysticks...Cool

           


Attached Files Thumbnail(s)
   
Reply
#15
Great, I'm glad it helped you!
I hope other participants will find it useful!
---
You have a cool install  Big Grin

I made myself a portable console:
       
Reply
#16
Awesome guys, we will update our documentation, hopefully more people will test this.
Reply
#17
nice console  Smile
I wish I'll manage to do one like this one day...
Reply
#18
Wow, congrat! With hdmi port access as well, nice :-) You designed your own case or took it online (unless it is a real gameboy case)?
Reply
#19
This is a chinese copy of the case from the "game boy" with buttons.
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  RetrOrangePi 4.1 - Orange Pi Zero GPIO - Getting GPIO to work bharathram21391 15 1,499 05-15-2018, 04:58 PM
Last Post: alexkidd
  GPIO (one more time) znoxx 1 335 05-13-2018, 11:39 AM
Last Post: alexkidd
  GPIO config mauricio-ramos 2 667 02-26-2018, 02:34 AM
Last Post: canadien
  Enable GPIO - Failed to fetch Padova 7 1,414 02-15-2018, 10:22 PM
Last Post: alexkidd

Forum Jump:


Users browsing this thread: 1 Guest(s)