MRAA and Python on Ubilinux

Yo.
I was recently talking to a colleague who was doing some Python work, and wasn’t entirely sure how to go about controlling a Galileo’s GPIO from a Python script. I knew that MRAA actually had Python bindings, but I’d never really been interested in them. Hence, I decided to dig a little deeper to see if I couldn’t get it to work.
Turns out its a pretty straightforward process. Basically, you’ll need to have something called SWIG installed. Sadly, I’m not sure which particular version of SWIG it is I have, but I think its regular old Swig 2.0 (which is installed with ‘apt-get install swig’). You’ll also need Python 2.7.x and the Python development libraries, which is installed with ‘apt-get install python python-dev’. Once that’s done, the process is mostly as described in previous posts, with the cardinal difference that the cmake invocation is now as follows:
cmake –DCMAKE_C_COMPILER=clang –DCMAKE_CXX_COMPILER=clang++ –DCMAKE_C_FLAGS=-march=i586 –mno-sse –mno-mmx –DCMAKE_CXX_FLAGS=-march=i586 –mno-sse –mno-mmx –DBUILDSWIGNODE=off ..
Ordinarily, we’d also have included –DBUILDSWIGPYTHON=off as well, which would have disabled Python support, but that’s not what we’re trying to do here. Once this is done, we can go ahead and run ‘make’ and ‘make install’ as the case may be to get everything installed.
As a quick digression, I suspect that ‘make install’ does not actually overwrite the libmraa.so file in /usr/local/lib. This is because while running ‘make install’, it reported that the ‘libmraa.so’ file was up to date, which it obviously wasn’t as I was trying to install a new version, so I manually removed that file and any similar-looking ones (e.g libmraa.so.0), ran ‘ldconfig’, then ran ‘make install’, then another ‘ldconfig’. YMMV.
Once we’ve ‘make install’ed, running any of the Python examples in the <mraa source tree>/examples/python subdirectory will fail. Doing some more reading, it turns out Debian has some weird policy about Python modules. A command is specified on the libmraa build instructions page, but it looked a bit dicey for Ubilinux because it essentially was creating a symbolic link to an existing folder, except that the link name they provided already existed as a physical file. That would lead to a…conflict of interests, so I simply navigated to /usr/local/lib/python2.7/site-packages (where the ‘make install’ command installed the Python module to), and copied the mraa.py and _mraa.so files to /usr/lib/python2.7/dist-packages. Once that was done, the examples ran successfully. Give it a shot…cross over to the dark side..
*speaks in Parseltongue*

Comments

Popular posts from this blog

Enabling SPI1 on the Raspberry Pi B+/Zero/2/3

Bitbanging SPI on the Raspberry Pi (via spi-gpio)

Getting Started with Logic Analyzers and Pulseview