I have put together a python library for Galileo. Right now it has the ability to toggle Digital Pins, read from Digital Pins, read Analog Pins, and a few other basic commands. It has a few examples (ported from Arduino IDE example) in it too.
I am looking into publishing this to a repository so everyone can use it and help expand it.
1 of 1 people found this helpful
yep, you can- you can go from scratch (not that difficult, you just need the 'IOMappings' doc in the documents section of this site), otherwise I believe somebody has been working on a python library for this exact purpose, which should be available on github or some such service pretty soon.
EDIT: didn't see chofrock's comment above- that's what I was referring to.
If you're going the do-it-yourself route, I gave a brief explanation of how the pin muxing works which may help you understand (copied and pasted below from previous post- this example shows commands for a linux shell, but easy to emulate in python, all you're doing is writing to/reading from files):NOTE: you need the IOMappings.pdf document to follow along with this.
This diagram warrants a bit of explanation. below is a simple example of controlling a GPIO from the linux command prompt (let's use gpio3 as an example).
echo "3" > /sys/class/gpio/export //write a "3" to the export file, which reserves gpio3 for use
echo "out" > /sys/class/gpio/gpio3/direction //sets gpio3 as an output
echo "1" > /sys/class/gpio/gpio3/value //sets gpio3 high
echo "0" > /sys/class/gpio/gpio3/value //sets gpio3 low
echo "3" > /sys/class/gpio/unexport //unexport gpio3- can now be used by something/someone else
now, this holds true for Galileo, except for one small detail;
most of the I/Os are behind a mux to allow multiple functions for one pin (no native pin muxing on Quark).
In practice, this means that if you want to set one GPIO to high, you actually have to export and perform a write operation ontwo GPIOs.
Let's walk through an example of this with the I/O mapping PDF. We're going to set pin 0 on the arduino header to high.
Take a look at the first table, labelled "I/O Mappings". in the first column labelled "Arduino IDE ID" we have all the pin numbers from the arduino header. Take the first value which is IO0- this is the pin we're looking for. Now follow along in the row until you come to the '"Linux" column- which contains a value of 50.
This means that pin 0 on the arduino header corresponds to gpio50 in sysfs (/sys/class/gpio/gpio50).
However, if we want to access this pin, we first have to set the appropriate mux value. So, now look at the "I/O function muxing" table- the first two colums are "0" and "1". under the "1" column, find IO0, and follow the row along to the "Linux GPIO ID" column, which contains a value of 40.
So, now we know that, in order to set IO0 high, we need to first set gpio40 high and then gpio50.
echo "40" > /sys/class/gpio/export //write a "40" to the export file, which reserves gpio40 for use
echo "out" > /sys/class/gpio/gpio40/direction //sets gpio40 as an output
echo "1" > /sys/class/gpio/gpio40/value //sets gpio40 high
echo "50" > /sys/class/gpio/export //write a "50" to the export file, which reserves gpio50 for use
echo "out" > /sys/class/gpio/gpio50/direction //sets gpio50 as an output
echo "1" > /sys/class/gpio/gpio50/value //sets gpio50 high
1 of 1 people found this helpful
Oh, and I developed my Library mainly from the information that Sergey has in his blog post http://www.malinov.com/Home/sergey-s-blog/intelgalileo-programminggpiofromlinux
The diagram with all the muxes helps out. Saying it is one thing, seeing the schematic for me was very helpful.
Thanks. That was really helpful. Are you aware of a way to integrate the commands into Python, or will I have to set it up so that the code triggers a separate script?
Your link helped me out a lot. Any idea when your library is going to be released?
"integrate the commands into python"
I dont know what you mean. those commands are just writing values to files- i.e.
echo "40" > /sys/class/gpio/export means "write '40' to this file /sys/class/gpio/export"
So you just need to know basic file i/o in python. which is super easy. and If you don't know it then it'll take you about 3 minutes to learn.
the above as a python script would be something like;
with open("/sys/class/gpio/export", "r") as fh:
I understand the "system" api, as well as the linux commands that were illustrated here. I have a related problem, which is that I have installed
unzipping that 7z archive to my sd card, but I do not have a python interpreter in the installation
The SD Card contains
10/05/2013 12:35 PM <DIR> .
10/05/2013 12:35 PM <DIR> ..
10/05/2013 12:35 PM <DIR> boot
09/30/2013 07:23 PM 2,113,856 bzImage
09/30/2013 07:28 PM 1,441,609 core-image-minimal-initramfs-clanton.cpio.gz
09/30/2013 07:25 PM 314,572,800 image-full-clanton.ext3
3 File(s) 318,128,265 bytes
3 Dir(s) 515,875,467,264 bytes free
And after booting, and telneting to the system I see the following :
Poky 9.0 (Yocto Project 1.4 Reference Distro) 1.4.1 clanton
/ # uname -a
Linux clanton 3.8.7-yocto-standard #1 Mon Sep 16 14:59:19 IST 2013 i586 GNU/Linux
When I then attempt to find python, I have no luck :
/ # ls /usr/bin/python
ls: /usr/bin/python: No such file or directory
/ # python
/bin/sh: python: not found
I am clearly missing something. I'm not installing the "LITTLE" Linux installation, and I've been reading that the main linux installation for galileo contains goodies like python and node.js. Any help would be appreciated greatly.
yes, Python and node.js (among others packages) are on thew SD image. If you're not finding any python installation then your board isn't booting from SD. Did you do the firmware upgrade from the IDE? The board will not boot from SD if you haven't done the firmware upgrade.
arduino_4_life, thanks for the update. I've moved the discussion to its own thread. I'd like to credit you with the answer. Would you like to copy your response there ? The link in Linux install without access to Python
Carl thank you for posting that. With quite a bit of beating on openssl, my Galileo Git was able to clone your library. I expect it will be very useful.
It is interesting, the Fade Sketch which a python translation is shown in your example directory, does not do PWM on pin 9. Neither does implementing the file system write example that Sergey Malinov shows in his example shell lines,
However, running the fade sketch in the Arduino examples does work!
Have rebuilt the kernel with Sergey Malinov's fix for the correct speed of I2C communication, thought it could have been the source of the issue, but, no luck!
Any explanations from anyone?
I found that the Fade example works, kind of.
In order to get it to work, you need to power down the Galileo, boot it up, and run the fade script first before any other scripts.
The fade script will work once. If you try to run it again, it will not work.
The fade script will not work if any other script has been run.
I have absolutely no idea why this is happening. My thoughts are there is some mux or other GPIO register that is not getting setup correctly? I could not figure it out though.
we have a project where you can do this directly from the browser, it is called Wyliodrin (www.wyliodrin.com). let us know if it works for you and if you have any feedback, we would be happy to listen to it.