Python interface for UART image/video transfer with embedded devices
Project description
PyDIPLink
PyDIPLink is a Python library for transferring images and video between microcontrollers and your computer over UART.
If you're working on embedded vision projects and need to send images from your PC to your device, or receive camera frames from your device back to your PC, this library handles all the serial communication for you.
What it does
PyDIPLink sends and receives images over a serial connection. It supports different image formats like RGB888, RGB565, Grayscale, YUV, HSV, and compressed JPEG. You can use it for:
- Sending test images from PC to your embedded device
- Receiving processed images from device back to PC
- Streaming JPEG frames from device to PC
The library works at high speeds (tested up to 500000 baud) and handles all the protocol details, timeouts, and error checking automatically.
Installation
Install from PyPI:
pip install pydiplink
Or from source:
git clone https://github.com/EmbedDIP/PyDIPLink.git
cd PyDIPLink
pip install -e .
How to use it
Command line tool
Once installed, you can run the command line tool:
# Start listening on default port (/dev/ttyUSB0 at 500000 baud)
pydiplink
# Or specify your port and baud rate
pydiplink --port /dev/ttyUSB1 --baud 115200
pydiplink --port COM3 --baud 500000 # Windows
# Set a default image to send when your device requests one
pydiplink --image myimage.jpg
The tool will sit and listen for commands from your device. When the device requests an image, it sends it. When the device sends an image or JPEG frame, it saves it automatically.
Extra features
Video recording
If you want to record JPEG streams to video files:
from pydiplink import JpegVideoWriter
with JpegVideoWriter("output.avi", fps=30, resolution=(640, 480)) as writer:
for i in range(300):
frame = receive_and_show_jpeg(ser)
if frame is not None:
writer.write_frame(frame)
Or from command line:
pydiplink --record --output video.avi --fps 15
Histogram and signal data
Receive histogram or other 1D signal data from your device:
import serial
from pydiplink import receive_1d_signal
ser = serial.Serial('/dev/ttyUSB0', 500000, timeout=5)
signal_data = receive_1d_signal(ser, plot=True, save_path="histogram")
ser.close()
Protocol
PyDIPLink uses a simple protocol. Your device sends 3-byte commands:
- STR - Device requests an image from PC
- STW - Device sends a raw image to PC
- STJ - Device sends a JPEG frame to PC
- ST1 - Device sends signal data (optional, for histograms)
The library handles all the details automatically. Just send the command from your device and PyDIPLink will respond appropriately.
Image formats supported: RGB888, RGB565, Grayscale, YUV, HSV, and JPEG.
Configuration
You can set these environment variables:
export DIPLINK_PORT=/dev/ttyUSB0
export DIPLINK_BAUD=500000
export DIPLINK_IMAGE=input.jpg
There are safety limits to prevent issues: images can't be larger than 4096x4096 pixels or 50MB total.
Examples
Check the examples/ folder for complete working examples:
basic_image_transfer.py- Sending and receiving imagesjpeg_streaming.py- Video streaming
Documentation
See docs/API.md for complete API documentation.
License
MIT License - see LICENSE file.
Author
Ozan Durgut - GitHub
If you find a bug or want to request a feature, open an issue.
Organization
PyDIPLink is part of the embedDIP organization. Other code projects related to, using, or referencing PyDIPLink can be found in the embedDIP organization on GitHub.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydiplink-0.1.0.tar.gz.
File metadata
- Download URL: pydiplink-0.1.0.tar.gz
- Upload date:
- Size: 18.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66f89c2e18341ebae134f7bc15d91d0a88b20ab2b3e879a6669187af55bd51e6
|
|
| MD5 |
2bf64c87216be23d8aa7f9c50f1ba30a
|
|
| BLAKE2b-256 |
dc04c59c3e5479484df2ee3e7828458aa7131ab3a15f1f435043dffd8d355cb8
|
File details
Details for the file pydiplink-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pydiplink-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e12566ffbe15f3d5b6453ecc586bb6041ad85ab94eb41218c9c1014032deb369
|
|
| MD5 |
27894ded310efa6fb9b7b4bd833d77e7
|
|
| BLAKE2b-256 |
d46bac4b5af0bd0dfc638c77aea3cb2448fdcf4d95909f7b6c8080d64c786287
|