Coder Social home page Coder Social logo

micropython-ssd1306's Introduction

micropython-ssd1306

This is a fork of the driver for SSD1306 displays which is hosted in the Micropython package. The purpose of this fork is to make the driver available on PyPi and thus installable via the upip package manager.

Installation

Use the upip package manager:

upip.install('micropython-ssd1306')

If your board or your computer doesn't have an active internet connection you can also clone this project on your local drive and copy the ssd1306.py to your board.

Example Usage

This shows an example usage on an ESP32 board with an SSD1306 display with an resolution of 128x32 pixels. The display is connected via I2C. On the ESP32 the I2C pins are: SDA: 23, SCL: 22.

First we set up the I2C bus on our ESP32 and scan for devices.

>>> import machine
>>> i2c = machine.I2C(sda=machine.Pin(23), scl=machine.Pin(22))
>>> i2c.scan()
[60]

This shows us that there is a device on address 60 which is 3C in Hex. That is where our display is supposed to live. Now we create an object for our OLED display.

>>> from ssd1306 import SSD1306_I2C
>>> oled = SSD1306_I2C(128, 32, i2c)

This is it. Now we can use our OLED display:

>>> oled.fill(1)
>>> oled.show()

This fills the whole display with white pixels. To clear the display do:

>>> oled.fill(0)
>>> oled.show()

Now we can also write some text:

>>> oled.text('Hello', 0, 0)
>>> oled.text('World', 0, 10)
>>> oled.show()

Find more information on how to use the SSD1306 on the great tutorial about the OLED featherwing from Adafruit.

micropython-ssd1306's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

micropython-ssd1306's Issues

Not work multiple display

Not work multiple display. Work only latest ininztalize.

if

oled1 = SSD1306_SPI(128, 64, spi, Pin(17),Pin(20), Pin(16))
oled3 = SSD1306_SPI(128, 64, spi, Pin(17),Pin(20), Pin(13))
oled2 = SSD1306_SPI(128, 64, spi, Pin(17),Pin(20), Pin(14))

work only oled2

oled1 = SSD1306_SPI(128, 64, spi, Pin(17),Pin(20), Pin(16))
oled2 = SSD1306_SPI(128, 64, spi, Pin(17),Pin(20), Pin(14))
oled3 = SSD1306_SPI(128, 64, spi, Pin(17),Pin(20), Pin(13))

work only oled3

if i control the cs pins myself it works correctly

Can the text size change?

Hello, first of all, thank you very much for the contribution, it is very appreciated. I only have a small doubt, is there any function that allows you to change the size of the text?

I'm interested in changing the text size for a project in which I work

Fix for random garbage dots on the OLED

I would like to leave a note to folks also having the problem that the SSD1306 only displays random dots (=garbage). I had this problem on my HELTEC_Wifi_LoRa_32_v3 board banging my head for hours only to finally find and apply this simple fix from @piskernik

To fix one simply has to extend the class initialization with an explicit reset PIN parameter:

# extend ssd1306.py library:
...
class SSD1306_I2C(SSD1306):
    def __init__(self, width, height, i2c, addr=0x3C, external_vcc=False, res=None):
        self.i2c = i2c
        self.addr = addr
        self.res = res
        self.temp = bytearray(2)
        self.write_list = [b"\x40", None]  # Co=0, D/C#=1
        if res != None:                 # NEW!
            res.init(res.OUT, value=0)
            import utime as time
            self.res(1)
            time.sleep_ms(1)
            self.res(0)
            time.sleep_ms(10)
            self.res(1)
        super().__init__(width, height, external_vcc)
...

and then to call it as follows (e.g. pin 21 on Heltec V3, could be pin 16 on other boards):

...
import ssd1306
oled = ssd1306.SSD1306_I2C(128, 64, i2c, res=Pin(21))
...

Here you can find more data about pins etc. .

can't import micropython-ssd1306

on a raspberry pi, running Bullseye, running Thonny, Tools, Manage Packages, search for SSD1306, try to install micropython-ssd1306 yields the following error:

ERROR: Could not find a version that satisfies the requirement micropython-ssd1306
ERROR: No matching distribution found for micropython-ssd1306
Process returned with code 1

ss1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.