{"id":13802184,"url":"https://github.com/mcauser/micropython-hx1230","last_synced_at":"2025-07-28T05:32:49.585Z","repository":{"id":55942271,"uuid":"203081646","full_name":"mcauser/micropython-hx1230","owner":"mcauser","description":"MicroPython library for HX1230 96x68 LCD modules","archived":false,"fork":false,"pushed_at":"2020-12-05T12:24:35.000Z","size":2837,"stargazers_count":5,"open_issues_count":2,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-18T17:51:24.853Z","etag":null,"topics":["esp8266","hx1230","lcd","micropython","stm32f4","wemos-d1-mini"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mcauser.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-19T02:10:04.000Z","updated_at":"2020-02-06T11:26:49.000Z","dependencies_parsed_at":"2022-08-15T10:00:38.150Z","dependency_job_id":null,"html_url":"https://github.com/mcauser/micropython-hx1230","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcauser%2Fmicropython-hx1230","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcauser%2Fmicropython-hx1230/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcauser%2Fmicropython-hx1230/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcauser%2Fmicropython-hx1230/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcauser","download_url":"https://codeload.github.com/mcauser/micropython-hx1230/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227870644,"owners_count":17832425,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["esp8266","hx1230","lcd","micropython","stm32f4","wemos-d1-mini"],"created_at":"2024-08-04T00:01:38.463Z","updated_at":"2024-12-03T07:20:31.877Z","avatar_url":"https://github.com/mcauser.png","language":"Python","readme":"# MicroPython HX1230\n\nMicroPython library for HX1230 96x68 monochrome LCD displays.\n\nMarketed as an upgrade of the [Nokia 5110 LCD](https://github.com/mcauser/micropython-pcd8544) (PCD8544 84x48).\n\n![demo](docs/demo.jpg)\n\n#### Pinout\n\nPin | Name | Description\n:--:|:----:|:--------------------------------\n1   | RST  | External reset input, active low\n2   | CE   | Chip enable, active low\n3   | N/C  | Not connected\n4   | DIN  | Serial data input\n5   | CLK  | Serial clock, up to 4 Mbits/s\n6   | VCC  | Supply voltage 3.3-5V\n7   | BL   | Backlight 3.3-5V\n8   | GND  | Ground\n\nYou can save a GPIO pin by connecting RST to VCC and relying on the software reset command.\n\nYou can save another GPIO pin by connecting BL to VCC, but you will no longer be able to toggle the backlight in software.\n\n## Example\n\n**Basic Example**\n\n```python\n# Wemos D1 Mini ESP8266\nfrom machine import Pin, SPI\nimport hx1230_fb\n\nspi = SPI(1)\nspi.init(baudrate=4000000, polarity=0, phase=0)\ncs = Pin(2)\nrst = Pin(0)\n\n# backlight on\nbl = Pin(4, Pin.OUT, value=1)\n\nlcd = hx1230_fb.HX1230_FB_SPI(spi, cs, rst)\n\n# test pattern (50% on)\nlcd.data(bytearray([0x55, 0xAA] * 48 * 9))\n\n# write some text using Frambuffer\nlcd.fill(0)\nlcd.show()\nlcd.text('MicroPython',4,0,1)\nlcd.text('HX1230',24,12,1)\nlcd.text('96x68',28,24,1)\nlcd.text('Mono LCD',16,36,1)\nlcd.text('9-bit SPI',12,48,1)\nlcd.text('Framebuffer',4,60,1)\nlcd.show()\n```\n\nSee [/examples](/examples) for more detailed examples.\n\n## Interfaces\n\nThere are 2 versions of this library. `hx1230.py` and `hx1230_fb.py`.\n\n* hx1230.py - base version, does not extend anything.\n* hx1230_fb.py - extends framebuf.FrameBuffer and provides additional drawing methods.\n\nBoth use either SPI or bit-bang SPI to communicate with the display.\n\n### SPI\n\nThe display uses 9-bit SPI, where the MSB is DC (data/command).\nBoth data and commands are sent as 2 bytes, with 7 unused bits in the lower byte.\n\nData bits are sent MSB first. The least significant data bit is the top most pixel\nand the most significant data bit is the lowest pixel in the page on the display.\n\n```python\n# VCC GND STM32F407ZGT6\nfrom machine import Pin, SPI\nspi = SPI(2)\nspi.init(baudrate=2000000, polarity=0, phase=0)\ncs = Pin('B12', Pin.OUT)\nrst = Pin('B11', Pin.OUT)\nbl = Pin('B1', Pin.OUT, value=1)  # backlight on\n\n# without framebuffer\nimport hx1230\nlcd = hx1230.HX1230_SPI(spi, cs, rst)\nlcd.data([255,127,63,31,15,7,3,1])\n\n# with framebuffer\nimport hx1230_fb\nlcd = hx1230_fb.HX1230_FB_SPI(spi, cs, rst)\nlcd.text('hello',0,0,1)\nlcd.show()\n```\n\n### Bit-Bang SPI\n\nIn this mode, exactly 9 bits are sent each time, with DC as the MSB.\n```python\n# VCC GND STM32F407ZGT6\nfrom machine import Pin\nmosi = Pin('B15', Pin.OUT)\nsck = Pin('B13', Pin.OUT)\ncs = Pin('B12', Pin.OUT)\nrst = Pin('B11', Pin.OUT)\nbl = Pin('B1', Pin.OUT, value=1)  # backlight on\n\n# without framebuffer\nimport hx1230\nlcd = hx1230.HX1230_BBSPI(mosi, sck, cs, rst)\nlcd.data([255,127,63,31,15,7,3,1])\n\n# with framebuffer\nimport hx1230_fb\nlcd = hx1230_fb.HX1230_FB_BBSPI(spi, cs, rst)\nlcd.text('hello',0,0,1)\nlcd.show()\n```\n\n## Methods\n\nInitialisation.\n```python\ninit(contrast, seg_remap, com_remap, start)\n```\n\nReset the display. Performs a software reset when no RST pin provided.\n```python\nreset(software=False)\n```\n\nProvide power to the display.\n```python\npower(on=True)\n```\n\nSet the display contrast in the range 0-31. 0 is faint, 31 is dark.\n```python\ncontrast(contrast=15)\n```\n\nInvert the display.\n```python\ninvert(invert=True)\n```\n\nTurn the display on/off.\n```python\ndisplay(on=True)\n```\n\nToggle test mode, which turns all pixels on (or off when in inverted mode).\n```python\ntest(on=True)\n```\n\nSet the pixel orientation. Seg remap to flip horizontal, com remap to flip vertical.\nBoth seg remap and com remap to rotate 180 degrees.\nIn normal operation, the black strip on the display is at the top.\n```python\norientation(seg_remap=False, com_remap=False)\n```\n\nMove the cursor for the next write.\nThe x is column (0-95) and the y is the page (0-9).\nPixels are arranged in horizontal pages of 96x8 pixels.\nThe display is 68 pixels tall. 68 / 8 = 8.5, rounded up is 9 pages.\nThe bottom 4 pixels are last page are ignored.\n```python\nposition(x, y)\n```\n\nShifts the entire display down. Range is 0-63. Pixels wrap around.\n```python\nstart_line(line=0)\n```\n\nFills the entire DDRAM with a colour. Then resets x,y position to 0,0\n```python\nclear(color=0)\n```\n\nWrites a command to the display\n```python\ncommand(command)\n```\n\nWrites data to the display\n```python\ndata(data)\n```\n\n## Additional FrameBuffer methods\n\nFill the entire FrameBuffer with a colour.\n```python\nfill(color)\n```\n\nSets a pixel to the given colour. When color is not provided, gets the pixel colour.\n```python\npixel(x, y, color)\n```\n\nShifts the display contents by the given vector. Previous contents remain.\n```python\nscroll(dx, dy)\n```\n\nWrites text using the built in monospace 8x8 font\n```python\ntext(string, x, y, color)\n```\n\nDraws a line from the given coordinates, 1px thick, using the given colour.\n```python\nline(x1, y1, x2, y2, color)\n```\n\nDraws a horizontal line, 1px thick, using the given colour.\n```python\nhline(x, y, w, color)\n```\n\nDraws a vertical line, 1px thick, using the given colour.\n```python\nvline(x, y, h, color)\n```\n\nDraws a 1px thick rectangle at the given location using the given colour.\n```python\nrect(x, y, w, h, color)\n```\n\nDraws a filled rectangle at the given location using the given colour.\n```python\nfill_rect(x, y, w, h, color)\n```\n\nWrites the entire framebuffer to the display.\n```python\nshow()\n```\n\n## Commands\n\nCommand         | D/C | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 | Description                | Initial\n--------------- | --- | -- | -- | -- | -- | -- | -- | -- | -- | -------------------------- | -------\nSet power       | 0   | 0  | 0  | 1  | 0  | P3 | P2 | P1 | P0 | P=15: On, P=8: Off         | 0x2F\nSet contrast    | 0   | 1  | 0  | 0  | C4 | C3 | C2 | C1 | C0 | C=0: Faint, C=31: Dark     | 0x8F\nSet inverted    | 0   | 1  | 0  | 1  | 0  | 0  | 1  | 1  | I  | I=0: Normal, I=1: Inverted | 0xA6\nAll pixels on   | 0   | 1  | 0  | 1  | 0  | 0  | 1  | 0  | A  | A=0: Normal, A=1: All On   | 0xA4\nDisplay enable  | 0   | 1  | 0  | 1  | 0  | 1  | 1  | 1  | D  | D=0: Off, D=1: On          | 0xAF\nSet page        | 0   | 1  | 0  | 1  | 1  | 0  | Y2 | Y1 | Y0 | Y=0~7: Page                | 0xB0\nSet column low  | 0   | 0  | 0  | 0  | 0  | X3 | X2 | X1 | X0 | X=0~15: Column low 4 bits  | 0x00\nSet column high | 0   | 0  | 0  | 0  | 1  | 0  | X6 | X5 | X4 | X=0~7: Column high 3 bits  | 0x10\nSet scan start  | 0   | 0  | 1  | S5 | S4 | S3 | S2 | S1 | S0 | S=0~63: Start Line         | 0x40\nSEG remap       | 0   | 1  | 0  | 1  | 0  | 0  | 0  | 0  | S  | S=0: Normal, S=1: remap    | 0xA0\nCOM remap       | 0   | 1  | 1  | 0  | 0  | C  | 0  | 0  | 0  | C=0: Normal, C=1: remap    | 0xC0\nSoftware reset  | 0   | 1  | 1  | 1  | 0  | 0  | 0  | 1  | 0  | 0xE2                       | -\nWrite data      | 1   | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 | D=0~255: Data              | -\n\n## Addressing and orientation\n\nThe displays memory is compatible with the Framebuffer [MONO_VLSB](http://docs.micropython.org/en/latest/library/framebuf.html#framebuf.framebuf.MONO_VLSB) format.\n\nYou 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.\n\n![orientation](docs/orientation.jpg)\n\n## Parts\n\n* [HX1230](https://www.aliexpress.com/item/32810394997.html) $2.60 AUD\n* [WeMos D1 Mini](https://www.aliexpress.com/item/32529101036.html) $5.25 AUD\n* [VCC GND STM32F407VGT6](https://www.aliexpress.com/item/33012284134.html) $35.52 AUD\n\n## Connections\n\nWeMos D1 Mini | HX1230 LCD\n------------- | ----------\nD3 (GPIO0)    | 1 RST\nD4 (GPIO2)    | 2 CE\nn/a           | 3 N/C\nD7 (GPIO13)   | 4 DIN\nD5 (GPIO14)   | 5 CLK\n3V3           | 6 VCC\nD2 (GPIO4)    | 7 BL\nG             | 8 GND\n\nVCC GND ZGT6  | HX1230 LCD\n------------- | ----------\nB11           | 1 RST\nB12 SPI2 CS   | 2 CE\nn/a           | 3 N/C\nB15 SPI2 MOSI | 4 DIN\nB13 SPI2 SCK  | 5 CLK\n3V3           | 6 VCC\nB1            | 7 BL\nGND           | 8 GND\n\n## Links\n\n* [WeMos D1 Mini](https://wiki.wemos.cc/products:d1:d1_mini)\n* [micropython.org](http://micropython.org)\n* [Docs on framebuf](http://docs.micropython.org/en/latest/library/framebuf.html)\n* [HX1230 datasheet in Chinese](docs/hx1230_datasheet.pdf)\n* [HX1230 datasheet converted to English](docs/hx1230_datasheet_en.pdf)\n\n## License\n\nLicensed under the [MIT License](http://opensource.org/licenses/MIT).\n","funding_links":[],"categories":["Libraries"],"sub_categories":["Display"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcauser%2Fmicropython-hx1230","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcauser%2Fmicropython-hx1230","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcauser%2Fmicropython-hx1230/lists"}