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:
-
-
class pylibftdi.examples.bit_server.ReqHandler(request, client_address, server)[source]
Bases: BaseHTTPServer.BaseHTTPRequestHandler
-
do_GET()[source]
-
do_POST()[source]
-
send_head()[source]
-
class pylibftdi.examples.bit_server.ThreadingServer(server_address, RequestHandlerClass, bind_and_activate=True)[source]
Bases: SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer
-
pylibftdi.examples.bit_server.get_page()[source]
-
pylibftdi.examples.bit_server.runserver(port=8008)[source]
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-2013 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.
-
write_cmd(x)[source]
-
write_data(x)[source]
-
pylibftdi.examples.lcd.display(string, device_id=None)[source]
Display the given string on an attached LCD
an optional device_id can be given.
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-2013 Ben Bass <benbass@codedstructure.net>
All rights reserved.
-
pylibftdi.examples.led_flash.flash_forever(rate)[source]
toggle bit zero at rate Hz
-
pylibftdi.examples.led_flash.main()[source]
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-2013 Ben Bass <benbass@codedstructure.net>
All rights reserved.
-
pylibftdi.examples.list_devices.get_ftdi_device_list()[source]
return a list of lines, each a colon-separated
vendor:product:serial summary of detected devices
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
-
class pylibftdi.examples.magic_candle.Candle[source]
Bases: object
-
run()[source]
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-2013 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
@param interval - polling interval in seconds
@param count - number of polls to do, or infinite if 0
@param match - value to look for to exit early
@param mask - mask of read value before comparing to match
@return bool - ‘ok’. either a match was made or none was requested
-
pylibftdi.examples.pin_read.display_value(value)[source]
display the given value
-
pylibftdi.examples.pin_read.get_value()[source]
get the value of the pins
-
pylibftdi.examples.pin_read.main(args=None)[source]
serial_loopback Module
test serial loopback; assumes Rx and Tx are connected
Copyright (c) 2010-2013 Ben Bass <benbass@codedstructure.net>
All rights reserved.
-
class pylibftdi.examples.serial_loopback.LoopbackTester[source]
Bases: object
-
main()[source]
-
test_loopback(lengths)[source]
-
pylibftdi.examples.serial_loopback.test_string(length)[source]