micropython tft display factory
So you have a nifty display like a bright TFT LCD, Charlieplex LED or NeoPixel matrix powered by MicroPython, but what if you want to draw shapes and graphics on it? Most MicroPython display modules only give you basic pixel drawing commands so it"s difficult to draw graphics yourself pixel by pixel. Luckily there"s a handy new MicroPython graphics module you can use to draw basic shapes and graphics on any pixel-based display! This module shows some of the power of MicroPython--a single module can work with any pixel display because of MicroPython"s dynamic language features. In this guide you"ll learn how to use a MicroPython graphics module to draw basic line, rectangle, circle, and triangle shapes on pixel-based displays like the ILI9341 TFT FeatherWing.
For this guide there"s no special hardware you need to draw graphics on a display. However you do need to have a pixel-based display of some sort (LED, TFT, NeoPixel--anything!) connected to your MicroPython board. Check out the following guides for details on how to use a few pixel displays with MicroPython:
First make sure you are running the latest version of MicroPython for your board. If you"re using the ESP8266 MicroPython port you must be running version
If your board supports USB mass storage, like the SAMD21 MicroPython port, then simply drag the .mpy and other files to the board"s file system (eject the drive and reset the board to make sure it is picked up by MicroPython).
The following section will show how to draw shapes on a ILI9341 TFT display like the TFT FeatherWing. You"ll see how the module can be adpated to draw on any pixel-based display by plugging in a new pixel drawing function too.
Next you"ll need to initialize your display so that you can draw pixels on it. Consult the MicroPython display guides for details on initializing displays.
To use the graphics and shape rendering module you"ll need to import its module and create an instance of the GFX class inside it. For example, to create a graphics renderer for the TFT FeatherWing above you would run:
A pixel drawing function to call when the GFX class needs to write a pixel. For this example the TFT display classpixelfunction is specified. It"s important to note that to use the graphics class youmusthave a function it can call to draw pixels! This function can live anywhere, like as a global function or on a class instance. The function needs to take at least a pixel x position and pixel y position parameter (in that order), and any number of other positional and keyword parameters after them (like color, intensity, etc.).
There are two optional parameters you can specify as keyword arguments too. They aren"t shown in this guide but see how the ILI9341 display example code uses them:
hline- Optionally set hline to a fast horizontal line drawing function for your display. This will improve the speed of drawing certain shapes. The function should take as parameters an x position and y position of the line start, then width of the line in pixels. Any number of optional color or other parameters can follow. If you don"t provide a hline function a slow default implementation that draws pixel by pixel will be used.
vline - Optionally set vline to a fast vertical line drawing function for your display. This will improve the speed of drawing certain shapes, especially filled shapes. The function should take as parameters an x position, y position of the line start, then height of the line in pixels. Any number of optional color or other parameters can follow. If you don"t provide a vline function a slow default implementation that draws pixel by pixel will be used.
Now the fun begins! After creating the GFX class you can call functions to draw shapes on the display. For example, draw a simple line across the entire display with the line function:
That"s all there is to basic shape drawing with the Adafruit MicroPython GFX module! With these basic shape primitives you can start to create interesting graphic projects, like a pong or breakout game using filled rectangles and circles. You can add text with the Adafruit MicroPython bitmap font module too!
Remember any pixel-based display can be used with this library, for example, an OLED display or NeoPixel, Charlieplex LED, or simple LED backpack matrix are great targets to use with the library. Just plug in each module"s pixel function and you"ll be drawing shapes in no time!
Timing the display.clear() function gets a time of about 1100ms to write a completely black screen. Results are worse when looking at displaying an image. I am taking one of the RAW images from the repo which are preconverted pngs and so there shouldn"t be any conversion needed at write time. When writing one to fill the screen I get a write time of 2680ms, over 2.5 seconds, which is a far cry from the 40ms you get, even allowing for the factor of a larger display.
I am very new to working with SPI displays so could be completely missing something but I appreciate the help you are offereing. How much work has to go into each of the drivers / would it be feasable for me to work on creating a driver to work with your GUI with some learning?
In this tutorial Tony Goodhew explains how to use the basic graphics procedures which are included in the display driver, and for the ambitious makers out there he also provides examples for advanced shapes and graphics!
All the other graphical and text objects we would like to display can be built from this single pixel instruction; such as lines, circles, rectangles, triangles and text strings at different sizes.
This is all carried out with code. Display manufacturers usually supply some of these procedures/methods but leave the rest up to the end user to construct.
At the top of our driver program we will always import a minimal set of libraries using this block at the top of our MicroPython script (we add even more later when we want to do advanced programs):
The third line here imports the Framebuffer library which includes several very useful routines to draw objects on the display. The garbage collection library, gc, has also been imported so that we can check how much memory is available.
Each program contains the screen driver code, sets up the buttons/joystick (if applicable), sets the width and height variables, loads the essential libraries, defines the colour (R, G, B) and clear (c) procedures, then displays some colour checking text like this:
Draw a dark grey rectangle in the centre of the screen. Draw 500 white pixels inside the square, none touching the edge. (Random was explained in the previous display tutorial.)
This is routine is very complicated. It splits the original triangle into two with a horizontal line and then fills them in. If you uncomment all the # lcd.show() lines and sleep instructions it will slow right down and you can see it working (unfortunately, the 2” display needs such a large buffer that there is not enough memory for the filled triangles code):
In the centre of the screen display a ‘bull’s eye’ circular target with a ‘gold’ centre, 4 other colours and scores 10, 8, 6, 4 and 2 written in the appropriate positions.
You may have noticed that on some screens the text is very small and difficult to read. In a following tutorial will add an extra font, with more characters, which we can display in different sizes.
This article was written by Tony Goodhew. Tony is a retired teacher of computing who starting writing code back in 1968 when it was called programming - he started with FORTRAN IV on an IBM 1130! An active Raspberry Pi community member, his main interests now are coding in MicroPython, travelling and photography.
I have a problem using this library. The only thing my display does so far is lighting up in a nice white. I am pretty new to python and GPIO so i can"t really complete the given data from the documentation to fullfill my needs.
What i need is a straight forward information on which pin on the display to connect to which pin on the raspberry pi 3b. What also would be great is information on which pins i can change in the code and which pins can be used for more than once in one project (like I2C or similar).
My hardware consists of a raspberry pi 3B and a red display (I dubble checked. It is the red "brother" to the black one shown in the first entry to this blog).
This guide is about DWIN HMI Touch Screen TFT LCD Display. HMI Means Human-Machine Interface. DWIN is specialized in making HMI Touch screen displays that are compatible with all microcontrollers like Arduino, STM32, PIC, and 8051 families of Microcontrollers.
This is a Getting Started tutorial with 7-inch DWIN HMI TFT LCD Display. We will see the architecture, features, board design, components, and specifications. We will also learn about the TTL & RS232 interfaces. Using the DGUS software you can create UI and with SD Card you can load the firmware on display memory.
One of the method to load the firmware to the T5L DWIN LCD Display is by using the SD Card. An SD Card of up to 16GB can be used to download the firmware files. We can easily insert the Micro SD card into the SD Card slot on the backside.
After copying the file, remove the SD Card from your computer and insert it into the SD Card slot of DWIN LCD Display. Then power the display using the USB Cable. The firmware downloading process will start automatically.
The next part of this tutorial includes creating UI and interfacing DWIN LCD Display with Arduino. For that you can follow the DWIN LCD Arduino Interfacing Guide.
The ESP32 touch sensor development kit, ESP32-Sense Kit, is used for evaluating and developing ESP32 touch sensor system. ESP32-Sense Kit consists of one motherboard and multiple daughterboards. The motherboard contains a display unit, a main control unit and a debug unit. The daughterboards have touch electrodes in different combinations or shapes, such as linear slider, wheel slider, matrix buttons and spring buttons, depending on the application scenarios. Users can design and add their own daughterboards for special usage cases.
ESP-WROOM-32 based development board with SH1106 OLED display (128×64 pixels), RJ-45 Ethernet connector, CAN-bus connector, Micro USB connector, USB-to-UART bridge, LiPo battery connector and charging circuit.
ESP32 development board with ePaper display, TI PCM5102A DAC, ICS43434 MEMS Microphone, CP2102N USB-to-UART bridge, microSD card slot, and LiPo charger.