diff --git a/README.rst b/README.rst index f454b62..34f9a12 100644 --- a/README.rst +++ b/README.rst @@ -157,6 +157,24 @@ Usage Example # use QwiicJoystick(i2c, address) for a different address # joystick = QwiicJoystick(i2c, 0x21)""" +Upgrading +========= +On supported GNU/Linux systems like the Raspberry Pi, you can upgrade the driver locally `from +PyPI `_. + +To upgrade for current user: + +.. code-block:: shell + + pip3 install --upgrade sparkfun-circuitpython-qwiicjoystick + +To upgrade system-wide (this may be required in some cases): + +.. code-block:: shell + + sudo pip3 install --upgrade sparkfun-circuitpython-qwiicjoystick + + Contributing ============ diff --git a/examples/qwiicjoystick_simpletest.py b/examples/qwiicjoystick_simpletest.py index 8c2ebd9..b383790 100644 --- a/examples/qwiicjoystick_simpletest.py +++ b/examples/qwiicjoystick_simpletest.py @@ -36,6 +36,7 @@ print("Press Joystick button to exit program.") +# joystick.button goes to 0 when pressed while joystick.button == 1: print("X = " + str(joystick.horizontal) + " Y = " + str(joystick.vertical)) sleep(0.200) # sleep a bit to slow down messages diff --git a/sparkfun_qwiicjoystick.py b/sparkfun_qwiicjoystick.py index 0ff2ad6..ec6a7aa 100644 --- a/sparkfun_qwiicjoystick.py +++ b/sparkfun_qwiicjoystick.py @@ -110,8 +110,12 @@ def __init__(self, i2c, address=QWIIC_JOYSTICK_ADDR, debug=False): @property def connected(self): """True if the Joystick is connected and a valid id is successful read.""" - if self._read_register(_JOYSTICK_ID) != QWIIC_JOYSTICK_ADDR: + try: + # Attempt to read the id and see if we get an error + self._read_register(_JOYSTICK_ID) + except ValueError: return False + return True @property @@ -195,8 +199,11 @@ def set_i2c_address(self, new_address): def _read_register(self, addr): # Read and return a byte from the specified 8-bit register address. with self._device as device: + device.write(bytes([addr & 0xFF])) result = bytearray(1) - device.write_then_readinto(bytes([addr & 0xFF]), result) + device.readinto(result) + # For some reason, write_then_readinto returns invalid data + # device.write_then_readinto(bytes([addr & 0xFF]), result) if self._debug: print("$%02X => %s" % (addr, [hex(i) for i in result])) return result[0]