Hi,
I have ported the Qwiic Joystick, Qwiic Relay and Qwiic Twist Arduino libraries to CircuitPython libraries. All the example programs were also ported, so one can follow along the Sparkfun Arduino tutorials and Hookup Guides with a Raspberry Pi using these CircuitPython classes and the python example code.
The Arduino function names were converted to Python following PEP8 style rules. Single value getter/setter methods were converted to Python class properties. For example, joystick.getHorizontal() in Arduino code becomes joystick.horizontal in python code. The Arduino methods relayOn() and relayOff() become relay_on() and relay_off() in python, and so on.
These libraries were released to the CircuitPython Community Repository. The source code, examples, installation information and documentation are available on GitHub.
Qwiic Joystick:
https://github.com/fourstix/Sparkfun_Ci … icJoystick
Qwiic Relay:
The source code, examples and documentation are available on GitHub here:
https://github.com/fourstix/Sparkfun_Ci … QwiicRelay
Qwiic Twist:
https://github.com/fourstix/Sparkfun_Ci … QwiicTwist
Adafruit has an excellent tutorial on installing CircuitPython on a Raspberry Pi.
https://learn.adafruit.com/circuitpytho … pberry-pi/
Once CircuitPython is installed on your Raspberry Pi, you can install the Qwiic CirucuitPython libraries you wish to use through Pip3 commands.
pip3 install sparkfun-circuitpython-qwiicjoystick
pip3 install sparkfun-circuitpython-qwiicrelay
pip3 install sparkfun-circuitpython-qwiictwist
Example:
Using the CircuitPython library on a Raspberry Pi, you can program the Joystick as follows:
# import the CircuitPython board and busio libraries
import board
import busio
import sparkfun_qwiicjoystick
# Create bus object using the board's I2C port
i2c = busio.I2C(board.SCL, board.SDA)
joystick = sparkfun_qwiicjoystick.QwiiJoystick(i2c) # default address is 0x20
# For a different address use QwiicJoystick(i2c, address)
# joysitck = sparkfun_qwiicjoystick.QwiicJoystick(i2c, 0x21)
# show the joystick position and button values
print('X: ' + str(joystick.horizontal)
+ ' Y: ' + str(joystick.vertical)
+ ' Button: ' + str(joystick.button))
For QwiicRelay you would create the class with:
relay = sparkfun_qwiicrelay.QwiiRelay(i2c) # default address is 0x18
And for QwiicTwist you would use:
twist = sparkfun_qwiictwist.QwiiTwist(i2c) # default address is 0x3F
I wrote these libraries on my own time and they are open source under the MIT license and free to use. They are based on Sparkfun and Adafruit products, tutorials and code. Sparkfun and Adafruit retain all rights to their respective intellectual properties. Please note that I am neither a Sparkfun nor Adafruit employee, so no official warranty or support for these libraries is implied or given by either company.
That said, please enjoy them and have fun!
Gaston Williams aka Fourstix