I would like to start by saying that I am rather new to Raspberry Pi, but I have programmed Arduino. At the moment I am trying to get a Pi Zero W to transfer a JPG over serial using python and the Adafruit Console cable. I followed these instructions to setup the serial connection and it works great: https://www.instructables.com/id/Read-and-write-from-serial-port-with-Raspberry-Pi/. I have been looking for help with how to alter the code so that I can copy a JPG and send it via serial from the Zero W to the 3B+. Here is what I tried:

On the Zero side (transmit):

shutil.copyfileobj(open('/locaton/of/image.jpg', 'rb'), my_serial_portinfo)

Both of these options seem to be just sitting when I run the code; almost like nothing is happening or it is waiting. my_serial_portinfo includes all the information that is needed for the serial port.

On the 3B+ side (recieving):

shutil.copyfileobj(mu_serial_portinfo, '/location/to/place/jpg')

(I have placed a variety of byte sizes here to see if it changes anything) This does nothing but returns a statement of:

program exiting with code: 0

My python code has only one of the lines that I have mentioned above and the required information for the serial port.

Can anyone help me? Is there a way to easily move a file from my Zero W to my 3B+ over serial. I originally started trying to do this with an USB ethernet connection (setting up the Zero as a gadget) and had a terrible time with it. If I cannot get help I might have to switch back and seek more help.



Both of these options seem to be just sitting when I run the code; almost like nothing is happening, ...

Can anyone help me? ...


The tutorial you are following is good. Its example of writing to one serial port and reading back from another serial port is, as the author says, a good start point.

However you need more preparation to do further experiments. I would recommend another tutorial, the one by emmeshop, listed in the references below. This tutorials tells you more tricks which are useful in debugging.

The OP in the post listed in the reference list below has the same problem as yours: he wrote programs to let Rpi talk to Arduino, and there is nothing happening, ...

You will see an answer in the same post, briefly describing the follow debugging steps:

  1. Check hardware port Tx, Rx is working properly,

  2. Write a python program to loop back Tx to Rx, to make sure software is also working properly. The listed little program is "plug and play", you don't need any library, just run it to make sure basic things are OK.

  3. There are also experiences to share, such as which USB serial adapter is good (CH340 better than PL2302), which terminal simulator is good (SuperTerm, better than puTTY)

In short, this is another stepping stone to hop further.

BTW, the example loop back program shows write/read AT text commands. But it can do binary strings (eg python "bytes" datatype) as well. In other words, there is no difference between transferring text or binary files representing .jpg or other popular formats such as jason etc. But of course it is best for a newbie to start experimenting with human readable text files.

Good luck to data transfer!:)


1. Raspberry Pi Serial (UART) Tutorial - 2018

2. Serial to Arduino totally non-responsive - 2019

3. Read and Write From Serial Port With Raspberry Pi - emmeshop 2017

Procedures to read/write between RS232/TTL 3 to 5V adapter and a USB-serial adapter

  1. List TTY devices

$ dmesg | grep tty <<<< to list tty ... console [tty1] enabled ... dev:f1: ttyAMA0 at MMIO 0x3f201000 (irq = 83, base_baud = 0) is a PL011 rev3 ... console [ttyAMA0] enabled

  1. Disabloe serial concole $sudo raspi-config <<<<< to disable serial console, ttyAMA0 to PL011 rev 3 driver $dmesg | grep tty ... console [tty1] enabled ... dev:f1: ttyAMA0 at MMIO 0x3f201000 (irq = 83, base_baud = 0) is a PL011 rev3

  2. Write two python program, one write from one serial adapter, another to read from another serial adapter

Write two python programs serial_write.py serial_read.py

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.