The purpose of this Instructable is to illustrate how to set up and use IPC (interprocess communication) between a Python script and the executing sketch on the Intel Galileo board. In addition to providing the source code I will be going over the code in detail and pointing out the rationale behind several decisions. The hope is that this will make it easier for you if something breaks or you want to extend the code's functionality. It wouldn't really be very instructional if I mailed you a finished product therefore this Instructable isn't complete without a solid walk-through of the code.
I recommend downloading the files in the /sketch, /python, and /examples from my GitHub (https://github.com/bunneydude/IPCBuffer). The readme files contain instructions on how to install them. Also, download the nrf24.zip file below (the slightly modified radio library for porting to Galileo from here). Instead of posting the code in the Instructable you can follow along with the source code itself.
That being said, documentation is not complete without examples. After the code walk-through there are instructions on how to use this IPC library to decrypt data the Galileo receives wirelessly from a MSP430.
The following skills will be somewhat assumed for this Instructable:
Compiling Python Modules For Galileo To use IPC objects from Python we can use the sysv_ipc module by Philip. For the encryption demo we need the PyCrypto module. Download and extract both. The build process is the same:
Source the cross-compiler environment from the Galileo Arduino IDE folder:
If you don't have them already, install the dev package for python:
sudo apt-get install python-dev
In the top directory of sysv_ipc and pycrypto, run the setup script:
sudo python setup.py build
You'll see a string of commands that were executed in the form of "gcc -option -more options -etc". These need to be run with the compiler the source script specified in environmental variable CC. There are several tutorials online for how to get Python to cross-compile properly but for a quick fix you can do the following:
Copy all the "gcc" commands into a text file (e.g. "build_cmds")
Find and replace every 'gcc' with '$CC'.
sudo -s -H
Re-source the environment script, then execute the commands from the text file:
The files we need are sysv_ipc.so and the "Crypto" folder - both found within their respective build/lib.linux-i686-2.7 directories. Copy these two files to /usr/lib/python2.7/site-packages on the Galileo with WinSCP or your favorite file transfer program. I've uploaded the compiled files from my Galileo in known_good.zip.
With the MSP430 board and Galileo powered up, launch the shm_python script as specified above. When you ground one of the six port 2 pins on the MSP430 a message should be printed saying which pin was pressed. The current encoding in shm_python.py is specific to how the wires were laid out on my breadboard. The MSP430 code supports grounding multiple pins - additional values just need to be added to the key dictionary in shm_decrypt.py.
To destroy the IPC objects, download python_interface.zip and run tui.py (requires pySerial) from the computer you used to program the Galileo. Launching tui.py will open a COM port (defaults to COM 5) at 115200 baud. This is a simple script to send and receive serial data consistent with the protocol coded into galileo_ipc.ino. Reading from register 1 will call myBuffer.close() within the sketch. I.e.
Ingresa el e-mail asociado con tu cuenta y te enviaremos tu usuario y una contraseña temporal.