OLED LCD Display

From Sketching with Hardware at LMU Wiki
Revision as of 18:03, 20 August 2020 by Manuela (talk | contribs)
Jump to navigation Jump to search

Description

See also Tutorial Display

We use ssd1306.py


How to connect it electrically

Text

Image(s)

How to control it in MicroPython

 1 from machine import Pin, I2C
 2 from ssd1306 import SSD1306_I2C
 3 
 4 i2c = I2C(scl=Pin(15), sda=Pin(4))
 5 pin16 = Pin(16, Pin.OUT)
 6 pin16.on()
 7 
 8 oled_width = 128
 9 oled_height = 64
10 oled = SSD1306_I2C(oled_width,oled_height,i2c)
11 
12 # switch the display off, but it's still active
13 oled.poweroff()
14 
15 # switch the display on again
16 oled.poweron()
17 
18 # contrast in range 0-255 (0=darker)
19 oled.contrast(contrast)
20 
21 # invert in True/False
22 oled.invert(invert)
23 
24 # content will be shown, has to be called when something changes
25 oled.show()
26 
27 
28 # Graphics
29 # fill the screen in color c (0=dark, 1=bright)
30 oled.fill(c)
31 
32 # set pixel at position x,y to color c
33 oled.pixel(x,y,c)
34 
35 # returns color of pixel x,y
36 oled.pixel(x,y)
37 
38 # draws a horizontal line from x,y, length=w in color c
39 oled.hline(x,y,w,c)
40 
41 # draws a vertical line from x,y, length=w in color c
42 oled.vline(x,y,w,c)
43 
44 # draws a line from x1,y1 to x2,y2 in color c
45 oled.line(x1,y1,x2,y2,c)
46 
47 # draws a rectangle at position x,y with width=w and height=h in color c
48 oled.rect(x,y,w,h,c)
49 
50 # draws a filled rectangle at position x,y with width=w and height=h in color c
51 oled.fill_rect(x,y,w,h,c)
52 
53 
54 # Text
55 # set text s at pixel x,y
56 oled.text(s,x,y,c)
57 
58 # line = line number (0-5)
59 # pos = horizontal position (0-15)
60 def text_line(text, line, pos=0):
61   x = 10*pos
62   y = line*11
63   oled.text(text,x,y)
64   oled.show()
65 
66 # don't forget to show!
67 oled.show()

A small Program in MicroPython

1 # todo 
2 # code goes here

text

image(s)

Related Tutorial Videos

change to the right video


Background

text

image(s)