0.96-inch LCD , using IDE’s built-in lcd.py code, the LCD screen displays as multiple segmented screen images in strip fragments, making it impossible to see the captured image, as shown in the following figure:
use the codes linked(https://blog.csdn.net/weixin_49038319/article/details/140162952),but img is wrong with colors
import sensor, image, time
from pyb import Pin, SPI
cs = Pin(“P3”, Pin.OUT_OD)
rst = Pin(“P7”, Pin.OUT_PP)
rs = Pin(“P8”, Pin.OUT_PP)
spi = SPI(2, SPI.MASTER, baudrate=int(1000000000), polarity=0, phase=0)
def write_command_byte(c):
cs.low()
rs.low()
spi.send(c)
cs.high()
def write_data_byte(c):
cs.low()
rs.high()
spi.send(c)
cs.high()
def write_command(c, *data):
write_command_byte(c)
if data:
for d in data: write_data_byte(d)
def write_image(img):
cs.low()
rs.high()
spi.send(img)
cs.high()
def lcd2():
write_command(0x2a)
write_data_byte(0x00)
write_data_byte(0x02)
write_data_byte(0x00)
write_data_byte(0x81)
write_command(0x2b)
write_data_byte(0x00)
write_data_byte(0x01)
write_data_byte(0x00)
write_data_byte(0xa0)
write_command(0x2c)
rst.low()
rst.high()
write_command(0x11) # Sleep Exit 退出休眠
write_command(0x36, 0xC0)
write_command(0x3A, 0x05)
write_command(0x29)
sensor.reset() # 初始化摄像头感光元件
sensor.set_pixformat(sensor.RGB565) # 必须这样写
sensor.set_framesize(sensor.QQVGA2) # must be this
sensor.skip_frames(time = 2000) # 让新设置生效
clock = time.clock() # 跟踪FPS帧率
while(True):
clock.tick() # 跟踪snapshots()之间经过的毫秒数
img = sensor.snapshot() # 拍一张照片并返回图像
write_command(0x2C) # 编写图像命令
lcd2()
write_image(img)
print(clock.fps())

