Pythonic interface to FTDI devices using libftdi.
Project description
pylibftdi is a minimal Pythonic interface to FTDI devices using libftdi.
- Features:
No dependencies beyond standard library and a libftdi install.
Supports parallel and serial devices
Support for multiple devices
File-like interface wherever appropriate
Cross-platform
- Limitations:
The API might change prior to reaching a 1.0 release.
Usage
The primary interface is the Device class in the pylibftdi package; this gives serial access on relevant FTDI devices (e.g. the UM232R), providing a file-like interface (read, write). Baudrate is controlled with the baudrate property.
If a Device instance is created with mode='t' (text mode) then read() and write() can use the given encoding (defaulting to latin-1). This allows easier integration with passing unicode strings between devices.
Multiple devices are supported by passing the desired device serial number (as a string) in the device_id parameter - this is the first parameter in both Device() and BitBangDevice() constructors. Alternatively the device ‘description’ can be given, and an attempt will be made to match this if matching by serial number fails.
Examples
>>> from pylibftdi import Device >>> >>> with Device(mode='t') as dev: ... dev.baudrate = 115200 ... dev.write('Hello World')
The pylibftdi.BitBangDevice wrapper provides access to the parallel IO mode of operation through the port and direction properties. These provide an 8 bit IO port including all the relevant bit operations to make things simple.
>>> from pylibftdi import BitBangDevice >>> >>> with BitBangDevice('FTE00P4L') as bb: ... bb.direction = 0x0F # four LSB are output(1), four MSB are input(0) ... bb.port |= 2 # set bit 1 ... bb.port &= 0xFE # clear bit 0
There is support for a number of external devices and protocols, including interfacing with HD44780 LCDs using the 4-bit interface.
History & Motivation
This package is the result of various bits of work using FTDI’s devices, primarily for controlling external devices. Some of this is documented on the codedstructure blog, codedstructure.blogspot.com
Several other open-source Python FTDI wrappers exist, and each may be best for some projects. Some aim at closely wrapping the libftdi interface, others use FTDI’s own D2XX driver (ftd2xx) or talk directly to USB via libusb or similar (such as pyftdi).
The aim for pylibftdi is to work with libftdi, but to provide a high-level Pythonic interface. Various wrappers and utility functions are also part of the distribution; following Python’s batteries included approach, there are various interesting devices supported out-of-the-box - or at least there will be soon!
Plans
Add more examples: SPI devices, knight-rider effects, input devices, MIDI…
Perhaps add support for D2XX driver, though the name then becomes a slight liability ;)
License
Copyright (c) 2010-2024 Ben Bass <benbass@codedstructure.net>
pylibftdi is released under the MIT licence; see the file “LICENSE.txt” for information.
All trademarks referenced herein are property of their respective holders. libFTDI itself is developed by Intra2net AG. No association with Intra2net is claimed or implied, but I have found their library helpful and had fun with it…
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
File details
Details for the file pylibftdi-0.23.0.tar.gz
.
File metadata
- Download URL: pylibftdi-0.23.0.tar.gz
- Upload date:
- Size: 27.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf5b4c6ba73d79a6f6df849c345b00ba763d023201bed9ba51d876a4397b16d8 |
|
MD5 | c3f06a398c7e7e2bc9d6ff8476378d5e |
|
BLAKE2b-256 | 9df0551ccbd8e989e898707e0e0859344fcf538c2310521847a1035ad3e9b164 |
File details
Details for the file pylibftdi-0.23.0-py3-none-any.whl
.
File metadata
- Download URL: pylibftdi-0.23.0-py3-none-any.whl
- Upload date:
- Size: 33.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fe05879ffd5ba64b6fb8a777231f33487d97a888a4f84fa9b1f207e976c0cf2 |
|
MD5 | 70813b27c68398f597cb3d7ba3668a6b |
|
BLAKE2b-256 | 637eb3f579dfefeb680b4671b3049a56d7e3f6eb025e27b1481f8de4ae677f95 |