Hi, I am trying to transfer photos from a Raspberry Pi Zero taken with the Raspberry Pi camera to a Teensy 4.1. The two will be connected by their digital I/O pins, any suggestions on the best way to do this?
Define "best"
Why do you need to do it?
Any method that allows me to transfer a roughly 10mb size image from the raspi to teensy.
The Teensy is connected to a radio which will ultimately send the photo over air after it is received from the Raspberry PI. Both are going to be used as onboard computer, multiple other sensors will be connected to the Teensy, but the raspberry pi will just be used for the camera.
Both are 3V3 and I don't expect that the radio transmission rate is very fast. Send it out of a serial port to one of the Teensy's.
Okay I was thinking UART, I tried to use this code just to test functionality, but I get an error on the raspberry pi side.
Teensy code:
void setup() {
Serial1.begin(9600); // According to the Teensy Docs, this is the RX1 & TX1 on my board.
// Serial itself corrosponds to the micro-usb port
}
String msg = "";
void loop() {
if(Serial1.available() > 0) {
msg = "";
while(Serial1.available() > 0) {
char read = Serial1.read();
msg += read;
}
Serial1.write('X'); // Acknowledge with reply
}
Serial1.println(msg); // Output to console for debugging
// Should be a number 1-9
// TODO: further processing
}
and the raspberry pi code:
import time
import serial
import random
ser = serial.Serial(
port='/dev/ttyS0',
baudrate = 9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
while True:
n = random.randint(1,9)
print("Writing", n)
ser.write(n)
time.sleep(1)
feedback = ser.read()
print(feedback) // Expecting 'X'
However, I get this error:
line 1: import: command not found
line 2: import: command not found
line 3: import: command not found
line 4: syntax error near unexpected token (' line 4:
ser = serial.Serial(
I have the the teensy and raspberry pi connected through their RX/TX pins and ground.
Transferring 10 Mbytes at 9600 bps is going to be slow.
Both Pi Zero and Teensy 4.1 have native USB so transfer data via USB serial. Both support 480 Mbits/sec USB. 1 GHz Pi connected via 480 Mbits/sec USB to 600 MHz Teensy 4.1 is mind blowing. I wonder if it really works.
Search github for "xmodem arduino". Use Linux sz/rz (x, y, z modem) on the Pi.
Okay I will check it out, thank you. I'm a student and new to all of this, so I will try my best.
Hi, any reason I should use xmodem on the teensy instead of zmodem?
No reason not to. I assumed zmodem was not available on Arduino but it is.
Using ymodem and zmodem transfers on Linux. This is my experience so there may be better ways. I also did this a while ago so some of this is from my failing memory.
Install minicom (terminal program) and lrzsz (xyzmodem file transfer).
$ sudo apt install minicom lrzsz
minicom is a terminal program similar to Procomm 2.4 or TELIX for people who remember BBSes and DOS. It uses lrzsz for xyzmodem file transfers.
Example:
$ minicom -D /dev/ttyACM0
While in minicom, if the Arduino presents a command line interface, use it start ymodem or zmodem receive. Then to start sending file(s), press ^A S. Choose ymodem or zmodem. Choose the files to send. Start sending.
lrzsz can be used separately from minicom to start transfers from the command line. lrzsz defaults to doing transfers on stdin and stdout which is not very useful with Arduino boards since they appear as /dev/ttyACM* or /dev/ttyUSB* devices. The following script is my way to handle this.
This assumes the Arduino is in ymodem or zmodem receive batch mode.
Read the sz man page ('man sz') or read 'sz --help' for more options.
#!/bin/bash
# If sx,sb,sz are not present, sudo apt install lszrz
# man sz for more details and/or sz --help
TTY=/dev/tty${1}
shift
# Change serial port to raw mode so binary data passes unchanged.
stty -F $TTY raw
# ymodem batch
sb --ymodem "$@" <$TTY >$TTY
# zmodem batch
# sz "$@" <$TTY >$TTY
# Restore cooked mode (cooked is the opposite of raw).
stty -F $TTY cooked
What sort of 'radio' is this ?
What distance are you transfering the image ?
A lot of radios will take a long time to transfer a 10mb file ......
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.