Skip to content

Commit 1e7954e

Browse files
committed
HD44780 improve docs, move code comments to README.md.
1 parent d7cbefb commit 1e7954e

File tree

2 files changed

+60
-26
lines changed

2 files changed

+60
-26
lines changed

HD44780/README.md

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,74 @@
1-
# Driver for character-based LCD displays
1+
# 1. Driver for character-based LCD displays
22

33
This driver is for displays based on the Hitachi HD44780 driver: these are
44
widely available, typically in 16 character x 2 rows format.
55

6-
# Files
6+
# 2. Files
77

88
* `alcd.py` Driver, includes connection details.
99
* `alcdtest.py` Test/demo script.
1010

11-
Currently most of the documentation, including wiring details, is in the code.
11+
# 3. Typical wiring
1212

13-
# Display Formatting
13+
The driver uses 4-bit mode to economise on pins and wiring. Pins are arbitrary
14+
but this configuration was used in testing:
15+
16+
| LCD |Board |
17+
|:----:|:----:|
18+
| Rs | Y1 |
19+
| E | Y2 |
20+
| D7 | Y3 |
21+
| D6 | Y4 |
22+
| D5 | Y5 |
23+
| D4 | Y6 |
24+
25+
# 4. LCD Class
26+
27+
## 4.1 Constructor
28+
29+
This takes the following positional args:
30+
* `pinlist` A tuple of 6 strings, being the Pyboard pins used for signals
31+
`Rs`, `E`, `D4`, `D5`, `D6`, `D7` e.g. `('Y1','Y2','Y6','Y5','Y4','Y3')`.
32+
* `cols` The number of horizontal characters in the display (typically 16).
33+
* `rows` Default 2. Number of rows in the display.
34+
35+
## 4.2 Display updates
36+
37+
The class has no public properties or methods. The display is represented as an
38+
array of strings indexed by row. The row contents is replaced in its entirety.
39+
This is illustrated by the test program:
40+
41+
```python
42+
import uasyncio as asyncio
43+
import utime as time
44+
from alcd import LCD, PINLIST
45+
46+
lcd = LCD(PINLIST, cols = 16)
47+
48+
async def lcd_task():
49+
for secs in range(20, -1, -1):
50+
lcd[0] = 'MicroPython {}'.format(secs)
51+
lcd[1] = "{:11d}uS".format(time.ticks_us())
52+
await asyncio.sleep(1)
53+
54+
loop = asyncio.get_event_loop()
55+
loop.run_until_complete(lcd_task())
56+
```
57+
58+
The row contents may be read back by issuing
59+
60+
```python
61+
row0 = lcd[0]
62+
```
63+
64+
# 5. Display Formatting
1465

1566
The driver represents an LCD display as an array indexed by row. Assigning a
1667
string to a row causes that row to be updated. To write text to a specific
1768
column of the display it is recommended to use the Python string `format`
1869
method.
1970

20-
For exampls this function formats a string such that it is left-padded with
71+
For example this function formats a string such that it is left-padded with
2172
spaces to a given column and right-padded to the specified width (typically the
2273
width of the display). This ensures previous contents are overwritten.
2374

@@ -34,5 +85,5 @@ def print_at(st, col, width=16):
3485
>>>
3586
```
3687

37-
Similar use of the `format` method can be used to achieve more complex
88+
This use of the `format` method may be extended to achieve more complex
3889
tabulated data layouts.

HD44780/alcd.py

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,16 @@
1313
#
1414
# Author : Matt Hawkins
1515
# Site : http://www.raspberrypi-spy.co.uk
16-
#
17-
# Date : 26/07/2012
1816

1917
from machine import Pin
2018
import utime as time
2119
import uasyncio as asyncio
2220

23-
# **************************************************** LCD DRIVER ***************************************************
21+
# ********************************** GLOBAL CONSTANTS: TARGET BOARD PIN NUMBERS *************************************
2422

25-
"""
26-
Pin correspondence of default pinlist. This is supplied as an example
27-
Name LCD connector Board
28-
Rs 4 1 red Y1
29-
E 6 2 Y2
30-
D7 14 3 Y3
31-
D6 13 4 Y4
32-
D5 12 5 Y5
33-
D4 11 6 Y6
34-
"""
23+
# Supply board pin numbers as a tuple in order Rs, E, D4, D5, D6, D7
3524

36-
# *********************************** GLOBAL CONSTANTS: MICROPYTHON PIN NUMBERS *************************************
37-
38-
# Supply as board pin numbers as a tuple Rs, E, D4, D5, D6, D7
39-
40-
PINLIST = ('Y1','Y2','Y6','Y5','Y4','Y3')
25+
PINLIST = ('Y1','Y2','Y6','Y5','Y4','Y3') # As used in testing.
4126

4227
# **************************************************** LCD CLASS ****************************************************
4328
# Initstring:
@@ -121,5 +106,3 @@ async def runlcd(self): # Periodically check for changed tex
121106
await asyncio.sleep_ms(0) # Reshedule ASAP
122107
self.dirty[row] = False
123108
await asyncio.sleep_ms(20) # Give other coros a look-in
124-
125-

0 commit comments

Comments
 (0)