Skip to content

Commit 806837c

Browse files
committed
add LCD1602 Big Digits drive
Display large font numbers on LCD1602, ported from the [small display BIG DIGITS project](https://github.com/upiir/character_display_big_digits), please visit the project link to view the font image.
1 parent 7c9ca67 commit 806837c

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed

‎lcd/LCD1602_BIG_DIGITS/README.md‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# LCD1602 Big Digits
2+
3+
Display large font numbers on LCD1602, ported from the [small display BIG DIGITS project](https://github.com/upiir/character_display_big_digits), please visit the project link to view the font image.
4+
5+
**usage**
6+
7+
```
8+
from lcd1602_bigdigit import LCD1602_BIGDIGIT
9+
from machine import I2C, Pin
10+
from time import sleep_ms
11+
12+
i2c = I2C(1, sda = Pin(18), scl = Pin(16))
13+
14+
lcd = LCD1602_BIGDIGIT(i2c, 39)
15+
lcd.font('square_three')
16+
17+
n = 0
18+
while 1:
19+
n+=1
20+
lcd.number(n)
21+
sleep_ms(1000)
22+
23+
```
24+
25+
![](https://user-images.githubusercontent.com/117754156/230296829-0aea22ec-64da-4251-bfc0-5bbacfc92c3e.jpg)
26+
27+
28+
From microbit/micropython Chinese community.
29+
www.micropython.org.cn
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from lcd1602_bigdigit import LCD1602_BIGDIGIT
2+
from machine import I2C, Pin
3+
from time import sleep_ms
4+
5+
#i2c = I2C(1, sda=Pin(27), scl=Pin(26))
6+
i2c = I2C(1, sda = Pin(18), scl = Pin(16))
7+
8+
lcd = LCD1602_BIGDIGIT(i2c, 39)
9+
lcd.font('square_three')
10+
11+
n = 0
12+
while 1:
13+
n+=1
14+
lcd.number(n,4)
15+
sleep_ms(1000)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
'''
2+
mpy drive for I2C LCD1602 Big Digits
3+
4+
Author: shaoziyang
5+
Date: 2024.9
6+
7+
https://www.micropython.org.cn
8+
9+
'''
10+
from i2c_lcd1602 import I2C_LCD1602
11+
12+
BIGFONTS = {
13+
'real':[b'\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\x1c\x02\x02\x01\x01\x02\x02\x1c\x07\x08\x08\x10\x10\x08\x08\x07\x1c\x04\x04\x04\x08\x08\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x08\x08\x07\x03\x04\x04\x08\x08\x10\x10\x1f',b'\x00T\x07\x07$S$4\x93\x07\x924\x92\x84&\x07TTT6'],
14+
'real_bold':[b'\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\x1c\x0e\x06\x07\x07\x06\x0e\x1c\x07\x0e\x0c\x1c\x1c\x0c\x0e\x07\x1e\x06\x06\x06\x0c\x0c\x18\x18\x18\x18\x18\x18\x18\x18\x18\x18\x18\x18\x18\x18\x1c\x0c\x0e\x07\x03\x06\x06\x0c\x0c\x18\x18\x1f',b'\x00T\x07\x07$S$4\x93\x07\x924\x92\x84&\x07TTT6'],
15+
'rounded':[b'\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\x1c\x02\x01\x01\x01\x01\x02\x1c\x07\x08\x10\x10\x10\x10\x08\x07\x00\x00\x00\x10\x10\x10\x10\x1f\x10\x10\x10\x10\x10\x10\x10\x10\x01\x02\x04\x08\x00\x00\x00\x00\x10\x10\x10\x10\x10\x08\x04\x03',b'\x00T\x87\x07$S$4\x96\x07R4RT$\x07TTT4'],
16+
'rounded_bold':[b'\x1f\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\x1f\x1c\x1e\x07\x03\x03\x07\x1e\x1c\x07\x0f\x1c\x18\x18\x1c\x0f\x07\x00\x00\x00\x18\x18\x18\x1f\x1f\x18\x18\x18\x18\x18\x18\x18\x18\x03\x07\x0e\x0c\x00\x00\x00\x00\x18\x18\x18\x18\x18\x0c\x07\x03',b'\x00T\x87\x07$S$4\x96\x07R4RT$\x07TTT4'],
17+
'skewed':[b'\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\x1f\x01\x01\x01\x02\x04\x08\x10\x01\x02\x04\x08\x10\x10\x10\x1f\x1f\x10\x10\x10\x10\x10\x10\x1f\x10\x10\x10\x10\x10\x10\x10\x10\x1f\x00\x00\x00\x00\x00\x00\x1f\x1f\x10\x10\x10\x10\x10\x10\x10',b'\x00d\x07\x07$S$4S\x07\x92\x84\x92d$\x07dd\x94$'],
18+
'skewed_bold':[b'\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\x1f\x03\x03\x03\x02\x04\x08\x10\x01\x02\x04\x08\x18\x18\x18\x1f\x1f\x18\x18\x18\x18\x18\x18\x1f\x18\x18\x18\x18\x18\x18\x18\x18\x1f\x00\x00\x00\x00\x00\x00\x1f\x1f\x18\x18\x18\x18\x18\x18\x18',b'\x00d\x07\x07$S$4S\x07\x92\x84\x92d$\x07dd\x94$'],
19+
'dots_small':[b'\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x15\x15\x00\x01\x00\x00\x01\x00\x15\x15\x00\x10\x00\x00\x10\x00\x15\x15\x00\x10\x00\x00\x10\x00\x10\x10\x00\x10\x00\x00\x10\x00\x10\x15\x00\x00\x00\x00\x00\x00\x15\x10\x00\x10\x00\x00\x10\x00\x15',b'g\x97\x07\x07\x84X$4\x93\x07X\x84XT$\x07TTT\x84'],
20+
'dots_big':[b'\x1b\x1b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1b\x1b\x1b\x1b\x00\x03\x03\x00\x1b\x1b\x1b\x1b\x00\x18\x18\x00\x1b\x1b\x1b\x1b\x00\x18\x18\x00\x18\x18\x18\x18\x00\x18\x18\x00\x18\x18\x1b\x1b\x00\x00\x00\x00\x1b\x1b\x18\x18\x00\x18\x18\x00\x1b\x1b',b'g\x97\x07\x07\x84X$4\x93\x07X\x84XT$\x07TTT\x84'],
21+
'dashed':[b'\x1b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1b\x1b\x01\x00\x01\x01\x00\x01\x1b\x1b\x10\x00\x10\x10\x00\x10\x1b\x1b\x10\x00\x10\x10\x00\x10\x10\x10\x10\x00\x10\x10\x00\x10\x10\x1b\x00\x00\x00\x00\x00\x00\x1b\x10\x10\x00\x10\x10\x00\x10\x1b',b'g\x97\x07\x07\x84X$4\x93\x07X\x84XT$\x07TTT\x84'],
22+
'dashed_bold':[b'\x1b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1b\x1b\x03\x00\x03\x03\x00\x03\x1b\x1b\x18\x00\x18\x18\x00\x18\x1b\x1b\x18\x00\x18\x18\x00\x18\x18\x18\x18\x00\x18\x18\x00\x18\x18\x1b\x00\x00\x00\x00\x00\x00\x1b\x18\x18\x00\x18\x18\x00\x18\x1b',b'g\x97\x07\x07\x84X$4\x93\x07X\x84XT$\x07TTT\x84'],
23+
'angled':[b'\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\x1f\x01\x01\x01\x01\x01\x01\x1f\x1f\x10\x10\x10\x10\x10\x10\x1f\x1f\x01\x01\x01\x01\x01\x01\x01\x10\x10\x10\x10\x10\x10\x10\x10\x1f\x00\x00\x00\x00\x00\x00\x1f\x01\x01\x01\x01\x01\x01\x01\x1f',b'\x00T\x07\x07&X&4S\x07R4pT$\x07TTT\t'],
24+
'angled_bold':[b'\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\x1f\x03\x03\x03\x03\x03\x03\x1f\x1f\x18\x18\x18\x18\x18\x18\x1f\x1f\x03\x03\x03\x03\x03\x03\x03\x18\x18\x18\x18\x18\x18\x18\x18\x1f\x00\x00\x00\x00\x00\x00\x1f\x03\x03\x03\x03\x03\x03\x03\x1f',b'\x00T\x07\x07&X&4S\x07R4pT$\x07TTT\t'],
25+
'blocks':[b'\x1f\x1f\x1f\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x00\x00\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',b'\x11\x11\x01\x01!\x13!1\x13\x01\x121\x12\x11!\x01DU\x111'],
26+
'blocks_crossed':[b'\x1f\x1f\x1f\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x1f\x1f\x1f\x1f\x1e\x1d\x1b\x17\x0f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1e\x1d\x1f\x1f\x1f\x1f\x17\x0f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1e\x1d\x1b\x17\x0f\x1e\x1d\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x17\x0f',b"\x19\x81\x04\x01!C'1C\x01\x124\x12V!\x07VVV1"],
27+
'blocks_cut':[b'\x1f\x1f\x1f\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x1f\x1f\x1f\x1f\x01\x03\x07\x0f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x0f\x07\x03\x01\x10\x18\x1c\x1e\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1e\x1c\x18\x10\x00\x00\x00\x00\x00\x01\x03\x07\x1c\x18\x10\x00\x00\x00\x00\x00',b"A\x17\x04\x01'C!7C\x01\x127I\x17!\x07\x17AA\x87"],
28+
'classic':[b'\x1f\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x18\x1f\x1f\x03\x03\x03\x03\x03\x03\x1f\x1f\x18\x18\x18\x18\x18\x18\x1f\x01\x02\x04\x00\x00\x00\x00\x00\x18\x18\x18\x18\x18\x18\x18\x18\x1f\x00\x00\x00\x00\x00\x00\x1f\x18\x18\x18\x18\x18\x18\x18\x1f',b'\x00Tg\x07\x84X$4\x93\x07X\x84XT$\x07TTT\x84'],
29+
'classic_bold':[b'\x1f\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x18\x1f\x1f\x07\x07\x07\x07\x07\x07\x1f\x1f\x1c\x1c\x1c\x1c\x1c\x1c\x1f\x01\x03\x07\x00\x00\x00\x00\x00\x1c\x1c\x1c\x1c\x1c\x1c\x1c\x1c\x1f\x00\x00\x00\x00\x00\x00\x1f\x1c\x1c\x1c\x1c\x1c\x1c\x1c\x1f',b'\x00Tg\x07\x84X$4\x93\x07X\x84XT$\x07TTT\x84'],
30+
'classic_serif':[b'\x1f\x1f\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x18\x1f\x1f\x1f\x03\x03\x03\x03\x03\x03\x1f\x1f\x18\x18\x18\x18\x18\x18\x1f\x1f\x00\x00\x00\x00\x00\x1f\x1f\x18\x18\x18\x18\x18\x18\x18\x18\x1f\x1f\x00\x00\x00\x00\x00\x1f\x18\x18\x18\x18\x18\x18\x18\x1f',b'\x00T\x07\x07\x84V$4\x93\x07XdXT$\x07TTTd'],
31+
'tron':[b'\x1f\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x18\x1f\x1f\x03\x03\x03\x03\x03\x03\x03\x1f\x18\x18\x18\x18\x18\x18\x1f\x1f\x18\x18\x18\x18\x18\x18\x18\x18\x18\x18\x18\x18\x18\x18\x18\x1f\x00\x00\x00\x00\x00\x00\x1f\x18\x18\x18\x18\x18\x18\x18\x1f',b'd\x91\x07\x07$X$1\x93\x07X1XQ$\x07TQT\x04'],
32+
'tron_bold':[b'\x1f\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x18\x1f\x1f\x07\x07\x07\x07\x07\x07\x07\x1f\x1c\x1c\x1c\x1c\x1c\x1c\x1f\x1f\x1c\x1c\x1c\x1c\x1c\x1c\x1c\x1c\x1c\x1c\x1c\x1c\x1c\x1c\x1c\x1f\x00\x00\x00\x00\x00\x00\x1f\x1c\x1c\x1c\x1c\x1c\x1c\x1c\x1f',b'd\x91\x07\x07$X$1\x93\x07X1XQ$\x07TQT\x04'],
33+
'square_two':[b'\x1f\x1f\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x18\x1f\x1f\x1f\x1f\x03\x03\x03\x03\x1f\x1f\x1f\x1f\x18\x18\x18\x18\x1f\x1f\x01\x03\x07\x00\x00\x00\x00\x00\x18\x18\x18\x18\x18\x18\x18\x18\x1f\x1f\x00\x00\x00\x00\x1f\x1f\x18\x18\x18\x18\x18\x18\x1f\x1f',b'\x00Tg\x07\x84X$4\x93\x07X\x84XT$\x07TTT\x84'],
34+
'square_three':[b'\x1f\x1f\x1c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1c\x1f\x1f\x1f\x1f\x07\x07\x07\x07\x1f\x1f\x1f\x1f\x1c\x1c\x1c\x1c\x1f\x1f\x01\x03\x07\x0f\x00\x00\x00\x00\x1c\x1c\x1c\x1c\x1c\x1c\x1c\x1c\x1f\x1f\x00\x00\x00\x00\x1f\x1f\x1c\x1c\x1c\x1c\x1c\x1c\x1f\x1f',b'\x11Tg\x07\x84X$4\x93\x07X\x84XT$\x07TTT\x84'],
35+
'square_four':[b'\x1f\x1f\x1c\x1c\x00\x00\x00\x00\x00\x00\x00\x00\x1c\x1c\x1f\x1f\x1f\x1f\x0f\x0f\x0f\x0f\x1f\x1f\x1f\x1f\x1e\x1e\x1e\x1e\x1f\x1f\x01\x03\x07\x0f\x00\x00\x00\x00\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1f\x1f\x00\x00\x00\x00\x1f\x1f\x1e\x1e\x1e\x1e\x1e\x1e\x1f\x1f',b'\x11Tg\x07\x84X$4\x93\x07X\x84XT$\x07TTT\x84'],
36+
'square_five':[b'\x1f\x1f\x1f\x1c\x00\x00\x00\x00\x00\x00\x00\x00\x1c\x1f\x1f\x1f\x1f\x1f\x1f\x0f\x0f\x1f\x1f\x1f\x1f\x1f\x1f\x1e\x1e\x1f\x1f\x1f\x01\x03\x07\x0f\x0f\x00\x00\x00\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1f\x1f\x1f\x00\x00\x1f\x1f\x1f\x1e\x1e\x1e\x1e\x1e\x1f\x1f\x1f',b'\x11Tg\x07\x84X$4\x93\x07X\x84XT$\x07TTT\x84'],
37+
}
38+
39+
class LCD1602_BIGDIGIT(I2C_LCD1602):
40+
41+
def __init__(self, i2c, addr=0):
42+
self.i2c = i2c
43+
self.addr = addr
44+
super().__init__(i2c, addr)
45+
self.fontdat = (bytearray(64), bytearray(20))
46+
self.font('real')
47+
48+
def font(self, fontname):
49+
try:
50+
self.fontdat = BIGFONTS[fontname]
51+
self.write_cgram(self.fontdat[0])
52+
except:
53+
print('Load font error!')
54+
55+
# show one digit
56+
def digit(self, n=0, pos=0):
57+
n = n%10
58+
d1 = self.fontdat[1][n*2+0]
59+
d2 = self.fontdat[1][n*2+1]
60+
self.char((d1//16-2)%256, pos, 0)
61+
self.char((d1%16-2)%256)
62+
self.char((d2//16-2)%256, pos, 1)
63+
self.char((d2%16-2)%256)
64+
65+
# show number
66+
def number(self, num=1, bits=5):
67+
for i in range(bits):
68+
self.digit(num%10, 13-i*3)
69+
num //= 10

0 commit comments

Comments
 (0)