If you want to do it the easy way and just for retroarch-emulators, just try
sudo ./Retropie-Setup/retropie_setup.sh
and choose “Register retroarch controller”.
after you configured it, this should be your first gamepad for retroarch-emulators.
If you want to do this for more than one Controller, you’ll have to set the gamepadindexes in the retroarch.cfg:
sudo nano /opt/retropie/configs/all/retroarch.cfg
and then watch out for the lines like
Input_player1_index=0
so you could Change this to the corresponding Controller (I think they’re numbered by the USB-ports they’re plugged in at boot, so left upper is 0, left downer is 1, right upper 2 and right downer 3).