{"id":13802190,"url":"https://github.com/devbis/st7789_mpy","last_synced_at":"2025-04-09T15:06:45.633Z","repository":{"id":52939299,"uuid":"182564817","full_name":"devbis/st7789_mpy","owner":"devbis","description":"Fast pure-C driver for MicroPython that can handle display modules on ST7789 chip","archived":false,"fork":false,"pushed_at":"2024-01-23T08:45:47.000Z","size":119,"stargazers_count":213,"open_issues_count":10,"forks_count":43,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-09T15:06:41.585Z","etag":null,"topics":["esp32","esp8266","micropython","micropython-driver","st7789"],"latest_commit_sha":null,"homepage":null,"language":"C","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/devbis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-04-21T17:49:52.000Z","updated_at":"2025-04-03T13:46:32.000Z","dependencies_parsed_at":"2024-01-29T19:30:24.594Z","dependency_job_id":null,"html_url":"https://github.com/devbis/st7789_mpy","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/devbis%2Fst7789_mpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devbis%2Fst7789_mpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devbis%2Fst7789_mpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devbis%2Fst7789_mpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devbis","download_url":"https://codeload.github.com/devbis/st7789_mpy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248055284,"owners_count":21040157,"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":["esp32","esp8266","micropython","micropython-driver","st7789"],"created_at":"2024-08-04T00:01:38.728Z","updated_at":"2025-04-09T15:06:45.617Z","avatar_url":"https://github.com/devbis.png","language":"C","funding_links":[],"categories":["Libraries"],"sub_categories":["Display"],"readme":"ST7789 Driver for MicroPython\n=============================\n\n\nOverview\n--------\nThis is a driver for MicroPython to handle cheap displays\nbased on ST7789 chip.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/devbis/st7789_mpy/master/docs/ST7789.jpg\" alt=\"ST7789 display photo\"/\u003e\n\u003c/p\u003e\n\nIt supports both 240x240 and 135x240 variants of displays.\n\nIt is written in pure C, so you have to build\nfirmware by yourself.\nESP8266, ESP32, and STM32 ports are supported for now.\n\n\nBuilding instruction\n---------------------\n\nPrepare build tools as described in the manual.\nYou should follow the instruction for building MicroPython and\nensure that you can build the firmware without this display module.\n\nClone this module alongside the MPY sources:\n\n    git clone https://github.com/devbis/st7789_mpy.git\n\nGo to MicroPython ports directory and for ESP8266 run:\n\n    cd micropython/ports/esp8266\n\nfor ESP32:\n\n    cd micropython/ports/esp32\n\nAnd then compile the module with specified USER_C_MODULES dir\n\n    make USER_C_MODULES=../../../st7789_mpy/ all\n\n\nIf you have other user modules, copy the st7789_driver/st7789 to\nthe user modules directory\n\nUpload the resulting firmware to your MCU as usual with esptool.py\n(See\n[MicroPython docs](http://docs.micropython.org/en/latest/esp8266/tutorial/intro.html#deploying-the-firmware)\nfor more info)\n\n    make deploy\n\nWorking examples\n----------------\n\nThis module was tested on ESP32 and ESP8266 MCUs.\n\nYou have to provide `machine.SPI` object and at least two pins for RESET and\nDC pins on the screen for the display object.\n\n\n    # ESP 8266\n\n    import machine\n    import st7789\n    spi = machine.SPI(1, baudrate=40000000, polarity=1)\n    display = st7789.ST7789(spi, 240, 240, reset=machine.Pin(5, machine.Pin.OUT), dc=machine.Pin(4, machine.Pin.OUT))\n    display.init()\n\n\nFor ESP32 modules you have to provide specific pins for SPI.\nUnfortunately, I was unable to run this display on SPI(1) interface.\nFor machine.SPI(2) == VSPI you have to use\n\n- CLK: Pin(18)\n- MOSI: Pin(23)\n\nOther SPI pins are not used.\n\n\n    # ESP32\n\n    import machine\n    import st7789\n    spi = machine.SPI(2, baudrate=40000000, polarity=1, sck=machine.Pin(18), mosi=machine.Pin(23))\n    display = st7789.ST7789(spi, 240, 240, reset=machine.Pin(4, machine.Pin.OUT), dc=machine.Pin(2, machine.Pin.OUT))\n    display.init()\n\n\nI couldn't run the display on an SPI with baudrate higher than 40MHZ\n\nAlso, the driver was tested on STM32 board:\n\n\n    # STM32\n    \n    import machine\n    import st7789\n    spi = machine.SPI(2, baudrate=12000000, polarity=1)\n    display = st7789.ST7789(spi, 135, 240, reset=machine.Pin('B3', machine.Pin.OUT), dc=machine.Pin('B6', machine.Pin.OUT))\n    display.init()\n\n\nMethods\n-------------\n\nThis driver supports only 16bit colors in RGB565 notation.\n\n\n- `ST7789.fill(color)`\n\n  Fill the entire display with the specified color.\n\n- `ST7789.pixel(x, y, color)`\n\n  Set the specified pixel to the given color.\n\n- `ST7789.line(x0, y0, x1, y1, color)`\n\n  Draws a single line with the provided `color` from (`x0`, `y0`) to\n  (`x1`, `y1`).\n\n- `ST7789.hline(x, y, length, color)`\n\n  Draws a single horizontal line with the provided `color` and `length`\n  in pixels. Along with `vline`, this is a fast version with reduced\n  number of SPI calls.\n\n- `ST7789.vline(x, y, length, color)`\n\n  Draws a single horizontal line with the provided `color` and `length`\n  in pixels.\n\n- `ST7789.rect(x, y, width, height, color)`\n\n  Draws a rectangle from (`x`, `y`) with corresponding dimensions\n\n- `ST7789.fill_rect(x, y, width, height, color)`\n\n  Fill a rectangle starting from (`x`, `y`) coordinates\n\n- `ST7789.blit_buffer(buffer, x, y, width, height)`\n\n  Copy bytes() or bytearray() content to the screen internal memory.\n  Note: every color requires 2 bytes in the array\n\nAlso, the module exposes predefined colors:\n  `BLACK`, `BLUE`, `RED`, `GREEN`, `CYAN`, `MAGENTA`, `YELLOW`, and `WHITE`\n\n\nHelper functions\n----------------\n\n- `color565(r, g, b)`\n\n  Pack a color into 2-bytes rgb565 format\n\n- `map_bitarray_to_rgb565(bitarray, buffer, width, color=WHITE, bg_color=BLACK)`\n\n  Convert a bitarray to the rgb565 color buffer which is suitable for blitting.\n  Bit 1 in bitarray is a pixel with `color` and 0 - with `bg_color`.\n\n  This is a helper with a good performance to print text with a high\n  resolution font. You can use an awesome tool\n  https://github.com/peterhinch/micropython-font-to-py\n  to generate a bitmap fonts from .ttf and use them as a frozen bytecode from\n  the ROM memory.\n\nPerformance\n-----------\n\nFor the comparison I used an excellent library for Arduino\nthat can handle this screen.\n\nhttps://github.com/ananevilya/Arduino-ST7789-Library/\n\nAlso, I used my slow driver for this screen, written in pure python.\n\nhttps://github.com/devbis/st7789py_mpy/\n\nI used these modules to draw a line from 0,0 to 239,239\nThe table represents the time in milliseconds for each case\n\n|         | Arduino-ST7789 | st7789py_mpy | st7789_mpy    |\n|---------|----------------|--------------|---------------|\n| ESP8266 | 26             | 450          | 12            |\n| ESP32   | 23             | 450          | 47            |\n\n\nAs you can see, the ESP32 module draws a line 4 times slower than\nthe older ESP8266 module.\n\n\nTroubleshooting\n---------------\n\n#### Overflow of iram1_0_seg\n\nWhen building a firmware for esp8266 you can see this failure message from\nthe linker:\n\n    LINK build/firmware.elf\n    xtensa-lx106-elf-ld: build/firmware.elf section `.text' will not fit in region `iram1_0_seg'\n    xtensa-lx106-elf-ld: region `iram1_0_seg' overflowed by 292 bytes\n    Makefile:192: recipe for target 'build/firmware.elf' failed\n\nTo fix this issue, you have to put st7789 module to irom0 section.\nEdit `esp8266_common.ld` file in the `ports/esp8266` dir and add a line\n\n    *st7789/*.o(.literal* .text*)\n\nin the `.irom0.text : ALIGN(4)` section\n\n\n#### Unsupported dimensions\n\nThis driver supports only 240x240 and 135x240 pixel displays.\nIf you have a display with an unsupported resolution, you can pass\n`xstart` and `ystart` parameters to the display constructor to set the\nrequired offsets.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevbis%2Fst7789_mpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevbis%2Fst7789_mpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevbis%2Fst7789_mpy/lists"}