I'm doing a hobby project and I have a task to make an exchange of information between two Raspberry Pi Pico. I want to take an image from the memory of Pi Pico #1 and send it using SPI to the memory of Pi Pico #2. I wrote CircuitPython code for every Pi Pico. I'll put in the pin numbers later.
Please tell me what am I doing wrong?
Code of the program - transmitter:
import board
import busio
import digitalio
with open('image.jpg', "rb") as image:
img = f.read()
imgbyte = bytearray(img)
spi = busio.SPI(board.SCK, MISO=board.MISO)
spi.configure(baudrate=5000000, phase=0, polarity=0)
while not spi.try_lock():
pass
cs = digitalio.DigitalInOut(board.D2)
cs.direction = digitalio.Direction.OUTPUT
cs.value = False
spi.write(imgbyte)
cs.value = True
spi.unlock()
Program code = receiver:
import board
import busio
import digitalio
spi = busio.SPI(board.SCK, MISO=board.MISO)
spi.configure(baudrate=5000000, phase=0, polarity=0)
while not spi.try_lock():
pass
cs = digitalio.DigitalInOut(board.D2)
cs.direction = digitalio.Direction.INPUT
cs.value = False
receiver = bytearray(4)
spi.readinto(receiver)
cs.value = True
spi.unlock()
try:
with open("/lmage.jpg", "a") as image:
image.write(receiver)
image.flush()
time.sleep(1)
except OSError as e:
print("error")