6184 views|45 replies

1w

Posts

25

Resources
The OP
 

OLED display driver [Copy link]

 
 

Improved the OLED driver to support multiple fonts. Currently supports:

  • 6x8
  • 8x16
  • 12x24
  • 16x32

Drivers:

游客,如果您要查看本帖隐藏内容请回复


This content is originally created by dcexpert , a user of EEWORLD forum. If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source

Latest reply

Learn from it, thank you sir.  Details Published on 2024-4-2 10:22

赞赏

3

查看全部赞赏

 
 

1w

Posts

25

Resources
2
 

Demo

from machine import I2C, Pin
from oled import OLED12864_I2C

i2c = I2C(-1, scl = Pin(27, pull = Pin.PULL_UP), sda = Pin(13, pull = Pin.PULL_UP))

oled = OLED12864_I2C(i2c)
oled.text(0, 0, '0123456789')
oled.Font('Font_8x16')
oled.text(0, 1, '0123456789')
oled.Font('Font_12x24')
oled.text(0, 3, '0123456789')

 
 
 

1

Posts

0

Resources
3
 

All the masters show their magical powers

 
 
 

3

Posts

0

Resources
4
 

Thanks, I registered to see it.

Comments

Welcome to learn and communicate together  Details Published on 2020-2-4 18:28
 
 
 

1w

Posts

25

Resources
5
 
stategrid posted on 2020-2-4 16:44 Thank you, I registered to take a look

Welcome to learn and communicate together

 
 
 

13

Posts

0

Resources
6
 

Good things should be collected

 
 
 

4

Posts

0

Resources
7
 

OLED display driver[ edit ]

 
 
 

15

Posts

0

Resources
8
 

Good things need to be collected

 
 
 

3

Posts

0

Resources
9
 

Some analysis of the code, I am a novice and a layman, please give me some advice

First of all, the screen resolution is 128*64. The dot matrix display mode is from left to right from def text_6x8. After the horizontal coordinate scans to 128, it turns to the starting point of the next line, that is, x=0, y+1.

x > 120 instead of x > 126, I think to avoid going out of range?

Then the display method of these displays is to open a buffer, some are in the display controller, some are in the MCU memory, and some are both. The size of the buffer is the same as the screen, 128*64, that is, corresponding to each point on the screen.

By rewriting the buffer and sending the rewriting result to the hardware interface, the characters can be displayed.

The next step is to find the corresponding character position in font to see what content to rewrite. This part of the code is not clear

def char_6x8(self, x=0, y=0, ch=32, c=1):
try:
ind = x + y * 128 + 1
n = (min(127, max(ord(ch), 32)) -32)*5
for i in range(5):
screen[ind+i] = Font_6x8[n+i] if c else Font_6x8[n+i]^0xFF
screen[ind+5] = 0 if c else 0xFF
self .set_pos(x, y)
self.i2c.writeto(self.ADDR, b'\x40' + screen[ind:ind + 6])
except:
return

def text_6x8(self, x=0, y=0, s='', c=1, wrap=0):
for i in range(len(s)):
self.char(x, y, s[i] , c)
x += 6
if wrap and x > 120:
x = 0
y += 1

Comments

When using i2c or spi, because the internal cache data of oled cannot be read, a 128x64/8=1024-byte buffer needs to be opened externally. Because the font is not large, it is faster to put it directly into ram. If it is to display Chinese, the font library is large, it is best to put it in flash, or  Details Published on 2020-2-14 22:03
 
 
 

2

Posts

0

Resources
10
 

See if this works.

 
 
 

1w

Posts

25

Resources
11
 
stategrid posted on 2020-2-8 04:58 Some analysis of the code, I am a novice and a layman, please give me some advice. First of all, the screen resolution is 128*64, and the dot matrix display mode is from def text_6 ...

When using the i2c or spi method, because the internal cache data of the oled cannot be read, a 128x64/8=1024-byte buffer needs to be opened externally.

Because the font is not large, it is faster to put it directly into RAM. If you want to display Chinese, the font library is large, it is best to put it in flash, or use a dedicated font chip.

 
 
 

5

Posts

0

Resources
12
 

Awesome. Let's learn

 
 
 

1027

Posts

0

Resources
13
 

Thanks for sharing

 
 
 

1

Posts

0

Resources
14
 
Thank you, I'll learn from you.
 
 
 

5

Posts

0

Resources
15
 

Good things should be collected

 
 
 

4

Posts

0

Resources
16
 

study

 
 
 

2w

Posts

341

Resources
17
 

See what's going on

 
 
 

2

Posts

0

Resources
18
 

study

 
 
 

63

Posts

0

Resources
19
 

Take a look and learn

 
 
 

4

Posts

0

Resources
20
 

Thank you for sharing

 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list