All right, so a few days and a lot of reading about i2c later, I came up with a simple code to read the basic inputs of the NES controller. Thanks to Andyroo for the starting place.
For anybody interested here's the code:
import time
from smbus import SMBus
address = 0x52
class nes:
def __init__(self,delay = 0.05):
i2c_bus = 1
self.delay = delay
self.bus = SMBus(i2c_bus)
time.sleep(1)
self.bus.write_byte_data(address,0x40,0x00)
def raw(self):
time.sleep(self.delay)
data = self.bus.read_i2c_block_data(address, 0, 6)
time.sleep(self.delay)
return data
def read(self, key = 0, name = ""):
data = self.raw()
a = data[4]
b = data[5]
if a == 255 and b == 255:
key = 0
name = "none"
elif a == 255 and b == 254:
key = 1
name = "up_arrow"
elif a == 191 and b == 255:
key = 2
name = "down_arrow"
elif a == 255 and b == 253:
key = 3
name = ("left_arrow")
elif a == 127 and b == 255:
key = 4
name = ("right_arrow")
elif a == 239 and b == 255:
key = 5
name = ("select")
elif a == 251 and b == 255:
key = 6
name = ("start")
elif a == 255 and b == 191:
key = 7
name = ("b")
elif a == 255 and b == 239:
key = 8
name = ("a")
elif a == 63 and b == 252:
key = 9
name = ("full_arrow")
else:
key = 100
name = ("unregistered")
return key, name