Example: 50-Arduino-Boards/Portenta-H7/50-Board-Control/spi_control.py
import csi
import time
from pyb import Pin, SPI
cs = Pin("D11", Pin.OUT_OD)
rst = Pin("D12", Pin.OUT_PP)
rs = Pin("D13", Pin.OUT_PP)
spi = SPI(2, SPI.MASTER, 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)
csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.GRAYSCALE)
csi0.framesize((128, 160))
csi0.snapshot(time=2000)
clock = time.clock()
while True:
clock.tick()
img = csi0.snapshot()
write_command(0x2C)
write_image(img)
print(clock.fps())