examples Package¶
examples Package¶
pylibftdi examples
bit_server Module¶
bit_server.py - remote HTTP interface to bit-bangged FTDI port This runs as a web server, connect to port 8008
Change HTTP_PORT for different port number or supply alternate as args[1]
- Requires:
pylibftdi
- class pylibftdi.examples.bit_server.ReqHandler(request, client_address, server)[source]¶
Bases:
BaseHTTPRequestHandler
lcd Module¶
Write a string (argv[1] if run from command line) to a HD44780 LCD module connected via a FTDI UM232R/245R module using pylibftdi
example usage:
# while true; > do python lcd.py $( awk ‘{print $1}’ /proc/loadavg); > sleep 5; > done
Copyright (c) 2010-2014 Ben Bass <benbass@codedstructure.net> All rights reserved.
- class pylibftdi.examples.lcd.LCD(device)[source]¶
Bases:
object- The UM232R/245R is wired to the LCD as follows:
DB0..3 to LCD D4..D7 (pin 11..pin 14) DB6 to LCD ‘RS’ (pin 4) DB7 to LCD ‘E’ (pin 6)
- init_four_bit()[source]¶
set the LCD’s 4 bit mode, since we only have 8 data lines and need at least 2 to strobe data into the module and select between data and commands.
- data¶
This class is a descriptor for a bus of a given width starting at a given offset (0 = LSB). The device which does the actual reading and writing is assumed to be a BitBangDevice instance in the ‘device’ attribute of the object to which this is attached.
- e¶
This class is a descriptor for a bus of a given width starting at a given offset (0 = LSB). The device which does the actual reading and writing is assumed to be a BitBangDevice instance in the ‘device’ attribute of the object to which this is attached.
- rs¶
This class is a descriptor for a bus of a given width starting at a given offset (0 = LSB). The device which does the actual reading and writing is assumed to be a BitBangDevice instance in the ‘device’ attribute of the object to which this is attached.
led_flash Module¶
Flash an LED connected via a FTDI UM232R/245R module using pylibftdi
Optionally supply a flash rate (in Hz, default 1) as an argument
Copyright (c) 2010-2014 Ben Bass <benbass@codedstructure.net> All rights reserved.
list_devices Module¶
Report connected FTDI devices. This may be useful in obtaining serial numbers to use as the device_id parameter of the Device() constructor to communicate with a specific device when more than one is present.
example usage:
$ python pylibftdi/examples/list_devices.py FTDI:UB232R:FTAS1UN5 FTDI:UM232R USB <-> Serial:FTE4FFVQ
To open a device specifically to communicate with the second of these devices, the following would be used:
>>> from pylibftdi import Device
>>> dev = Device(device_id="FTE4FFVQ")
>>>
Copyright (c) 2011-2014 Ben Bass <benbass@codedstructure.net> All rights reserved.
magic_candle Module¶
- Magic Candle - light falling on the LDR turns on the LED, which due
to arrangement keeps the LED on until LDR/LED path is blocked
LDR (via a transistor switch - dark = ‘1’) - D0 LED (via series resistor) - D1
pylibftdi - codedstructure 2013-2014
- class pylibftdi.examples.magic_candle.Candle[source]¶
Bases:
object- be_light¶
This class is a descriptor for a bus of a given width starting at a given offset (0 = LSB). The device which does the actual reading and writing is assumed to be a BitBangDevice instance in the ‘device’ attribute of the object to which this is attached.
- is_dark¶
This class is a descriptor for a bus of a given width starting at a given offset (0 = LSB). The device which does the actual reading and writing is assumed to be a BitBangDevice instance in the ‘device’ attribute of the object to which this is attached.
midi_output Module¶
- class pylibftdi.examples.midi_output.MidiDevice(*o, **k)[source]¶
Bases:
Device- __init__(*o, **k)[source]¶
Device([device_id[, mode, [OPTIONS …]]) -> Device instance
represents a single FTDI device accessible via the libftdi driver. Supports a basic file-like interface (open/close/read/write, context manager support).
- Parameters:
device_id – an optional serial number of the device to open. if omitted, this refers to the first device found, which is convenient if only one device is attached, but otherwise fairly useless.
mode – either ‘b’ (binary) or ‘t’ (text). This primarily affects Python 3 calls to read() and write(), which will accept/return unicode strings which will be encoded/decoded according to the given…
encoding – the codec name to be used for text operations.
interface_select – select interface to use on multi-interface devices
device_index – optional index of the device to open, in the event of multiple matches for other parameters (PID, VID, device_id). Defaults to zero (the first device found).
The following parameters are only available as keyword parameters and override class attributes, so may be specified in subclasses.
- Parameters:
lazy_open – if True, then the device will not be opened immediately - the user must perform an explicit open() call prior to other operations.
chunk_size – if non-zero, split read and write operations into chunks of this size. With large or slow accesses, interruptions (i.e. KeyboardInterrupt) may not happen in a timely fashion.
auto_detach – default True, whether to automatically re-attach the kernel driver on device close.
index – optional index into list_devices() to open. Useful in the event that multiple devices of differing VID/PID are attached, where device_index is insufficient to select as device indexing restarts at 0 for each VID/PID combination.
vid – optional vendor ID to open. If omitted, the default USB_VID_LIST is used to search for devices.
pid – optional product ID to open. If omitted, the default USB_PID_LIST is used to search for devices.
pin_read Module¶
Display values on input pins of a BitBangDevice.
- TODO:
ANSI colours / display differences in bold
- example - beep on pin 1 going high:
$ pylibftdi/examples/pin_read.py -n 0.01 -m 1 -k 1 && beep
Copyright (c) 2011-2014 Ben Bass <benbass@codedstructure.net> All rights reserved.
- pylibftdi.examples.pin_read.display_loop(interval=1, count=0, match=None, mask=255)[source]¶
display and compare the value
- Parameters:
interval – polling interval in seconds
count – number of polls to do, or infinite if 0
match – value to look for to exit early
mask – mask of read value before comparing to match
- Returns:
‘ok’. either a match was made or none was requested
- Return type:
bool
serial_loopback Module¶
test serial loopback; assumes Rx and Tx are connected
Copyright (c) 2010-2020 Ben Bass <benbass@codedstructure.net> All rights reserved.
info Module¶
Report environment info relevant to pylibftdi
example usage:
$ python3 -m pylibftdi.examples.info
pylibftdi version : 0.15.0
libftdi version : libftdi_version(major=1, minor=1, micro=0, version_str='1.1', snapshot_str='unknown')
libftdi library path : /usr/local/lib/libftdi1.dylib
libusb version : libusb_version(major=1, minor=0, micro=19, nano=10903, rc='', describe='http://libusb.info')
libusb library path : /usr/local/lib/libusb-1.0.dylib
Python version : 3.4.0
OS platform : Darwin-14.1.0-x86_64-i386-64bit
Copyright (c) 2015-2020 Ben Bass <benbass@codedstructure.net>