import machine import time # Interfacing a SNES-Controller with Micropython on ESP32 # Clock, Latch, Data, according to # https://gamefaqs.gamespot.com/snes/916396-super-nintendo/faqs/5395 # # Some colors do not match. Mine where # white : 5V # blue : Clock (in website yellow) # yellow : Latch (in webseite orange) # red : Data # brown : GND # # # Wiring: Clock and Latch can be directly connected to the ESP32 # Do not use Pin 12 (used to determine voltage at boot, it seems) # # To connect Data, you must use a level-converter (or a voltage divider # might do the trick # clk = machine.Pin(13, machine.Pin.OUT) clk.value(1) lat = machine.Pin(14, machine.Pin.OUT) lat.value(0) dat = machine.Pin(27, machine.Pin.IN) while True: # Init: Lat for 12us high lat.value(1) time.sleep_us(12) lat.value(0) # Get values time.sleep_us(12) buttons = 0 for b in range(16): clk.value(0) buttons |= ((1-dat.value()) << b) time.sleep_us(6) clk.value(1) time.sleep_us(6) print(bin(buttons)) time.sleep_ms(100)