OLED LCD Display: Difference between revisions

From Sketching with Hardware at LMU Wiki
Jump to navigation Jump to search
Created page with "= Description = Text Image(s) = How to connect it electrically = Text Image(s) = How to control it in MicroPython = <syntaxhighlight lang="python" line='line'> # todo #..."
 
No edit summary
Line 1: Line 1:
= Description =
= Description =
Text
See also '''[https://www.sketching-with-hardware.org/wiki/Tutorial_Display Tutorial Display]'''
 
We use '''[https://www.sketching-with-hardware.org/files/ssd1306.py ssd1306.py]'''


Image(s)




Line 12: Line 13:
= How to control it in MicroPython =
= How to control it in MicroPython =
<syntaxhighlight lang="python" line='line'>
<syntaxhighlight lang="python" line='line'>
# todo
from machine import Pin, I2C
# code goes here
from ssd1306 import SSD1306_I2C
 
i2c = I2C(scl=Pin(15), sda=Pin(4))
pin16 = Pin(16, Pin.OUT)
pin16.on()
 
oled_width = 128
oled_height = 64
oled = SSD1306_I2C(oled_width,oled_height,i2c)
 
# switch the display off, but it's still active
oled.poweroff()
 
# switch the display on again
oled.poweron()
 
# contrast in range 0-255 (0=darker)
oled.contrast(contrast)
 
# invert in True/False
oled.invert(invert)
 
# content will be shown, has to be called when something changes
oled.show()
 
 
# Graphics
# fill the screen in color c (0=dark, 1=bright)
oled.fill(c)
 
# set pixel at position x,y to color c
oled.pixel(x,y,c)
 
# returns color of pixel x,y
oled.pixel(x,y)
 
# draws a horizontal line from x,y, length=w in color c
oled.hline(x,y,w,c)
 
# draws a vertical line from x,y, length=w in color c
oled.vline(x,y,w,c)
 
# draws a line from x1,y1 to x2,y2 in color c
oled.line(x1,y1,x2,y2,c)
 
# draws a rectangle at position x,y with width=w and height=h in color c
oled.rect(x,y,w,h,c)
 
# draws a filled rectangle at position x,y with width=w and height=h in color c
oled.fill_rect(x,y,w,h,c)
 
 
# Text
# set text s at pixel x,y
oled.text(s,x,y,c)
 
# line = line number (0-5)
# pos = horizontal position (0-15)
def text_line(text, line, pos=0):
  x = 10*pos
  y = line*11
  oled.text(text,x,y)
  oled.show()
 
# don't forget to show!
oled.show()
</syntaxhighlight>
</syntaxhighlight>



Revision as of 18:03, 20 August 2020

Description

See also Tutorial Display

We use ssd1306.py


How to connect it electrically

Text

Image(s)

How to control it in MicroPython

from machine import Pin, I2C
from ssd1306 import SSD1306_I2C

i2c = I2C(scl=Pin(15), sda=Pin(4))
pin16 = Pin(16, Pin.OUT)
pin16.on()

oled_width = 128
oled_height = 64
oled = SSD1306_I2C(oled_width,oled_height,i2c)

# switch the display off, but it's still active
oled.poweroff()

# switch the display on again
oled.poweron()

# contrast in range 0-255 (0=darker)
oled.contrast(contrast)

# invert in True/False
oled.invert(invert)

# content will be shown, has to be called when something changes
oled.show()


# Graphics
# fill the screen in color c (0=dark, 1=bright)
oled.fill(c)

# set pixel at position x,y to color c
oled.pixel(x,y,c)

# returns color of pixel x,y
oled.pixel(x,y)

# draws a horizontal line from x,y, length=w in color c
oled.hline(x,y,w,c)

# draws a vertical line from x,y, length=w in color c
oled.vline(x,y,w,c)

# draws a line from x1,y1 to x2,y2 in color c
oled.line(x1,y1,x2,y2,c)

# draws a rectangle at position x,y with width=w and height=h in color c
oled.rect(x,y,w,h,c)

# draws a filled rectangle at position x,y with width=w and height=h in color c
oled.fill_rect(x,y,w,h,c)


# Text
# set text s at pixel x,y
oled.text(s,x,y,c)

# line = line number (0-5)
# pos = horizontal position (0-15)
def text_line(text, line, pos=0):
  x = 10*pos
  y = line*11
  oled.text(text,x,y)
  oled.show()

# don't forget to show!
oled.show()

A small Program in MicroPython

# todo 
# code goes here

text

image(s)

Related Tutorial Videos

change to the right video


Background

text

image(s)