|
1 | | -Qwiic_OLED_Base_Py |
2 | | -=================== |
| 1 | + |
3 | 2 |
|
4 | | -<p align="center"> |
5 | | - <img src="https://cdn.sparkfun.com/assets/custom_pages/2/7/2/qwiic-logo-registered.jpg" width=200> |
6 | | - <img src="https://www.python.org/static/community_logos/python-logo-master-v3-TM.png" width=240> |
7 | | -</p> |
8 | | -<p align="center"> |
9 | | - <a href="https://pypi.org/project/sparkfun-qwiic-oled-base/" alt="Package"> |
10 | | - <img src="https://img.shields.io/pypi/pyversions/sparkfun_qwiic_oled_base.svg" /></a> |
11 | | - <a href="https://github.com/sparkfun/Qwiic_OLED_Base_Py/issues" alt="Issues"> |
12 | | - <img src="https://img.shields.io/github/issues/sparkfun/Qwiic_OLED_Base_Py.svg" /></a> |
13 | | - <a href="https://qwiic-oled-base-py.readthedocs.io/en/latest/index.html" alt="Documentation"> |
14 | | - <img src="https://readthedocs.org/projects/qwiic-oled-base-py/badge/?version=latest&style=flat" /></a> |
15 | | - <a href="https://github.com/sparkfun/Qwiic_OLED_Base_Py/blob/master/LICENSE" alt="License"> |
16 | | - <img src="https://img.shields.io/badge/license-MIT-blue.svg" /></a> |
17 | | - <a href="https://twitter.com/intent/follow?screen_name=sparkfun"> |
18 | | - <img src="https://img.shields.io/twitter/follow/sparkfun.svg?style=social&logo=twitter" |
19 | | - alt="follow on Twitter"></a> |
20 | | - |
21 | | -</p> |
| 3 | +# SparkFun Qwiic OLED - Python Package |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +[](https://docs.sparkfun.com/qwiic_oled_base_py/classqwiic__oled_1_1qwiic__oled__base_1_1_qwiic_oled_base.html) |
22 | 10 |
|
23 | | -<img src="https://cdn.sparkfun.com//assets/parts/1/2/6/2/1/14532-SparkFun_Micro_OLED_Breakout__Qwiic_-01.jpg" align="right" width=200 alt="SparkFun Qwiic Micro OLED Breakout"> |
| 11 | +The SparkFun Qwiic OLED Module provides a simple and cost effective solution for adding OLED capabilities to your project. Implementing a SparkFun Qwiic I2C interface, these sensors can be rapidly added to any project with boards that are part of the SparkFun Qwiic ecosystem. |
24 | 12 |
|
25 | | -The base (superclass/parent) Python package for the [Qwiic_Micro_OLED_Py](https://github.com/sparkfun/Qwiic_Micro_OLED_Py) and [Qwiic_OLED_Display_Py](https://github.com/sparkfun/Qwiic_OLED__Display_Py) derived (subclass/child) Python packages, which are intended for the qwiic [Micro OLED](https://www.sparkfun.com/products/14532) and [OLED Display](https://www.sparkfun.com/products/17153) boards. |
| 13 | +This repository implements a Python package for the SparkFun Qwiic OLED. This package works with Python, MicroPython and CircuitPython. |
26 | 14 |
|
27 | | -This package is a port of the [SparkFun Micro OLED Breakout Arduino Library](https://github.com/sparkfun/SparkFun_Micro_OLED_Arduino_Library) |
| 15 | +### Contents |
28 | 16 |
|
29 | | -This package can be used in conjunction with the overall [SparkFun qwiic Python Package](https://github.com/sparkfun/Qwiic_Py) |
| 17 | +* [About](#about-the-package) |
| 18 | +* [Getting Started](#getting-started) |
| 19 | +* [Installation](#installation) |
| 20 | +* [Supported Platforms](#supported-platforms) |
| 21 | +* [Documentation](https://docs.sparkfun.com/qwiic_oled_base_py/classqwiic__oled_1_1qwiic__oled__base_1_1_qwiic_oled_base.html) |
| 22 | +* [Examples](#examples) |
| 23 | + |
| 24 | +## About the Package |
| 25 | + |
| 26 | +This python package enables the user to access the features of the OLED via a single Qwiic cable. This includes displaying a splashscreen, drawing shapes, writing different fonts, moving the cursor and more. The capabilities of the OLED are each demonstrated in the included examples. |
30 | 27 |
|
31 | 28 | New to qwiic? Take a look at the entire [SparkFun qwiic ecosystem](https://www.sparkfun.com/qwiic). |
32 | 29 |
|
33 | | -<br> |
34 | | -<img src="https://cdn.sparkfun.com//assets/parts/1/6/1/3/5/17153-SparkFun_Qwiic_OLED_Display__0.91_in__128x32_-01.jpg" align="right" width=200 alt="SparkFun Qwiic OLED Display"> |
| 30 | +### Supported SparkFun Products |
35 | 31 |
|
36 | | -## Contents |
| 32 | +This Python package supports the following SparkFun qwiic products on Python, MicroPython and Circuit python. |
37 | 33 |
|
38 | | -* [Supported Platforms](#supported-platforms) |
39 | | -* [Dependencies](#dependencies) |
40 | | -* [Installation](#installation) |
41 | | -* [Documentation](#documentation) |
42 | | -* [Example Use](#example-use) |
| 34 | +* [SparkFun OLED Sensor - OLED](http://www.sparkfun.com/qwiic) |
| 35 | + |
| 36 | +### Supported Platforms |
| 37 | + |
| 38 | +| Python | Platform | Boards | |
| 39 | +|--|--|--| |
| 40 | +| Python | Linux | [Raspberry Pi](https://www.sparkfun.com/raspberry-pi-5-8gb.html) , [NVIDIA Jetson Orin Nano](https://www.sparkfun.com/nvidia-jetson-orin-nano-developer-kit.html) via the [SparkFun Qwiic SHIM](https://www.sparkfun.com/sparkfun-qwiic-shim-for-raspberry-pi.html) | |
| 41 | +| MicroPython | Raspberry Pi - RP2, ESP32 | [SparkFun RP2040 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-rp2040.html), [SparkFun RP2350 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-rp2350.html), [SparkFun ESP32 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-esp32-wroom-usb-c.html) |
| 42 | +|CircuitPython | Raspberry Pi - RP2, ESP32 | [SparkFun RP2040 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-rp2040.html), [SparkFun RP2350 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-rp2350.html), [SparkFun ESP32 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-esp32-wroom-usb-c.html) |
| 43 | + |
| 44 | +> [!NOTE] |
| 45 | +> The listed supported platforms and boards are the primary platform targets tested. It is fully expected that this package will work across a wide variety of Python enabled systems. |
| 46 | +
|
| 47 | +## Installation |
43 | 48 |
|
44 | | -Supported Platforms |
45 | | --------------------- |
46 | | -The qwiic Python package current supports the following platforms: |
47 | | -* [Raspberry Pi](https://www.sparkfun.com/search/results?term=raspberry+pi) |
48 | | -* [NVidia Jetson Nano](https://www.sparkfun.com/products/15297) |
49 | | -* [Google Coral Development Board](https://www.sparkfun.com/products/15318) |
| 49 | +The first step to using this package is installing it on your system. The install method depends on the python platform. The following sections outline installation on Python, MicroPython and CircuitPython. |
50 | 50 |
|
51 | | -Dependencies |
52 | | -================ |
53 | | -This driver package depends on the qwiic I2C driver: |
54 | | -[Qwiic_I2C_Py](https://github.com/sparkfun/Qwiic_I2C_Py) |
| 51 | +### Python |
55 | 52 |
|
56 | | -Documentation |
57 | | -------------- |
58 | | -The SparkFun qwiic OLED Base module documentation is hosted at [ReadTheDocs](https://qwiic-oled-base-py.readthedocs.io/en/latest/index.html) |
| 53 | +#### PyPi Installation |
59 | 54 |
|
60 | | -Installation |
61 | | --------------- |
| 55 | +The package is primarily installed using the `pip3` command, downloading the package from the Python Index - "PyPi". |
62 | 56 |
|
63 | | -### PyPi Installation |
64 | | -This repository is hosted on PyPi as the [sparkfun-qwiic-oled-base](https://pypi.org/project/sparkfun-qwiic-oled-base/) package. On systems that support PyPi installation via pip, this library is installed using the following commands |
| 57 | +Note - the below instructions outline installation on a Linux-based (Raspberry Pi) system. |
65 | 58 |
|
66 | | -For all users (note: the user must have sudo privileges): |
| 59 | +First, setup a virtual environment from a specific directory using venv: |
67 | 60 | ```sh |
68 | | -sudo pip install sparkfun-qwiic-oled-base |
| 61 | +python3 -m venv path/to/venv |
69 | 62 | ``` |
70 | | -For the current user: |
| 63 | +You can pass any path as path/to/venv, just make sure you use the same one for all future steps. For more information on venv [click here](https://docs.python.org/3/library/venv.html). |
71 | 64 |
|
| 65 | +Next, install the qwiic package with: |
72 | 66 | ```sh |
73 | | -pip install sparkfun_qwiic_oled_base |
| 67 | +path/to/venv/bin/pip3 install sparkfun-qwiic-oled |
| 68 | +``` |
| 69 | +Now you should be able to run any example or custom python scripts that have `import qwiic_oled` by running e.g.: |
| 70 | +```sh |
| 71 | +path/to/venv/bin/python3 example_script.py |
74 | 72 | ``` |
75 | 73 |
|
76 | | -### Local Installation |
77 | | -To install, make sure the setuptools package is installed on the system. |
| 74 | +### MicroPython Installation |
| 75 | +If not already installed, follow the [instructions here](https://docs.micropython.org/en/latest/reference/mpremote.html) to install mpremote on your computer. |
78 | 76 |
|
79 | | -Direct installation at the command line: |
| 77 | +Connect a device with MicroPython installed to your computer and then install the package directly to your device with mpremote mip. |
80 | 78 | ```sh |
81 | | -python setup.py install |
| 79 | +mpremote mip install github:sparkfun/qwiic_oled_py |
82 | 80 | ``` |
83 | 81 |
|
84 | | -To build a package for use with pip: |
| 82 | +If you would also like to install the examples for this repository, issue the following mip command as well: |
85 | 83 | ```sh |
86 | | -python setup.py sdist |
87 | | - ``` |
88 | | -A package file is built and placed in a subdirectory called dist. This package file can be installed using pip. |
| 84 | +mpremote mip install github:sparkfun/qwiic_oled_py@examples |
| 85 | +``` |
| 86 | + |
| 87 | +### CircuitPython Installation |
| 88 | +If not already installed, follow the [instructions here](https://docs.circuitpython.org/projects/circup/en/latest/#installation) to install CircUp on your computer. |
| 89 | + |
| 90 | +Ensure that you have the latest version of the SparkFun Qwiic CircuitPython bundle. |
89 | 91 | ```sh |
90 | | -cd dist |
91 | | -pip install sparkfun_oled_base-<version>.tar.gz |
| 92 | +circup bundle-add sparkfun/Qwiic_Py |
92 | 93 | ``` |
93 | | - |
| 94 | + |
| 95 | +Finally, connect a device with CircuitPython installed to your computer and then install the package directly to your device with circup. |
| 96 | +```sh |
| 97 | +circup install --py qwiic_oled |
| 98 | +``` |
| 99 | + |
| 100 | +If you would like to install any of the examples from this repository, issue the corresponding circup command from below. (NOTE: The below syntax assumes you are using CircUp on Windows. Linux and Mac will have different path seperators. See the [CircUp "example" command documentation](https://learn.adafruit.com/keep-your-circuitpython-libraries-on-devices-up-to-date-with-circup/example-command) for more information) |
| 101 | + |
| 102 | +```sh |
| 103 | +circup example qwiic_oled\ex1_splash_screen |
| 104 | +circup example qwiic_oled\ex2_hello_world |
| 105 | +circup example qwiic_oled\ex3_demo |
| 106 | +circup example qwiic_oled\ex4_cube |
| 107 | +circup example qwiic_oled\ex5_micro_bitmap |
| 108 | +``` |
| 109 | + |
94 | 110 | Example Use |
95 | | ------------- |
96 | | -This example is intended to be used with the [Micro OLED Breakout](https://www.sparkfun.com/products/14532) board. (See the <a href="https://github.com/sparkfun/Qwiic_OLED_Base_Py/tree/main/examples">examples directory</a> for more detailed use cases.) |
| 111 | + --------------- |
| 112 | +Below is a quickstart program to print readings from the OLED. |
| 113 | + |
| 114 | +See the examples directory for more detailed use examples and [examples/README.md](https://github.com/sparkfun/qwiic_oled_py/blob/main/examples/README.md) for a summary of the available examples. |
97 | 115 |
|
98 | 116 | ```python |
99 | | -import qwiic_oled_base |
| 117 | + |
| 118 | +import qwiic_oled |
| 119 | +import time |
100 | 120 | import sys |
101 | 121 |
|
102 | 122 |
|
103 | | -def runExample(): |
| 123 | +userOLED = qwiic_oled.QwiicMicroOled() # Micro OLED https://www.sparkfun.com/products/14532 |
104 | 124 |
|
105 | | - # These lines of code are all you need to initialize the OLED display and print text on the screen. |
| 125 | +def runExample(): |
106 | 126 |
|
107 | | - print("\nSparkFun Micro OLED Hello Example\n") |
108 | | - myOLED = qwiic_oled_base.QwiicOledBase() |
| 127 | + print("\nOLED Display - Splash screen example\n") |
| 128 | + myOLED = userOLED |
109 | 129 |
|
110 | | - if myOLED.is_connected() == False: |
111 | | - print("The Qwiic Micro OLED device isn't connected to the system. Please check your connection", \ |
| 130 | + if not myOLED.connected: |
| 131 | + print("The OLED Display isn't connected to the system. Please check your connection", \ |
112 | 132 | file=sys.stderr) |
113 | 133 | return |
114 | 134 |
|
115 | | - # Before you can start using the OLED, call begin() to init all of the pins and configure the OLED. |
116 | 135 | myOLED.begin() |
117 | 136 |
|
| 137 | + myOLED.clear(myOLED.ALL) # Clear the display's memory (gets rid of artifacts) |
| 138 | + |
| 139 | + myOLED.display() # Display buffer contents |
| 140 | + time.sleep(3) |
| 141 | + |
118 | 142 | myOLED.clear(myOLED.PAGE) # Clear the display's buffer |
119 | 143 |
|
120 | | - myOLED.print("Hello World") # Add "Hello World" to buffer |
| 144 | + myOLED.display() |
| 145 | + time.sleep(3) |
| 146 | + |
| 147 | + qwiic_oled.oled_logos.add_logo(myOLED._screenbuffer) |
121 | 148 |
|
122 | | - # To actually draw anything on the display, you must call the display() function. |
123 | 149 | myOLED.display() |
124 | 150 |
|
125 | | -runExample() |
126 | | -``` |
| 151 | +if __name__ == '__main__': |
| 152 | + try: |
| 153 | + runExample() |
| 154 | + except (KeyboardInterrupt, SystemExit) as exErr: |
| 155 | + print("\nEnding OLED bitmap Example") |
| 156 | + sys.exit(0) |
127 | 157 |
|
| 158 | +``` |
128 | 159 | <p align="center"> |
129 | 160 | <img src="https://cdn.sparkfun.com/assets/custom_pages/3/3/4/dark-logo-red-flame.png" alt="SparkFun - Start Something"> |
130 | 161 | </p> |
0 commit comments