|
1 |
| -Adafruit CircuitPython driver for SSD1306 OLED displays. |
| 1 | +Introduction |
| 2 | +============ |
2 | 3 |
|
3 |
| -This driver is based on the SSD1306 driver in the MicroPython source but differs |
4 |
| -by supporting hardware I2C interfaces and Adafruit CircuitPython API. For a |
5 |
| -MicroPython machine API compatible library see: https://github.com/adafruit/micropython-adafruit-ssd1306 |
| 4 | +.. image:: https://readthedocs.org/projects/adafruit-circuitpython-ssd1306/badge/?version=latest |
| 5 | + :target: https://circuitpython.readthedocs.io/projects/ssd1306/en/latest/ |
| 6 | + :alt: Documentation Status |
| 7 | + |
| 8 | +.. image:: https://img.shields.io/discord/327254708534116352.svg |
| 9 | + :target: https://discord.gg/nBQh6qu |
| 10 | + :alt: Discord |
| 11 | + |
| 12 | +.. image:: https://travis-ci.org/adafruit/adafruit_CircuitPython_SSD1306.svg?branch=master |
| 13 | + :target: https://travis-ci.org/adafruit/adafruit_CircuitPython_SSD1306 |
| 14 | + :alt: Build Status |
| 15 | + |
| 16 | + Adafruit CircuitPython driver for SSD1306 OLED displays. |
| 17 | + |
| 18 | + This driver is based on the SSD1306 driver in the MicroPython source but differs |
| 19 | + by supporting hardware I2C interfaces and Adafruit CircuitPython API. For a |
| 20 | + MicroPython machine API compatible library see: https://github.com/adafruit/micropython-adafruit-ssd1306 |
| 21 | + |
| 22 | + |
| 23 | +Dependencies |
| 24 | +============= |
| 25 | +This driver depends on: |
| 26 | + |
| 27 | +* `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_ |
| 28 | +* `Bus Device <https://github.com/adafruit/Adafruit_CircuitPython_BusDevice>`_ |
| 29 | + |
| 30 | +Please ensure all dependencies are available on the CircuitPython filesystem. |
| 31 | +This is easily achieved by downloading |
| 32 | +`the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_. |
| 33 | + |
| 34 | +Usage Example |
| 35 | +============= |
| 36 | + |
| 37 | +.. code-block:: python3 |
| 38 | +
|
| 39 | + # Basic example of clearing and drawing pixels on a SSD1306 OLED display. |
| 40 | + # This example and library is meant to work with Adafruit CircuitPython API. |
| 41 | + # Author: Tony DiCola |
| 42 | + # License: Public Domain |
| 43 | +
|
| 44 | + # Import all board pins. |
| 45 | + from board import SCL, SDA |
| 46 | + import busio |
| 47 | +
|
| 48 | + # Import the SSD1306 module. |
| 49 | + import adafruit_ssd1306 |
| 50 | +
|
| 51 | +
|
| 52 | + # Create the I2C interface. |
| 53 | + i2c = busio.I2C(SCL, SDA) |
| 54 | +
|
| 55 | + # Create the SSD1306 OLED class. |
| 56 | + # The first two parameters are the pixel width and pixel height. Change these |
| 57 | + # to the right size for your display! |
| 58 | + display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c) |
| 59 | + # Alternatively you can change the I2C address of the device with an addr parameter: |
| 60 | + #display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, addr=0x31) |
| 61 | +
|
| 62 | + # Clear the display. Always call show after changing pixels to make the display |
| 63 | + # update visible! |
| 64 | + display.fill(0) |
| 65 | +
|
| 66 | + display.show() |
| 67 | +
|
| 68 | +
|
| 69 | +Contributing |
| 70 | +============ |
| 71 | + |
| 72 | +Contributions are welcome! Please read our `Code of Conduct |
| 73 | +<https://github.com/adafruit/adafruit_CircuitPython_SSD1306/blob/master/CODE_OF_CONDUCT.md>`_ |
| 74 | +before contributing to help this project stay welcoming. |
| 75 | + |
| 76 | +Building locally |
| 77 | +================ |
| 78 | + |
| 79 | +Zip release files |
| 80 | +----------------- |
| 81 | + |
| 82 | +To build this library locally you'll need to install the |
| 83 | +`circuitpython-build-tools <https://github.com/adafruit/circuitpython-build-tools>`_ package. |
| 84 | + |
| 85 | +.. code-block:: shell |
| 86 | +
|
| 87 | + python3 -m venv .env |
| 88 | + source .env/bin/activate |
| 89 | + pip install circuitpython-build-tools |
| 90 | +
|
| 91 | +Once installed, make sure you are in the virtual environment: |
| 92 | + |
| 93 | +.. code-block:: shell |
| 94 | +
|
| 95 | + source .env/bin/activate |
| 96 | +
|
| 97 | +Then run the build: |
| 98 | + |
| 99 | +.. code-block:: shell |
| 100 | +
|
| 101 | + circuitpython-build-bundles --filename_prefix adafruit-circuitpython-ssd1306 --library_location . |
| 102 | +
|
| 103 | +Sphinx documentation |
| 104 | +----------------------- |
| 105 | + |
| 106 | +Sphinx is used to build the documentation based on rST files and comments in the code. First, |
| 107 | +install dependencies (feel free to reuse the virtual environment from above): |
| 108 | + |
| 109 | +.. code-block:: shell |
| 110 | +
|
| 111 | + python3 -m venv .env |
| 112 | + source .env/bin/activate |
| 113 | + pip install Sphinx sphinx-rtd-theme |
| 114 | +
|
| 115 | +Now, once you have the virtual environment activated: |
| 116 | + |
| 117 | +.. code-block:: shell |
| 118 | +
|
| 119 | + cd docs |
| 120 | + sphinx-build -E -W -b html . _build/html |
| 121 | +
|
| 122 | +This will output the documentation to ``docs/_build/html``. Open the index.html in your browser to |
| 123 | +view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to |
| 124 | +locally verify it will pass. |
0 commit comments