Controlling the Maplin Robotic Arm with a Raspberry Pi

After seeing this article on wikihow by Jamie Scott, I decided a trip to Maplins was in order and I ended up buying one of their Robotic Arm kits

The python script I written to control the arm is based on his with a few minor amendments. Mainly, error handing for keyboard interrupts and mapping of the commands to more easily remembered versions in a dictionary.

The script and documentation are available from Github.


Checking File Permissions the Easy Way Using Python

Edit: Doh! Looks like I forgot something. In Linux, if a file or directory has read, write or executable permissions for the Owner only (nothing for ‘group’ and ‘others’) check_files() doesn’t add a dictionary entry for that path if the user running the script does not own the file or directory. Adding one little ‘elif’ block fixes this. (see the slightly revised code below.)

It never ceases to amaze me what even a wet-behind-the-ears hobbyist like myself can do with Python. I needed a way to get the file permissions and check for the existence of a large number of paths that I could re-use in other scripts. The function shown below is what I came up with.

It takes a Python list containing file/directory paths as an argument and returns a dictionary containing the Paths as keys and the concatenated values ‘READ’, ‘WRITE’, EXECUTE’ separated by commas (or ‘NOACCESS’ if the user doesn’t have read, write or executable permissions) to indicate the users level of access to each path, or just the value ‘NOEXISTS’ if the path does not exist.

def check_files(paths):
        dict = {}
        for p in paths:
            if not os.access(p, os.F_OK):
            if(os.access(p, os.W_OK)):
            if (os.access(p, os.X_OK)):
            elif os.access(p, os.F_OK) and not (os.access(p,os.R_OK)) and not (os.access(p, os.W_OK)) and not (os.access(p, os.X_OK)):
            status="" # Set blank before we enter the loop again
        return dict

This function will only give you the permissions for the user running the script but as this was all I needed I did not see that as a major problem. Hope someone finds this useful. As always, you can flame me/prop up my massive ego in the comments 🙂

Simple Power Loss Detector with SMS Notification

After having a few un-expected power outages this year, it got me thinking about how I could easily (and cheaply) be alerted (preferably via SMS) should one occur. With a laptop running Linux, a little bit of Python and some easily obtainable hardware and software, I come up with a simple method of doing just that. Read on for the code and set-up instructions. Continue reading Simple Power Loss Detector with SMS Notification

Handy Link: bpython

bpython is a Python interpreter interface on steroids! It’s main features are:

  • Syntax Highlighting
  • A save function (to save code you’ve entered to a file)
  • Auto-intending (we all know how important correct indenting is when you’re writing python scripts!)
  • Auto-Completion which displays suggestions for any built-in functions, helping you to get the syntax for a statement spot-on without having to dig through reference manuals. The auto-completion feature also helps with import declarations, showing you a list of available modules as you type.

Installation in Ubuntu is as painless as typing sudo apt-get install bpython Other packages are available for Debian, Fedora and OpenSUSE as well. You can also obtain the source code from here and compile it yourself if need be.

If you need any help with using bpython, then check out the project’s webpage. Hope this is useful to someone.

Happy new year!

Handy Link: “Invent with Python”

Need an accessible guide to learning Python that won’t send you to sleep? “Invent with Python” is just what you need!

Invent Your Own Computer Games with Python, 2nd Edition (to give it its full title) is a book written by Al Sweigart.  It is available for free on-line in both HTML and PDF format. You can download the PDF format from here.

The book is released under a Creative Commons licence and is aimed at people who are completely new to programming.

Comprised of 19 Chapters (at the time this post was written), it guides the reader through the basic concepts (Installation of Python, use of the Python interactive shell, Variables, functions, etc) and some of the more advanced stuff as well.

The coding examples in the book are all games (so you can actually have some fun with what you create as you go through the book!), which increase in complexity as the chapters progress.

There is also a Blog related to the book, so you can keep up with any future additions that are made to it.

Taken the Python Challenge?

Want a great way to learn a programming language and have some fun? Why not take the Python Challenge. Just found out about this little gem on hackaday  and thought I’d post it here to help spread the word.

The Python Challenge site consists of a series of levels ( 33 levels at present) in which you have to solve puzzles of increasing complexity using code you write yourself. Each puzzle solution then gives you access to the next level.

The site also has a great community behind it, with forums if you get really stuck and need a hint.

From Hackaday: Arduino Snow Clock

This Alarm Clock Arduino hack , featured on hackaday,  has to be one of the most innovative uses of an Arduino and Python I have seen! The maker, insingertech, has published full instructions on his hack here.

He goes into great detail on his build process and the diagrams (for the Relay Driver part of his circuit, especially) really help to explain things.

The only critisism I can think of here is that perhaps he should have used an Ethernet Shield for the network connectivity element of his project instead of a PC/Laptop.

Webthermo: Web-based Temperature Monitor

Ok, so someone has already beaten me to it (and done a excellent job of it as well) with the whole web-based temperature monitoring thing, but anyway… Here’s Webthermo! 🙂

Webthermo,  my follow-up to Ardthermo, is a small, web-enabled Python script which uses the CherryPy HTTP Python framework.  It allows you to monitor temperature (in both Celsius and Fahrenheit units) over the Internet (using the port-fowarding facility of your Router),  or on your own LAN via a web browser, your favorite RSS reader or a WAP-capable Mobile phone, using the same Arduino sketch and hardware setup as was used for Ardthermo.

It’s still in the early stages of development at the moment, so its still a bit rough around the edges but it works well enough. You can get a copy of the Python script, which also includes the Arduino sketch needed for the hardware side of things, from the Software page.

System Requirements and instructions on how to use Webthermo can be found below. Enjoy everyone!

Continue reading Webthermo: Web-based Temperature Monitor