This article discusses the use of the Sipeed M1W dock suit’s TFT-LCD module via the lcd class (MaixPy’s lcd class) built into the MaixPy, a module that allows programmers to use it with the efficiency of that class is high.
lcd class
The lcd class is a class for interfacing with TFT that has a port to plug into the board. The items within the class are as follows:
object <module 'lcd'> is of type module
__name__ -- lcd
init -- <function>
deinit -- <function>
width -- <function>
height -- <function>
type -- <function>
freq -- <function>
set_backlight -- <function>
get_backlight -- <function>
display -- <function>
clear -- <function>
rotation -- <function>
draw_string -- <function>
fill_rectangle -- <function>
XY_RLUD -- 0
YX_RLUD -- 32
XY_LRUD -- 64
YX_LRUD -- 96
XY_RLDU -- 128
YX_RLDU -- 160
XY_LRDU -- 192
YX_LRDU -- 224
BLACK -- 0
NAVY -- 3840
DARKGREEN -- 57347
DARKCYAN -- 61187
MAROON -- 120
PURPLE -- 3960
OLIVE -- 57467
LIGHTGREY -- 6342
DARKGREY -- 61307
BLUE -- 7936
GREEN -- 57351
CYAN -- 65287
RED -- 248
MAGENTA -- 8184
YELLOW -- 57599
WHITE -- 65535
ORANGE -- 8445
GREENYELLOW -- 58799
PINK -- 8184
Constant
These are constants for setting the display if the displayed display is reversed, such as alternating left characters. or on the bottom, etc.
- XY_RLUD
- YX_RLUD
- XY_LRUD
- YX_LRUD
- XY_RLDU
- YX_RLDU
- XY_LRDU
- YX_LRDU
Color value
The color values that the lcd class provides are as follows:
- BLACK
- NAVY
- DARKGREEN
- DARKCYAN
- MAROON
- PURPLE
- OLIVE
- LIGHTGREY
- DARKGREY
- BLUE
- GREEN
- CYAN
- RED
- MAGENTA
- YELLOW
- WHITE
- ORANGE
- GREENYELLOW
- PINK
Commands
The command group of the lcd class is as follows.
init()
This is the command to start the display.
deinit()
It is a command to deactivate the display.
width()
It is a command to read the width of the display
height()
It is a command to read the height of the display
type()
Returns the display type. But at the moment it doesn’t support different types of displays.
- 0 no display
- 1 has display
freq()
For reading the clock frequency in the data transmission between the display and the board.
freq(freq_value)
For resetting the clock frequency as required
set_backlight( status )
If the status is True, it will turn on the TFT illumination, if false, it will turn off the illumination.
get_backlight()
It is a command to read the status of the TFT illumination LED.
display( img )
Bring the buffer values stored in the img to display on the display.
clear( color_value )
Clear the display with the specified color value. If not, it will be black.
rotation( x )
Rotate the screen.
draw_string(x,y,text, text_color, bg_color )
Displays text at position (x,y) with a given color.
fill_rectangle( x, y, w, h, color )
Draw a solid rectangle in the given color.
Example Code
lcd1.py
Example showing background color change with text display After that, rotate the display with rotation() and display the following message:
# lcd1.py - By: JarutEx - Sat Oct 2 2021
import lcd,time,sensor
if (lcd.type() == 0):
print("Error : no lcd shield!")
while (True):
pass
lcd.freq(16000000)
lcd.init(color=(255,0,0))
colors = [
lcd.BLACK,
lcd.NAVY,
lcd.DARKGREEN,
lcd.DARKCYAN,
lcd.MAROON,
lcd.PURPLE,
lcd.OLIVE,
lcd.LIGHTGREY,
lcd.DARKGREY,
lcd.BLUE,
lcd.GREEN,
lcd.CYAN,
lcd.RED,
lcd.MAGENTA,
lcd.YELLOW,
lcd.WHITE,
lcd.ORANGE,
lcd.GREENYELLOW,
lcd.PINK
]
lcd.set_backlight(True)
for color in colors:
lcd.clear(color)
lcd.draw_string(40,100,"JarutEx",lcd.WHITE,color)
lcd.draw_string(40,120,"JarutEx",lcd.BLACK,color)
time.sleep(1)
lcd.clear(lcd.RED)
lcd.rotation(0)
lcd.draw_string(30, 30, "JarutEx", lcd.WHITE, lcd.RED)
time.sleep(1)
lcd.rotation(1)
lcd.draw_string(60, 60, "JarutExy", lcd.WHITE, lcd.RED)
time.sleep(1)
lcd.rotation(2)
lcd.draw_string(120, 60, "JarutEx", lcd.WHITE, lcd.RED)
time.sleep(1)
lcd.rotation(3)
lcd.draw_string(120, 120, "JarutExy", lcd.WHITE, lcd.RED)
time.sleep(1)
if (lcd.get_backlight()):
lcd.set_backlight( False )
In the first phase, changing the background color will result as shown in Figure 2, and the rotation of the display and display of the text will be as shown in Figure 3.
lcd2.py
An example of this program is to load a JPG image to display on the display by saving the image named pmai.jpg in the microSD. After that when powering the board, the board will report the availability of the microSD as shown in Figure 4, which means the card is ready to use.
After that, test the operation by using the program lcd2 as follows to load the image with the command image.Image(“/sd/pmai.jpg”) and display the image with the command lcd.display( img ) will get the result as shown in Figure 5.
# lcd2 - By: JaritEx - Sun Oct 3 2021
import image, time, lcd
clock = time.clock()
print("lcd freq. = {}Hz".format(lcd.freq()))
lcd.freq(80000000)
lcd.init(color=(255,0,0))
img = image.Image("/sd/pmai.jpg")
while(True):
clock.tick()
lcd.display(img)
Conclusion
From this article, you will find that MaixPy does not have a very basic set of commands that can be displayed. This is because the image processing instruction is mainly in the image class, however, it will be found that with the LCD instruction set, it is enough to display at a considerable speed and enough for basic use. Finally, have fun with programming.
If you want to talk with us, feel free to leave comments below!!
(C) 2020-2021, By Jarut Busarathid and Danai Jedsadathitikul
Updated 2021-12-22