1

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")
0andriy
  • 4,183
  • 1
  • 24
  • 37
Anton9101
  • 11
  • 3
  • At least your transmitter has a serious bug: you open your "image.jpg" by using the variable "image" as a file handle. But in the next line you try to input from the (never opened) file handle "f". – Peter I. Jul 24 '23 at 07:11

0 Answers0