I have been trying to create a retropie unit, and I'm in the midst of writing a script to inject uinput events for the analog axis values. This is the code I've written so far, but the issue is that I get IOERROR: (Errno 121) Remote I/O error.
When I use the command i2cdetect -y 1, the module shows up at address 0x48.
from evdev import UInput, ecodes as e;
import smbus;
from time import sleep;
def analogRead(pin):
global bus;
return bus.read_byte(0x48+pin);
bus = smbus.SMBus(1);
ui = UInput();
bus.write_byte_data(0x48,0x40 | (0 & 0x03) | (1 & 0x03) | (2 & 0x03), 0 | 1 | 2);
sleep(0.2);
bus.read_byte(0x48);
sleep(0.2);
bus.read_byte(0x49);
sleep(0.2);
bus.read_byte(0x50);
sleep(0.2);
while True:
if analogRead(0) <= 10:
ui.write(e.EV_KEY, e.KEY_S, 0);
ui.write(e.EV_KEY, e.KEY_W, 1);
elif analogRead(0) >= 245:
ui.write(e.EV_KEY, e.KEY_S, 1);
ui.write(e.EV_KEY, e.KEY_W, 0);
else:
ui.write(e.EV_KEY, e.KEY_S, 0);
ui.write(e.EV_KEY, e.KEY_W, 0);
if analogRead(1) <= 10:
ui.write(e.EV_KEY, e.KEY_D, 0);
ui.write(e.EV_KEY, e.KEY_A, 1);
elif analogRead(1) >= 245:
ui.write(e.EV_KEY, e.KEY_D, 1);
ui.write(e.EV_KEY, e.KEY_A, 0);
else:
ui.write(e.EV_KEY, e.KEY_D, 0);
ui.write(e.EV_KEY, e.KEY_A, 0);
EDIT: This issue occurs every time I attempt to run the python script.
The goal is to use a single pcf8591, and read three separate inputs: y-axis, x-axis, and the button press.
REVISED CODE:
from evdev import UInput, ecodes as e;
import smbus;
from time import sleep;
bus = smbus.SMBus(1);
ui = UInput();
bus.read_byte(0x48);
The revised, smaller sample, allows me to get a value of 128, which I assume references the first analog output, the y-axis. How can I access the other two analog inputs( button and x-axis )? I tried to increment the address by one to 0x49, but that is what produces my IOERROR.