Skip to content

Commit 4a57a0a

Browse files
committed
Updated readme file
1 parent a6dabd0 commit 4a57a0a

File tree

2 files changed

+70
-8
lines changed

2 files changed

+70
-8
lines changed

README.rst

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ Introduction
1313
:target: https://travis-ci.org/fourstix/Sparkfun_CircuitPython_QwiicJoystick
1414
:alt: Build Status
1515

16-
CircuitPython library for Sparkfun Qwiic Joystick
16+
CircuitPython library for Sparkfun Qwiic Joystick. This library is ported from the
17+
`SparkFun Qwiic Joystick Arduino Library <https://github.com/sparkfun/SparkFun_Qwiic_Joystick_Arduino_Library>`_
1718

1819
.. image:: https://cdn.sparkfun.com/assets/parts/1/3/5/5/8/15168-SparkFun_Qwiic_Joystick-01.jpg
1920
:target: https://www.sparkfun.com/products/15168
@@ -35,10 +36,46 @@ Please ensure all dependencies are available on the CircuitPython filesystem.
3536
This is easily achieved by downloading
3637
`the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_.
3738

39+
Raspberry Pi Setup
40+
------------------
41+
Adafruit has an excellent tutorial on this:
42+
`Installing CircuitPython Libraries on Raspberry Pi
43+
<https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/installing-circuitpython-on-raspberry-pi/>`_.
44+
45+
Quick Start Summary:
46+
* Start with the latest version of Raspbian with Wifi configured.
47+
* Enable SSH, I2C and SPI.
48+
.. code-block:: shell
49+
50+
sudo raspi-config
51+
52+
* Update your system to the latest version.
53+
.. code-block:: shell
54+
55+
sudo apt-get update
56+
sudo apt-get upgrade
57+
58+
* Update the python tools
59+
.. code-block:: shell
60+
61+
sudo pip3 install --upgrade setuptools
62+
(If pip3 is not installed, install it and rerun the command)
63+
.. code-block:: shell
64+
sudo apt-get install python3-pip
65+
* Install the CircuitPython libraries
66+
.. code-block:: shell
67+
68+
pip3 install RPI.GPIO
69+
pip3 install adafruit-blinka
70+
pip3 install
71+
72+
3873
Installing from PyPI
3974
--------------------
4075
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
4176
PyPI <https://pypi.org/project/sparkfun-circuitpython-qwiicjoystick/>`_. To install for current user:
77+
Installing this library will also install the dependency adafruit-circuitpython-busdevice.
78+
4279

4380
.. code-block:: shell
4481
@@ -63,6 +100,19 @@ Usage Example
63100
=============
64101
* `Qwiic Joystick Hookup Guide <https://learn.sparkfun.com/tutorials/qwiic-joystick-hoookup-guide>`_ - The Arduino examples in the Hookup Guide are available for Python with this library
65102
* `CircuitPython on a Raspberry Pi <https://learn.adafruit.com/circuitpython-on-raspberrypi-linux>`_ - Basic information on how to install CircuitPython on a Raspberry Pi.
103+
* Example:
104+
.. code-block:: shell
105+
106+
# import the CircuitPython board and busio libraries
107+
import board
108+
import busio
109+
110+
# Create bus object using the board's I2C port
111+
i2c = busio.I2C(board.SCL, board.SDA)
112+
113+
joystick = QwiicJoystick(i2c) # default address is 0x20
114+
# use QwiicJoystick(i2c, address) for a different address
115+
# joystick = QwiicJoystick(i2c, 0x21)"""
66116
67117
Contributing
68118
============

sparkfun_qwiicjoystick.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,19 @@
7676

7777
# class
7878
class Sparkfun_QwiicJoystick:
79-
"""CircuitPython class for the Sparkfun QwiicJoystick"""
79+
"""CircuitPython class for the Sparkfun QwiicJoystick
80+
Usage:
81+
# import the CircuitPython board and busio libraries
82+
import board
83+
import busio
84+
85+
# Create bus object using the board's I2C port
86+
i2c = busio.I2C(board.SCL, board.SDA)
87+
88+
joystick = QwiicJoystick(i2c) # default address is 0x20
89+
# use QwiicJoystick(i2c, address) for a different address
90+
# joystick = QwiicJoystick(i2c, 0x21)"""
91+
8092

8193
def __init__(self, i2c, address=QWIIC_JOYSTICK_ADDR, debug=False):
8294
"""Initialize Qwiic Joystick for i2c communication."""
@@ -89,21 +101,21 @@ def __init__(self, i2c, address=QWIIC_JOYSTICK_ADDR, debug=False):
89101

90102
@property
91103
def connected(self):
92-
"""Check the id of Joystick. Returns True if successful."""
104+
"""True if the Joystick is connected and a valid id is successful read."""
93105
if self._read_register(_JOYSTICK_ID) != QWIIC_JOYSTICK_ADDR:
94106
return False
95107
return True
96108

97109
@property
98110
def version(self):
99-
"""Return the version string for the Joystick firmware."""
111+
"""Firmware version string for joystick."""
100112
major = self._read_register(_JOYSTICK_VERSION1)
101113
minor = self._read_register(_JOYSTICK_VERSION2)
102114
return 'v' + str(major) + '.' + str(minor)
103115

104116
@property
105117
def horizontal(self):
106-
"""Return the X value 0 - 1023 of the joystick postion."""
118+
"""X value from 0 - 1023 of the joystick postion."""
107119
# Read MSB for horizontal joystick position
108120
x_msb = self._read_register(_JOYSTICK_X_MSB)
109121
# Read LSB for horizontal joystick position
@@ -115,7 +127,7 @@ def horizontal(self):
115127

116128
@property
117129
def vertical(self):
118-
"""Return the Y value 0 to 1023 of the joystick postion."""
130+
"""Y value from 0 to 1023 of the joystick postion."""
119131
# Read MSB for veritical joystick position
120132
y_msb = self._read_register(_JOYSTICK_Y_MSB)
121133
# Read LSB for vertical joystick position
@@ -127,14 +139,14 @@ def vertical(self):
127139

128140
@property
129141
def button(self):
130-
"""Return 0 if button is down, 1 if up."""
142+
"""0 if button is down, 1 if button is up."""
131143
button = self._read_register(_JOYSTICK_BUTTON)
132144
return button
133145

134146
# Issue: register 0x08 always contains 1 for some reason, even when cleared
135147
@property
136148
def button_status(self):
137-
"""Return 1 if button pressed between reads. Button status is cleared."""
149+
"""1 if button pressed between reads, cleared after read."""
138150
#read button status (since last check)
139151
status = self._read_register(_JOYSTICK_STATUS)
140152
#clear button status

0 commit comments

Comments
 (0)