First program: Use screen and camera
The development board has a matching camera and screen, please check whether the hardware connection is correct before powering on(Align according to the No. 1 pin marked on the cable)
Then power on, open the serial terminal, press the keyboard Ctrl+E
, and paste the following code:
import sensor, lcd
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.run(1)
sensor.skip_frames()
lcd.init(freq=15000000)
while(True):
lcd.display(sensor.snapshot())
Press the keyboard Ctrl+D
to start running the code
You will find that the screen is lit, and the picture taken by the camera is displayed
If it displays reset fail
, the camera is not connected well, or the camera is damaged, or check whether an unsupported camera is used
The meaning of the above programs can be found in the API manual, which can be found in the directory on the left, or you can use the search box in the upper left corner to search.
Now explain the above program:
import sensor, lcd
: first import the built-insensor
(camera) library andlcd
(screen) librarysensor.reset()
: Initialize the camera. If it fails, check the hardwaresensor.set_pixformat(sensor.RGB565)
: Set the camera toRGB565
format, the default is to useRGB565
sensor.set_framesize(sensor.QVGA)
: The resolution isQVGA
, that is,320x240
sensor.run(1)
: start to run, it is not necessary to call it in the current version, the camera will automatically start to run after the above settings are completedsensor.skip_frames()
: The image quality is not stable when the camera is just started, so some images are skippedlcd.init(freq=15000000)
: Initialize the LCD, here is a parameter calledfreq
, frequency, which specifies the clock frequency for driving the LCD, here is15MHz
, which can be adjusted according to the hardware performancewhile(True)
: This is a loop, the code inside the loop will be run continuouslysensor.snapshot()
: fetch a frame of image data from the camera, the return value is an image objectlcd.display()
: display image to LCDlcd.display(sensor.snapshot())
: here is to execute the image acquisition in brackets first, and the return value is directly displayed as a parameter to the LCD