How to avoid getting invalid argument when controlling joystick with smbus library

79 Views Asked by At

I am trying to control a 5 pin joystick with raspberry pi the code is attached however when I run this I get an error does anyone know how to resolve this issue?

I expected it to show me the position of the joystick when pushed i tried checking for typos and things that didn't make sense nothing worked

from signal import signal, SIGTERM, SIGHUP, pause
from smbus import SMBus
from time import sleep
from math import log10

bus = SMBus(1)
ads7830_commands = (0x84, 0xc4, 0x94, 0xd4, 0xa4, 0xe4, 0xb4, 0xf4)

def safe_exit(signum, frame):
    exit(1)

def read_ads7830(input):
    bus.write_byte(0xb4, ads7830_commands[input])
    return bus.read_byte(0x4b)


signal(SIGTERM, safe_exit)
signal(SIGHUP, safe_exit)

try:
    while True:
        print(f"x: {read_ads7830(7)}, Y: {read_ads7830(6)}")

        sleep(0.1)
    pause()

except KeyboardInterrupt:
    pass
0

There are 0 best solutions below