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 🙂

Handy Link: PHP Serial Class

Need a way to talk to your serial devices (Arduino, PIC Micro, etc) using PHP? This nifty new Serial PHP Class written by Rémy Sanchez should scratch your itch! It currently works with Windows and Linux systems.

As of the time this post was written, you will need a Linux system to use the full (that is, Read AND Write) functionality of the Serial Class.  If you are using it under Windows, you will only have Write access to the serial port, but as you can still do quite a lot with just write access as far as projects are concerned I don’t see that as a major drawback.

If you want to see a practical example of the PHP Serial Class in use, the guys at Hak5 have used it to control a Garage door via a Web interface. You can view the full episode here.

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.

AVR C Bit Level Operations Guide

Found this very comprehensive guide (Link is a PDF document), during my travels on Google, showing how to perform bit-level operations in AVR C. Hope it’s useful to someone.

If you’ve not got a PDF reader to hand, then you can use Google’s Quick View link to this guide to view it in your browser