The Elektor Forum will close. See also this link. From Friday March 1st it is no longer possible to log in to the forum. However, the content of the forum will remain visible until the end of March. As of April 1st the forum will definitely go off the air.

Python Programming and GUIs - fdti bit-banging

The topic on number crunching

Postby royleith » Tue Nov 06, 2012 12:00 am

I bought the book 'Python Programming And GUIs' by Andrew Pratt some time ago and got the demo (using ftdi bit-banging) working from the live Slackware disk and also from a Kubuntu installation on the hard drive using Python 2.7.

After a few Kubuntu upgrades, the demo no longer works. I decided to get it working on my Raspberry PI and this required a recompile of the fdti library, which eventually appeared to work. I also tried to compile the _simple_fdti.so shared Python library, with some errors and a smaller file size, and so I am using the original. However, I suspect that it uses X86 rather than ARM code.

The problem I have is that, even running as root in the /root directory and with _simple_fdti.so copied into the directory with the other files, I get the report:

ImportError: /root/demo/_simple_ftdi.so: cannot open shared object file: No such file or directory.

'ls' reports that the file is there. I have checked the 'from' lines in interface_classes.py; It has been like this for several versions of Kubuntu and now with Raspbian (using Python 2.7).

from Tkinter import *
from math import *
from _simple_ftdi import *

The first two are fine from the Python command line, but 'from _simple_fdti import *' gives the above warning.

Changing the extension to .py results in the file opening, but failing as a module. At least Python can see the file. BTW the file is also copied to /usr/local/libs/Python 2.7 as suggested in the book.

Any advice? Even though the Raspberry Pi is its own 'bit-banger' it would be nice to get the FTDI module working with Python.

Roy Leith
royleith
 
Posts: 11
Joined: Thu Jan 02, 2014 10:39 am

Postby royleith » Mon Nov 26, 2012 12:00 am

Two steps forward, one step back. I tried a more informed source for recompiling the simple_ftdi library and got several errors including a deprecated function which stopped the compile. I also found that the Raspberry Pi already has python-fdti in the repository. Installing this (and usb-dev and other devs) gives the correct ftdi.h in the correct place, but still no compile.

I booted the live-CD and there was no ftdi.h for comparison because non of the sources had been installed. The version of Slackware would not configure the ethernet or wifi connections and so I am at an impasse at the moment. I need to rewrite simple_fdti with the correct, supported functions. I also need to reuse the interface code to communicate with the ADS1286 chip. If anyone is using a networking Linux install that works with the original code, please install the fdti srcs and send me a copy of ftdi.h for comparison.

The GPL source indicates that it is only included for speed and that there is a python based alternative in the classes file. However, that may also be a problem with the latest fdti driver version. Another possibility is to use ftdi.py that comes with python-ftdi.
royleith
 
Posts: 11
Joined: Thu Jan 02, 2014 10:39 am

Postby royleith » Thu Dec 20, 2012 12:00 am

I have managed to compile _simple_ftdi.so for the Raspberry Pi from the files in the simple_ftdi folder in the original Slackware CD.

Installed Packages: They may not all be essential

swig swig-doc swig-examples

python-dev
python-ftdi
libftdi-dev
libusb-dev
python-tk

pi@raspberrypi ~/simple_ftdi $ sudo swig -python simple_ftdi.i
pi@raspberrypi ~/simple_ftdi $ gcc -O2 -fPIC -c simple_ftdi.c simple_ftdi_wrap.c -I/usr/include/python2.7

simple_ftdi.c: In function ‘open_device’:
simple_ftdi.c:49:1: warning: ‘ftdi_enable_bitbang’ is deprecated (declared at /usr/local/include/ftdi.h:413) [-Wdeprecated-declarations]

pi@raspberrypi ~/simple_ftdi $ gcc -shared simple_ftdi.o simple_ftdi_wrap.o -o _simple_ftdi.so -lftdi
pi@raspberrypi ~/simple_ftdi $

To try out the library, copy the resulting _simple_ftdi.so file into your home directory (/home/pi) and,

sudo idle
import _simple_ftdi
_simple_ftdi.find_all()

If you do not run idle with sudo, if it finds any devices it will report 'function not permitted'.

PS: I tried to post this several times with a couple of FTDI modules in the same powered hub as my wifi dongle and wireless mouse/keyboard dongle. Wifi just would not work at all well. There is something a little odd with the Raspi and its USB.

Roy Leith
royleith
 
Posts: 11
Joined: Thu Jan 02, 2014 10:39 am

Postby oloftangrot » Sun Feb 10, 2013 12:00 am

I run RH Fedora on a 64-bit machine and the shared lib from the book don't work with that machine either.

This Makefile builds a new interface lib that can be loaded by Python on my machine:

all: simple_ftdi.py _simple_ftdi.sosimple_ftdi.py: simple_ftdi.iswig -python simple_ftdi.isimple_ftdi.o: simple_ftdi.cgcc -fPIC -c simple_ftdi.c `pkg-config --cflags python`simple_ftdi_wrap.o: simple_ftdi.pygcc -fPIC -c simple_ftdi_wrap.c `pkg-config --cflags python` _simple_ftdi.so: simple_ftdi.o simple_ftdi_wrap.old -shared simple_ftdi.o simple_ftdi_wrap.o -o _simple_ftdi.so -lftdiclean:rm simple_ftdi.py *.o _simple_ftdi.so simple_ftdi_wrap.c


It shoudl run on a RPi as well provided development packages for libftdi and swig is installed. Also note that if you have issues with USB you might be pulling to much power from the USB port, use an powered USB hub and if needed replace the fuses on the USB power lines with zero ohm resistors.
oloftangrot
 
Posts: 2
Joined: Thu Jan 02, 2014 10:44 am

Postby andyp » Sat Mar 09, 2013 12:00 am

Hi Roy,

When you get the message

"ImportError: /root/demo/_simple_ftdi.so: cannot open shared object file: No such file or directory."

Have you tried running "ldconfig" at the command line?


The file ftdi.h is in /usr/local/include

I have just tried _simple_ftdi.so from the original slax with libftdi-0.20 on slackware 14 and python 2.7.3, called find_all(), worked ok.


The _simple_ftdi.so can be compiled for the pi, I have attached it.






If it's any help to get the wifi working with the original slax disk:

At the command line:

1. root@slax:~#iwlist scanning

(This will give you something like)


wlan0 Scan completed :
Cell 01 - Address: 00:18:F6:AC:3F:41
ESSID:"BTHomeHub-C76A"
Mode:Master
Channel:11
Frequency:2.462 GHz (Channel 11)
Quality=50/100 Signal level:-60 dBm
Encryption keyn
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s
24 Mb/s; 36 Mb/s; 54 Mb/s; 6 Mb/s; 9 Mb/s
12 Mb/s; 48 Mb/s
Extra:tsf=00000080acb0c240
Extra: Last beacon: 104ms ago
Cell 02 - Address: 02:18:F6:AC:3F:42
ESSID:"BTWiFi"
Mode:Master
Channel:11
Frequency:2.462 GHz (Channel 11)
Quality=50/100 Signal level:-60 dBm
Encryption keyff
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s
24 Mb/s; 36 Mb/s; 54 Mb/s; 6 Mb/s; 9 Mb/s
12 Mb/s; 48 Mb/s
Extra:tsf=00000080acb0c852
Extra: Last beacon: 104ms ago

eth0 Interface doesnt support scanning.


2. root@slax:~#iwconfig wlan0 essid BTHomeHub-C76A key xxxxxxxxx ap any
(xxxxxxxxx your wep key)


3. root@slax:~#ifconfig wlan0 up


4. root@slax:~#dhcpcd wlan0


Or if you prefer go to http://old.slax.org/modules.php and get the Slax-Network-Setup-Tool module which is really easy to use. I know you have to get on line first





Andy
Attachments
-simple-ftdi.so-for-rasp-pi.zip
(16.64 KiB) Downloaded 137 times
andyp
 
Posts: 2
Joined: Thu Jan 02, 2014 10:46 am

Postby Guest » Sat Feb 08, 2014 12:00 am

I just bought the book and try to download the ISO file mentioned on page 10, the link said its broken, is there other place to get it?
Guest
 

Postby Guest » Fri Feb 28, 2014 12:00 am

I have tried several times to download the iso, but it is corrupt.
I tried to contact via email elektor order@elektor.com but got no answer.
The exercises are inside the iso then the book is unusable.
Does anyone know where to find the iso posst running or exercises?
Guest
 

Postby andyp » Sun Mar 02, 2014 12:00 am

I have sent a replacement file which should be available soon.

Andrew Pratt.
andyp
 
Posts: 2
Joined: Thu Jan 02, 2014 10:46 am

Re: Python Programming and GUIs - fdti bit-banging

Postby VinayDand » Sun Dec 20, 2015 6:27 pm

I bought the book 'Python Programming And GUIs' by Andrew Pratt from Elektor Stores.
I have downloaded the book ISO file from Elektro site.
After burning on CD, I can boot from the Live CD and copied example files and FTDI library files on a flash drive.

I am trying Python examples on a Raspberry Pi now.

I am stuck at chapter 3.4 'A practical data logger'.
I have a FTDI UM245R board.

I have downloaded the _simple_ftdi.so for RPi from previous post by Andy Pratt.

My Question is,
1) Where should I copy the _simple_ftdi.so file on the Raspberry Pi
2) any other path command / permissions to be changed on RPi.

Presently 'import _simple_fdti' does not work under Python 2.7 IDLE ide command prompt.

As I am a newbie on Python and RPi, some detailed pointers are appreciated.

Best Regards,
Vinay
VinayDand
 
Posts: 1
Joined: Sun Dec 20, 2015 6:05 pm
Location: Mumbai - India


Return to Microcontrollers & Embedded

Who is online

Users browsing this forum: No registered users and 2 guests