I assume the Arduino config (or any joypad input config) overrides the retroarch.cfg in some way?
Your configuration in retroarch.cfg - as it is right now - configures a keyboard.input_player1_r = "w"
When configuring a gamepad, the syntax is different:input_player1_r_btn = "12"
RetroArch will load - indeed - the configuration from the autoconfig sub-folder if it finds one. The gamepad's auto-configuration file was generated by EmulationStation when you configured the gamepad in the Input Configuration step.
I find it easier to open up the RetroArch's menu (via Hotkey + X) and use the Controls menu to change things, test them and then save it with a Core input configuration remap.
For more details, see https://retropie.org.uk/docs/RetroArch-Configuration/.