Home

Awesome

MicroPython HX1230

MicroPython library for HX1230 96x68 monochrome LCD displays.

Marketed as an upgrade of the Nokia 5110 LCD (PCD8544 84x48).

demo

Pinout

PinNameDescription
1RSTExternal reset input, active low
2CEChip enable, active low
3N/CNot connected
4DINSerial data input
5CLKSerial clock, up to 4 Mbits/s
6VCCSupply voltage 3.3-5V
7BLBacklight 3.3-5V
8GNDGround

You can save a GPIO pin by connecting RST to VCC and relying on the software reset command.

You can save another GPIO pin by connecting BL to VCC, but you will no longer be able to toggle the backlight in software.

Example

Basic Example

# Wemos D1 Mini ESP8266
from machine import Pin, SPI
import hx1230_fb

spi = SPI(1)
spi.init(baudrate=4000000, polarity=0, phase=0)
cs = Pin(2)
rst = Pin(0)

# backlight on
bl = Pin(4, Pin.OUT, value=1)

lcd = hx1230_fb.HX1230_FB_SPI(spi, cs, rst)

# test pattern (50% on)
lcd.data(bytearray([0x55, 0xAA] * 48 * 9))

# write some text using Frambuffer
lcd.fill(0)
lcd.show()
lcd.text('MicroPython',4,0,1)
lcd.text('HX1230',24,12,1)
lcd.text('96x68',28,24,1)
lcd.text('Mono LCD',16,36,1)
lcd.text('9-bit SPI',12,48,1)
lcd.text('Framebuffer',4,60,1)
lcd.show()

See /examples for more detailed examples.

Interfaces

There are 2 versions of this library. hx1230.py and hx1230_fb.py.

Both use either SPI or bit-bang SPI to communicate with the display.

SPI

The display uses 9-bit SPI, where the MSB is DC (data/command). Both data and commands are sent as 2 bytes, with 7 unused bits in the lower byte.

Data bits are sent MSB first. The least significant data bit is the top most pixel and the most significant data bit is the lowest pixel in the page on the display.

# VCC GND STM32F407ZGT6
from machine import Pin, SPI
spi = SPI(2)
spi.init(baudrate=2000000, polarity=0, phase=0)
cs = Pin('B12', Pin.OUT)
rst = Pin('B11', Pin.OUT)
bl = Pin('B1', Pin.OUT, value=1)  # backlight on

# without framebuffer
import hx1230
lcd = hx1230.HX1230_SPI(spi, cs, rst)
lcd.data([255,127,63,31,15,7,3,1])

# with framebuffer
import hx1230_fb
lcd = hx1230_fb.HX1230_FB_SPI(spi, cs, rst)
lcd.text('hello',0,0,1)
lcd.show()

Bit-Bang SPI

In this mode, exactly 9 bits are sent each time, with DC as the MSB.

# VCC GND STM32F407ZGT6
from machine import Pin
mosi = Pin('B15', Pin.OUT)
sck = Pin('B13', Pin.OUT)
cs = Pin('B12', Pin.OUT)
rst = Pin('B11', Pin.OUT)
bl = Pin('B1', Pin.OUT, value=1)  # backlight on

# without framebuffer
import hx1230
lcd = hx1230.HX1230_BBSPI(mosi, sck, cs, rst)
lcd.data([255,127,63,31,15,7,3,1])

# with framebuffer
import hx1230_fb
lcd = hx1230_fb.HX1230_FB_BBSPI(spi, cs, rst)
lcd.text('hello',0,0,1)
lcd.show()

Methods

Initialisation.

init(contrast, seg_remap, com_remap, start)

Reset the display. Performs a software reset when no RST pin provided.

reset(software=False)

Provide power to the display.

power(on=True)

Set the display contrast in the range 0-31. 0 is faint, 31 is dark.

contrast(contrast=15)

Invert the display.

invert(invert=True)

Turn the display on/off.

display(on=True)

Toggle test mode, which turns all pixels on (or off when in inverted mode).

test(on=True)

Set the pixel orientation. Seg remap to flip horizontal, com remap to flip vertical. Both seg remap and com remap to rotate 180 degrees. In normal operation, the black strip on the display is at the top.

orientation(seg_remap=False, com_remap=False)

Move the cursor for the next write. The x is column (0-95) and the y is the page (0-9). Pixels are arranged in horizontal pages of 96x8 pixels. The display is 68 pixels tall. 68 / 8 = 8.5, rounded up is 9 pages. The bottom 4 pixels are last page are ignored.

position(x, y)

Shifts the entire display down. Range is 0-63. Pixels wrap around.

start_line(line=0)

Fills the entire DDRAM with a colour. Then resets x,y position to 0,0

clear(color=0)

Writes a command to the display

command(command)

Writes data to the display

data(data)

Additional FrameBuffer methods

Fill the entire FrameBuffer with a colour.

fill(color)

Sets a pixel to the given colour. When color is not provided, gets the pixel colour.

pixel(x, y, color)

Shifts the display contents by the given vector. Previous contents remain.

scroll(dx, dy)

Writes text using the built in monospace 8x8 font

text(string, x, y, color)

Draws a line from the given coordinates, 1px thick, using the given colour.

line(x1, y1, x2, y2, color)

Draws a horizontal line, 1px thick, using the given colour.

hline(x, y, w, color)

Draws a vertical line, 1px thick, using the given colour.

vline(x, y, h, color)

Draws a 1px thick rectangle at the given location using the given colour.

rect(x, y, w, h, color)

Draws a filled rectangle at the given location using the given colour.

fill_rect(x, y, w, h, color)

Writes the entire framebuffer to the display.

show()

Commands

CommandD/CD7D6D5D4D3D2D1D0DescriptionInitial
Set power00010P3P2P1P0P=15: On, P=8: Off0x2F
Set contrast0100C4C3C2C1C0C=0: Faint, C=31: Dark0x8F
Set inverted01010011II=0: Normal, I=1: Inverted0xA6
All pixels on01010010AA=0: Normal, A=1: All On0xA4
Display enable01010111DD=0: Off, D=1: On0xAF
Set page010110Y2Y1Y0Y=0~7: Page0xB0
Set column low00000X3X2X1X0X=0~15: Column low 4 bits0x00
Set column high000010X6X5X4X=0~7: Column high 3 bits0x10
Set scan start001S5S4S3S2S1S0S=0~63: Start Line0x40
SEG remap01010000SS=0: Normal, S=1: remap0xA0
COM remap01100C000C=0: Normal, C=1: remap0xC0
Software reset0111000100xE2-
Write data1D7D6D5D4D3D2D1D0D=0~255: Data-

Addressing and orientation

The displays memory is compatible with the Framebuffer MONO_VLSB format.

You can remap the segment and common output pins to flip the display horizontally, vertical or both - which is the same as a rotate 180 deg.

orientation

Parts

Connections

WeMos D1 MiniHX1230 LCD
D3 (GPIO0)1 RST
D4 (GPIO2)2 CE
n/a3 N/C
D7 (GPIO13)4 DIN
D5 (GPIO14)5 CLK
3V36 VCC
D2 (GPIO4)7 BL
G8 GND
VCC GND ZGT6HX1230 LCD
B111 RST
B12 SPI2 CS2 CE
n/a3 N/C
B15 SPI2 MOSI4 DIN
B13 SPI2 SCK5 CLK
3V36 VCC
B17 BL
GND8 GND

Links

License

Licensed under the MIT License.