All Projects → russhughes → ili9342c_mpy

russhughes / ili9342c_mpy

Licence: other
ILI9342C Fast 'C' Driver for MicroPython (M5Stack Core)

Programming Languages

python
139335 projects - #7 most used programming language
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to ili9342c mpy

esp-idf-parallel-tft
8bit parallel TFT & 4-line resistance touch screen Driver for esp-idf using i2s paralell mode
Stars: ✭ 45 (+45.16%)
Mutual labels:  ili9341, ili9342
Raspberry-ili9325
Parallel TFT Shield Library for wiringPi
Stars: ✭ 40 (+29.03%)
Mutual labels:  ili9341, ili9342
wiringpi-tft-tool
TFT Command Line Tool for Raspberry Pi
Stars: ✭ 35 (+12.9%)
Mutual labels:  ili9341, ili9342
STM32 TFT 8bit
STM32F103 8bit parallel TFT Library for Arduino_STM32
Stars: ✭ 45 (+45.16%)
Mutual labels:  ili9341, ili9342
M5Stack-Air-Quality-ESPHome
ESPHome configuration for M5Stack's PM2.5 Air Quality Kit with the PMSA003 particulate matter sensor and the SHT20 temperature and humidity sensor
Stars: ✭ 19 (-38.71%)
Mutual labels:  ili9341, m5stack
nanoFramework.M5Stack
📦 Board support package for M5Stack, M5StickC and M5StickCPlus for .NET nanoFramework
Stars: ✭ 18 (-41.94%)
Mutual labels:  m5stack
Arduino RT-Thread
RT-Thread library optimized for Arduino.
Stars: ✭ 38 (+22.58%)
Mutual labels:  ili9341
M5StickVComputer
A pure python operating system on M5StickV
Stars: ✭ 31 (+0%)
Mutual labels:  m5stack
WeatherPi TFT
a weather display for a raspberry pi and a TFT display written in python3 and pygame
Stars: ✭ 66 (+112.9%)
Mutual labels:  ili9341
M5Stack-MultiApp-Advanced
A M5Stack firmware made on PlatformIO
Stars: ✭ 155 (+400%)
Mutual labels:  m5stack
ESP32-R4sGate-for-Redmond
ESP32 Ready4Sky (R4S) Gateway for Redmond+ devices
Stars: ✭ 117 (+277.42%)
Mutual labels:  m5stack
spectrum128 cpm
zx spectrum 128 emulation on stm32f407 + Grant Searle's CP/M system port ili9341 16 bit display
Stars: ✭ 29 (-6.45%)
Mutual labels:  ili9341
M5Stack LovyanToyBox
lovyan's toybox
Stars: ✭ 16 (-48.39%)
Mutual labels:  m5stack
Crypto Coin Ticker
Bitcoin and Multi Crypto Coin Price Ticker with candlestick chart (Binance API Websocket) - SD-Config File Version
Stars: ✭ 37 (+19.35%)
Mutual labels:  m5stack
M5Stack-NMEA-2000-Display-CAN-BUS
This repository shows how to use the M5Stack as NMEA 2000 Display and WiFi Gateway.
Stars: ✭ 29 (-6.45%)
Mutual labels:  m5stack
esp32 mmd
esp32でmmd
Stars: ✭ 93 (+200%)
Mutual labels:  m5stack
AZ-Touch-Pi0-Weather
AZ-Touch PiZero Weatherstation
Stars: ✭ 31 (+0%)
Mutual labels:  ili9341
M5StickCProjects
StickWatch2 and some interesting projects based on M5StickC
Stars: ✭ 57 (+83.87%)
Mutual labels:  m5stack
Raspberry-ili9340spi
ILI9340 SPI TFT Library & XPT2046 Touch Screen Library for Raspberry
Stars: ✭ 26 (-16.13%)
Mutual labels:  ili9341
lvgl STM32F103 encoder rtx5
LittleVgl test, Custom STM32F103RC breakout Board. ILI9341 display over SPI with DMA. rotary encoder. KEIL RTX v5.
Stars: ✭ 32 (+3.23%)
Mutual labels:  ili9341

ILI9342C Driver for MicroPython

Image

Video of Toaster bitmap demo

This is a work in progress

This driver is based on devbis' st7789_mpy driver. I modified the original driver for one of my projects to add:

  • Display Rotation and Mirroring
  • Scrolling
  • Drawing text using 8 and 16 bit wide bitmap fonts
  • Drawing text using Hershey vector fonts
  • Drawing JPG's, including a SLOW mode to draw jpg's larger than available ram using the TJpgDec - Tiny JPEG Decompressor R0.01d. from http://elm-chan.org/fsw/tjpgd/00index.html

Included are 12 bitmap fonts derived from classic pc text mode fonts, 26 Hershey vector fonts and several example programs that run on the M5Stack Core. This driver supports 320x240 displays.

Pre-compiled MicroPython firmware

The firmware directory contains MicroPython v1.16 firmware.bin files with the ILI9342C C driver and frozen python font files compiled with ESP-IDF 4.2 using the CMake build system.

Thanks go out to:

-- Russ

Overview

This is a driver for MicroPython to handle displays based on the ILI9342C chip.

Building instruction

Prepare build tools as described in the manual. You should follow the instruction for building MicroPython and ensure that you can build the firmware without this display module.

Clone this module alongside the MPY sources:

$ git clone https://github.com/russhughes/ili9342c_mpy.git

Go to MicroPython ports directory:

$ cd micropython/ports/esp32

And then compile the module setting USER_C_MODULES to the directory with the driver source code.

$ make USER_C_MODULES=../../../ili9342c_mpy/ all

Upload the resulting firmware to your device using the esptool.py program. (See MicroPython docs for more info)

CMake building instructions for MicroPython 1.14 and later

for ESP32:

$ cd micropython/ports/esp32

And then compile the module with specified USER_C_MODULES dir

$ make USER_C_MODULES=../../../../ili9342c_mpy/src/micropython.cmake all

Erase the target device if this is the first time uploading this firmware

$ make USER_C_MODULES=../../../../ili9342c_mpy/src/micropython.cmake erase

Upload the new firmware

$ make USER_C_MODULES=../../../../ili9342c_mpy/src/micropython.cmake deploy

Additional build parameters

Additional build parameters may be specified during the build, erase and upload operations by including them after the make command. For example you can specify the DEBUG flag, Upload BAUD rate, alternate partition.csv file for different flash sizes and the USB serial port.

  make -j 4 \
    DEBUG=1 \
    BOARD=M5CORE2 \
    BAUD=3000000 \
    PART_SRC=partitions-16MiB.csv \
    PORT=/dev/tty.SLAB_USBtoUART \
    USER_C_MODULES=../../../../ili9342c_mpy/src/micropython.cmake all

Examples

This module was tested on M5Stack Core and M5Stack Core 2 devices and should run on other ESP32 devices that are able run GENERIC MicroPython Firmware. See the examples folder for sample programs.

# ESP32

import machine
import ili9342c
spi = machine.SPI(2, baudrate=40000000, polarity=1, phase=1, sck=Pin(18), mosi=Pin(23)),
display = ili9342c.ILI9342C(
    spi,
    320,
    240,
    reset=Pin(33, Pin.OUT),
    cs=Pin(14, Pin.OUT),
    dc=Pin(27, Pin.OUT),
    backlight=Pin(32, Pin.OUT),
    rotation=0)

Methods

  • ili9342c.ILI9342C(spi, width, height, reset, dc, cs, backlight, rotation, buffer_size)

    required args:

      `spi` spi device
      `width` display width
      `height` display height
    

    optional args:

      `reset` reset pin
      `dc` dc pin
      `cs` cs pin
      `backlight` backlight pin
      `rotation`
      `buffer_size` 0= buffer dynamically allocated and freed as needed.
    
      Rotation | Orientation
      -------- | --------------------
         0     | 0 degrees
         1     | 90 degrees
         2     | 180 degrees
         3     | 270 degrees
         4     | 0 degrees mirrored
         5     | 90 degrees mirrored
         6     | 180 degrees mirrored
         7     | 270 degrees mirrored
    
    
      If buffer_size is specified it must be large enough to contain the largest
      bitmap and/or JPG used (Rows * Columns *2 bytes).
    

This driver supports only 16bit colors in RGB565 notation.

  • ILI9342C.fill(color)

    Fill the entire display with the specified color.

  • ILI9342C.pixel(x, y, color)

    Set the specified pixel to the given color.

  • ILI9342C.line(x0, y0, x1, y1, color)

    Draws a single line with the provided color from (x0, y0) to (x1, y1).

  • ILI9342C.hline(x, y, length, color)

    Draws a single horizontal line with the provided color and length in pixels. Along with vline, this is a fast version with reduced number of SPI calls.

  • ILI9342C.vline(x, y, length, color)

    Draws a single horizontal line with the provided color and length in pixels.

  • ILI9342C.rect(x, y, width, height, color)

    Draws a rectangle from (x, y) with corresponding dimensions

  • ILI9342C.fill_rect(x, y, width, height, color)

    Fill a rectangle starting from (x, y) coordinates

  • ILI9342C.blit_buffer(buffer, x, y, width, height)

    Copy bytes() or bytearray() content to the screen internal memory. Note: every color requires 2 bytes in the array

  • ILI9342C.text(bitap_font, s, x, y[, fg, bg])

    Write text to the display using the specified bitmap font with the coordinates as the upper-left corner of the text. The foreground and background colors of the text can be set by the optional arguments fg and bg, otherwise the foreground color defaults to WHITE and the background color defaults to BLACK. See the README.md in the fonts directory for example fonts.

  • ILI9342C.write(bitap_font, s, x, y[, fg, bg])

    Write text to the display using the specified proportional or Monospace bitmap font module with the coordinates as the upper-left corner of the text. The foreground and background colors of the text can be set by the optional arguments fg and bg, otherwise the foreground color defaults to WHITE and the background color defaults to BLACK. See the README.md in the truetype/fonts directory for example fonts. Returns the width of the string as printed in pixels.

    The font2bitmap utility creates compatible 1 bit per pixel bitmap modules from Proportional or Monospaced True Type fonts. The character size, foreground, background colors and the characters to include in the bitmap module may be specified as parameters. Use the -h option for details. If you specify a buffer_size during the display initialization it must be large enough to hold the widest character (HEIGHT * MAX_WIDTH * 2).

  • ILI9342C.write_len(bitap_font, s)

    Returns the width of the string in pixels if printed in the specified font.

  • ILI9342C.draw(vector_font, s, x, y[, fg, bg])

    Draw text to the display using the specified hershey vector font with the coordinates as the lower-left corner of the text. The foreground and background colors of the text can be set by the optional arguments fg and bg, otherwise the foreground color defaults to WHITE and the background color defaults to BLACK. See the README.md in the fonts directory for example fonts and the utils directory for a font conversion program.

  • LI9342C.jpg(jpg_filename, x, y [, method])

    Draw JPG file on the display at the given x and y coordinates as the upper left corner of the image. There memory required to decode and display a JPG can be considerable as a full screen 320x240 JPG would require at least 3100 bytes for the working area + 320x240x2 bytes of ram to buffer the image. Jpg images that would require a buffer larger than available memory can be drawn by passing SLOW for method. The SLOW method will draw the image a piece at a time using the Minimum Coded Unit (MCU, typically 8x8 pixels).

  • ILI9342C.bitmap(bitmap, x , y [, index])

    Draw bitmap using the specified x, y coordinates as the upper-left corner of the of the bitmap. The optional index parameter provides a method to select from multiple bitmaps contained a bitmap module. The index is used to calculate the offset to the beginning of the desired bitmap using the modules HEIGHT, WIDTH and BPP values.

    Bitmap Utilities in the utils folder

    imgtobitmap.py creates compatible bitmap modules from image files using the Pillow Python Imaging Library.

    monofont2bitmap.py creates compatible bitmap modules from Monospaced True Type fonts. See the inconsolata_16.py, inconsolata_32.py and inconsolata_64.py files in the examples/lib folder for sample modules and the mono_font.py program for an example on how to use the modules. The character sizes, bit per pixel, foreground, background colors and the characters to include as bitmaps may be specified as parameters. Use the -h option for details. Bits per pixel settings larger than one may be used to create antialiased characters at the expense of memory use. If you specify a buffer_size during the display initialization it must be large enough to hold the one character (HEIGHT * WIDTH * 2).

  • ILI9342C.width()

    Returns the current logical width of the display. (ie a 320x240 display rotated 90 degrees is 240 pixels wide)

  • ILI9342C.height()

    Returns the current logical height of the display. (ie a 320x240 display rotated 90 degrees is 320 pixels high)

  • ILI9342C.rotation(r)

    Set the rotates the logical display in a clockwise direction. 0-Portrait (0 degrees), 1-Landscape (90 degrees), 2-Inverse Portrait (180 degrees), 3-Inverse Landscape (270 degrees)

    Rotations 4-7 are mirrors of Rotations 0-3 for use with ILI9341 Displays 4-Portrait (0 degrees) Mirrored, 1-Landscape (90 degrees) Mirrored, 2-Inverse Portrait (180 degrees) Mirrored, 3-Inverse Landscape (270 degrees) Mirrored.

The module exposes predefined colors: BLACK, BLUE, RED, GREEN, CYAN, MAGENTA, YELLOW, and WHITE

Helper functions

  • color565(r, g, b)

    Pack a color into 2-bytes rgb565 format

  • map_bitarray_to_rgb565(bitarray, buffer, width, color=WHITE, bg_color=BLACK)

    Convert a bitarray to the rgb565 color buffer which is suitable for blitting. Bit 1 in bitarray is a pixel with color and 0 - with bg_color.

    This is a helper with a good performance to print text with a high resolution font. You can use an awesome tool https://github.com/peterhinch/micropython-font-to-py to generate a bitmap fonts from .ttf and use them as a frozen bytecode from the ROM memory.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].