Skip to content

dhparki/oled_tty

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OLED_TTY

Elementary glass teleptye for SSD1306_I2C OLED on Pi Pico with word-wrap, smooth-scroll, big text, reverse text, and marquee. MicroPython.

Description

An elementary "glass teletype" built on top of the ssd1306.py module for monochrome SSD1306 OLEDs connected via I2C to Pi Pico. Provides extra text facilities - word-wrap, smooth-scroll, big text, reverse text, and marquee.

Video

https://www.dhparki.com/video/OLED_TTY.mp4

Installing

For how to connect an SSD1306 I2C OLED to a Pi Pico, see the manufacturers instructions.

To use the library, you need to install oled_tty.py on your Pico - e.g. using "SaveAs To Raspberry Pi Pico" from Thonny, or "Upload file to Pico" from Visual Studio Code. You also need to install ssd1306.py from https://github.com/micropython/micropython-lib/blob/master/micropython/drivers/display/ssd1306/ssd1306.py.

Executing program

The oled_tty.py file contains a demo which you can run on the Pico from an editor such as Thonny or Visual Studio Code. The demo assumes a 128 x 32 pixel OLDED with SCA and SCL connected to GPIO pins 4 and 5 respecively, plus power connections to 3V and GND, but you can edit the code to change this.

Limitations

The current code is for SSD1306_I2C OLEDs only. It could probably be modified for other monochrome OLEDs fairly easily; supporting colour OLEDs would be significantly harder.

Example (examples/archipoeta.py)

The following code runs the same demo as the main() routine in oled_tty.py. See "Executing program" for how to set it up.

from oled_tty import OLED_TTY
from utime import sleep

def main():
    oled = OLED_TTY(sda_pin=4, scl_pin=5, width=128, height=32) # Adjust pins and size as needed
    print(oled)

    try:
        print('Running demo - ^C to exit')

        oled.type('Confessio ab Archipoeta:')
        sleep(2)

        oled.cls()
        while True:
            oled.scroll('Meum est propositum in taberna mori,')
            oled.scroll('ut sint vina proxima morientis ori.')
            oled.scroll('tunc cantabunt letius angelorum chori:')
            oled.scroll('"Sit Deus propitius huic potatori."')
            sleep(10)
            oled.marquee("Salve, Mundus!", border=True)
    finally:
        print('Quit')
        oled.cleanup()

if __name__== "__main__":
    main()

Documentation

CONSTRUCTOR

    oled = OLED_TTY(sda_pin, scl_pin, width, height, speed=10, bufsize=20) 
        OLED display with type function with word-wrap, smooth-scroll, big text, reverse text, and marquee.
        sda_pin and scl_pin are GPIO pins, 
        width and height are in pixels.  
        speed is scroll speed in pixels per second, 
        bufsize is max lines to buffer while scrolling.

METHODS

    oled.cls() 
        clear screen and stop any scrolling or marquee

    oled.type(txt, cls=False)
        print with word-wrap.  
        If cls=True, clear screen first.

    oled.scroll(txt, cls=False)
        scroll text up with word-wrap.  
        If cls=True, clear screen first.

    oled.big_text(txt, x, y, scale = 2, rvs = False) - 
        draw text at x,y with given scale (power of 2)
        Reverse video if rvs=True

    oled.marquee(txt, scale = 2, speed = 50, top = None, border = False, callback = None) - 
        scroll text across display at given scale (power of 2) and speed (pixels per second). 
        Top = vertical position in pixels, default is half way up display.  
        If border=True, draw border around marquee.  
        If callback provided, call with no parameters when marquee finished.

DESTRUCTOR
    oled.cleanup() 
        call when finished to stop timers and clear display.

Authors

Dave Parkinson, davep@dhparki.com

Version History

  • 0.4
    • First public release on GitHub

License

This project is licensed under the MIT License - see the LICENSE.md file for details

About

Elementary glass teleptye for SSD1306_I2C OLED on Pi Pico with word-wrap, smooth-scroll, big text, reverse text, and marquee. MicroPython.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages