Example: 50-Arduino-Boards/Giga-H7/50-Board-Control/spi_control.py
import sensor
import time
from machine import Pin
from machine import SPI
cs = Pin("D2", Pin.OPEN_DRAIN)
rst = Pin("D3", Pin.OUT)
rs = Pin("D4", Pin.OUT)
spi = SPI(5, baudrate=int(1000000000 / 66), 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()
rst.low()
time.sleep_ms(100)
rst.high()
time.sleep_ms(100)
write_command(0x11)
time.sleep_ms(120)
write_command(0x36, 0xC0)
write_command(0x3A, 0x05)
write_command(0x29)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA2)
sensor.skip_frames(time=2000)
clock = time.clock()
while True:
clock.tick()
img = sensor.snapshot()
write_command(0x2C)
write_image(img)
print(clock.fps())