MaixCAM MaixPy Screen Usage
Update history
Date | Version | Author | Update content |
---|---|---|---|
2024-03-31 | 1.0.0 | neucrack | Initial document |
Introduction
MaixPy provides the display
module, which can display images on the screen, and can also send images to MaixVision for display, facilitating debugging and development.
API Documentation
This document introduces commonly used methods. For more APIs, please refer to the display section of the API documentation.
Using the Screen
- Import the
display
module:
from maix import display
- Create a
Display
object:
disp = display.Display()
- Display an image:
disp.show(img)
Here, the img
object is a maix.image.Image
object, which can be obtained through the read
method of the camera
module, or loaded from an image file in the file system using the load
method of the image
module, or created as a blank image using the Image
class of the image
module.
For example:
from maix import image, display
disp = display.Display()
img = image.load("/root/dog.jpg")
disp.show(img)
Here, you need to transfer the dog.jpg
file to the /root
directory on the device first.
Display text:
from maix import image, display
disp = display.Display()
img = image.Image(320, 240)
img.draw_rect(0, 0, disp.width(), disp.height(), color=image.Color.from_rgb(255, 0, 0), thickness=-1)
img.draw_rect(10, 10, 100, 100, color=image.Color.from_rgb(255, 0, 0))
img.draw_string(10, 10, "Hello MaixPy!", color=image.Color.from_rgb(255, 255, 255))
disp.show(img)
Read an image from the camera and display it:
from maix import camera, display, app
disp = display.Display()
cam = camera.Camera(320, 240)
while not app.need_exit():
img = cam.read()
disp.show(img)
Here,
while not app.need_exit():
is used to facilitate exiting the loop when theapp.set_exit_flag()
method is called elsewhere.
Adjusting Backlight Brightness
You can manually adjust the backlight brightness in the system's "Settings" app. If you want to adjust the backlight brightness programmatically, you can use the set_backlight
method, with the parameter being the brightness percentage, ranging from 0 to 100:
disp.set_backlight(50)
Note that when the program exits and returns to the app selection interface, the backlight brightness will automatically revert to the system setting.
Displaying on MaixVision
When running code in MaixVision, images can be displayed on MaixVision for easier debugging and development.
When calling the show
method, the image will be automatically compressed and sent to MaixVision for display.
Of course, if you don't have a screen, or to save memory by not initializing the screen, you can also directly call the send_to_maixvision
method of the maix.display
object to send the image to MaixVision for display.
from maix import image,display
from maix import image,display
img = image.Image(320, 240)
disp = display.Display()
img.draw_rect(0, 0, img.width(), img.height(), color=image.Color.from_rgb(255, 0, 0), thickness=-1)
img.draw_rect(10, 10, 100, 100, color=image.Color.from_rgb(255, 0, 0))
img.draw_string(10, 10, "Hello MaixPy!", color=image.Color.from_rgb(255, 255, 255))
display.send_to_maixvision(img)
Replacing with Other Screen Models
If you wish to switch to a screen of a different size, you can consult and purchase from the store.
For MaixCAM, the following four screen options are currently supported:
- 2.3-inch 552x368 resolution capacitive touch screen: The default screen that comes with MaixCAM.
- 2.4-inch 640x480 resolution capacitive touch screen: The default screen that comes with MaixCAM-Pro.
- 5-inch 854x480 resolution non-touch screen: Note that this is a non-touch screen, similar in size to a mobile phone screen.
- 7-inch 1280x800 resolution capacitive touch screen: A large 7-inch screen, suitable for scenarios requiring a fixed screen display.
The image refresh time difference between different screens is about 1-5 milliseconds, which is not significant; the main difference lies in the image resolution, which affects image processing time.
When replacing the screen, you must also modify the configuration file; otherwise, mismatched refresh timing could cause screen burn-in (leaving a ghost image on the screen). It’s important to follow the steps strictly as outlined below. If screen burn-in occurs, don’t panic; powering off and leaving it overnight usually resolves the issue.
- Follow the system burning documentation to burn the system. Once completed, a USB drive will appear.
- Open the USB drive, and you will see a
uEnv.txt
file. - Edit the
uEnv.txt
file, modifying thepannel
key value as follows:- 2.3-inch (MaixCAM default screen):
st7701_hd228001c31
. - 2.4-inch (MaixCAM-Pro default screen):
st7701_lct024bsi20
. - 5-inch:
st7701_dxq5d0019_V0
, with the earlier (2023) test screen beingst7701_dxq5d0019b480854
. - 7-inch:
mtd700920b
, with the earlier (2023) test screen beingzct2133v1
.
- 2.3-inch (MaixCAM default screen):
- Save the
uEnv.txt
file, and click to eject the USB drive—do not just disconnect the power, or the file may be lost. - Press the board's
reset
button, or power cycle to restart.
The above method is the safest, ensuring the screen model is set correctly before powering on. If you have already burned the system, you can also modify the system’s /boot/uEnv.txt
file and then reboot.