snim2.org

I am a Senior Lecturer in Computer Science at the University of Wolverhampton. My interests generally lie in the area of programming languages and tools, especially for the Internet of Things and other distributed systems.

« Personal blog »

Automate, automate, automate

I’ve recently been working on a new Python project, which started off as a bit of an experiment at the recent PyPy London Sprint. Working on a brand new repository is always nice, a blank slate and a chance to write some really elegant code, without all the crud of a legacy project.

In this case, the infrastructure for the project is pretty involved. I was using the pytest unit testing framework and using the rpython toolkit from pypy, both for the first time.

That led to an interesting situation. When I run the unit tests, I want to use the CPython interpreter. This means I can use all the standard library modules that I know well, and can test the basic algorithms I’m writing. When I want to “translate” my code into a binary executable, I use pypy and some of its rlib replacements for the Python standard library modules. When I get an runtime error in the translation, I need to know whether that is related to my use of the rlib libraries or my code is just plain wrong, and using CPython  helps me to do that.

The problem is that I have to keep switching between different standard libraries and interpreters. Somewhere in my code there is a switch for this:   

DEBUG = True

In testing that switch should be True and in production it should be False, but changing that line manually is a real pain, so I need some scripts to catch when I’ve set the DEBUG flag to the wrong mode.

Test automation #1

Here’s my (slightly simplified) first go at automating a test script:

import subprocess

debug_file = ...
framework = 'pytest.py'
try:
    retcode = subprocess.check_output(['grep', 'DEBUG = False', debug_file])
    print 'Please turn ON the DEBUG switch in', debug_file, 'before testing.'
except subprocess.CalledProcessError:
    subprocess.call(('python', framework))

What does this do? First the script calls the UNIX utility grep to find out whether there the DEBUG flag is correctly set:

retcode = subprocess.check_output(['grep', 'DEBUG = False', debug_file])

If it is, the script prints a warning message:

print 'Please turn ON the DEBUG switch in', debug_file, 'before testing.'

which tells me I have to edit the code, and if not, the script runs the tests:

subprocess.call(('python', framework))

Nice, but I still have to edit the file if the flag is wrong.

Test automation #2

Nicer, would be for the script to change the flag for me. Fortunately, this is easily done with the Python fileinput module. Here’s the second version of the full test script (slightly simplified):

import fileinput
import subprocess
import sys

debug_file = ...
debug_on = 'DEBUG = True'
debug_off = 'DEBUG = False'

def replace_all(filename, search_exp, replace_exp):
    """Replace all occurences of search_exp with replace_exp in filename.

    Code by Jason on:

http://stackoverflow.com/questions/39086/search-and-replace-a-line-in-a-file-in-python

    """
    for line in fileinput.input(filename, inplace=1, backup='.bak'):
        if search_exp in line:
            line = line.replace(search_exp, replace_exp)
        sys.stdout.write(line)

def main():
    """Check and correct debug switch. Run testing framework.
    """
    framework = 'pytest.py'
    opts = ''

    try:
        retcode = subprocess.check_output(['grep', debug_off, debug_file])
        print 'Turning ON the DEBUG switch in', debug_file, 'before testing...'
        replace_all(debug_file, debug_off, debug_on)
    except subprocess.CalledProcessError:
        pass
    finally:
        subprocess.call(('python', framework, opts))
    return

if __name__ == '__main__':
    main()

Test automation #3

So, now the flag is tested, set correctly if needs be and the tests are run. But I still have to run the test script! What a waste of typing. So, the next step is simply to call this script from a git pre-commit hook

Code for this post

The full history for this script can be found here and here.


Tagged: git, programming, pytest, python, software, unit testing, workflow

#efdhack2012 26th May 2012

This one’s a little different. Python West Midlands is hosting a hackday to kick off a new open source project for a very interesting little charity called Evidence for Development(EfD). EfD wants to help people make better decisions about aid projects – at local and national level – by putting real data about the real situation in the hands of the people making the decisions.

If you want to know if your aid programme is making a difference to the right people then you need to model the economy of your target village or district, before and after. Makes sense; simple science right? Problem is you can’ afford a bunch of western econometricians crawling all over the place (cost too much, takes too long) and anyway their cash-based economic models don’t work that well in a place where cash is only a small part of the economy (grow your own; harvest wild food; get paid in kind or cash or both for day labour; trade crops, labour or other goods; etc, etc). So EfD developed simple economic models that work in this environment, that can be learned and applied by locally trained people and that, are built to run on laptops. No reliance on big foundations’ data centres.

Last year EfD, in partnership with Chancellor College of the University of Malawi and The University of  Wolverhampton developed a Python/MySQLapp to model local economies that is already in use in several countries in Southern Africa.

This year the challenge is bigger – to build software that can model national and international economies. The model exists and works (it has a great track record of predicting famine effects from annual summary surveys of rural economies). But the only current implementations are proprietary, ill-supported and not extensible. Smells like open source spirit.

So for this hackday we’re going to have with us the two developers who led the IHM development last year (from Chancellor College in Zomba, Malawi) and the developers of the modeling methodologies from EfD (from Barnes and Surrey – exotic eh?). We’ll have a pretty completeMySQL database schema to work on and we hope to finish the day with a simple demo scenario that downloads reference data about a geographical area (a livelihood zone) produces a spreadsheet template to capture information about that livelihood zone (what they grow there, what they eat, how they make a living) runs some local completeness reports and uploads the captured data for merging (with other livelihood zone surveys) to allow analysis of a national survey.

I’m not a software developer, can I still contribute?

Yes! Absolutely. There are a number of jobs that can be contributed without writing any code. We would really appreciate the support of contributors who can build a web presence for these projects, write user and developer documentation, help spread the word and any number of jobs! If you’re keen to help out, there will definitely be a place for you.

When:

10:30 onwards, 26th May 2012. Please sign up here.

Where:

Thyme Software, Coventry University Technology Park, Puma Way, Coventry, CV1 2TT [map]


Tagged: charity, development, event, evidence_for_development, hackathon, hackday, malawi, mysql, python, pythonwm, software, uk

The great Christmas email experiment of 2011-12

This year I took pretty much all the holiday time I could over Christmas, probably for the first time ever. As an experiment, I let all the emails I received over this period accumulate in my Inobx, with the exception of things like posts to mailing lists which get automatically filtered, labeled and skip the Inbox. Generally, I try to follow an Inbox Zero policy, which means my Inbox is usually empty and every email I get is either dealt with as soon as I read it or saved in a “Next Action” list to be dealt with later. That policy makes it much easier to carve out large blocks of time for more difficult tasks, like writing lectures, marking or programming which all require uninterupted concentration. I think this works pretty decently, and at least I haven’t had to declare email bankruptcy.

So, the point of this experiment was really to see how well my Inbox Zero policy is working as well as I thought and, in particular, whether the bulk of the email I deal with is sensible content that really requires attention.

Of course, the “experiment” as such is a little silly, after all this is email from a vacation period and out of term time, so the results are weighted heavily. Usually I get a lot more email per day and a lot more relevant, sensible email that needs attention and the aim is always to maximise the time spent on those emails and minimise the time spent on unecessary emails.

Starting point

Anyway, enough caveats. My starting point was this:

Inbox: 316

Action list: 50

Before going on vacation I cleared out both the Inbox and the Action List of everything that could be dealt with then. So, the starting point here is all the email accumulated over a short vacation and all the items on my to-do list that couldn’t be finished before the holiday started.

The data

Yesterday I spent a happy (!!) afternoon going through each email and either responding to it, deleting it, reporting it as SPAM or filing it. In a Google Docs spreadsheet I wrote down the sender (anonymously unless the sender was a company), sender type and action for each email or group of emails from the same sender. I say “email”, actually I mean “email thread”. So one email on my spreadsheet here could well mean a thread of many emails from various senders. However, what I’m interested in here is really the aggregate data from the 300 emails, which you can see on this table:

Aggregated data from 300 emails
So, there are two things I’m interested in here:
  1. Where is the email from? Is it from people I need to communicate with or from companies and others sending “news” and other updates that can be ignored or processed in a more convenient way, such as via an RSS reader. Obviously emails from colleagues (including external collaborators) and students are all important. Other senders vary considerably depending on the content of the email.
  2. How were the emails processed? Emails that were deleted or marked as SPAM are emails I don’t want to receive repeatedly, so are best unsubscribed from. Emails that needed real attention can be filtered to be marked as important if they aren’t already.

Where to emails come from?

330 emails broken down by sender type

330 emails broken down by sender type

So, thinking of this email as signal and noise, the signal here is email from students, colleagues, friends and open source projects. Of course, SOME of the other emails will be important too and will need some action too, but this is a rough guide. The total number of “noise” emails, according to the sender, worked out as 78 out of 316, or around 25%.

Now, 25% to my mind is astonishingly low. Given that most of the email that hits my account gets filtered out and never sees the Inbox in the first place, 25% is really not what I expected to see here. 

What happened to all those emails?

300 email conversations broken down by next action

300 email conversations broken down by next action

The other way to look at signal vs noise is how the emails were processed. The signal in this case is the emails that were actioned immediately or saved for working on next week, which was 73 out of 316 or just over 23%. That’s very close to the previous SNR, becasuse the sender of a message is a good predictor of its importance.

Again though, 23% is astonishingly low. The main culprit is web apps and social media apps that send frequent notifications, updates and other fluff. Often when you sign up to these things they subscribe you to all sorts of email alerts automatically, then it takes effort on your part to change your settings and unsubscribe. A better way to deal with this, if you use GMail, is to use the Gmail plus trick which allows you to filter out all these emails automatically.

A point about unsubscribing from mailing lists 

When you unsubscribe from an email alert you are informing the sender that you no longer wish to be contacted. The very LAST thing you then need is another email saying “Well done! You have unsubscribed” which you then have to deal with separately. Seriously, this is a terrible way to treat potential customers. Very few of the email alerts I unsubscribed to did this, but those that did really annoyed me.TripIt, Klout, SAA, Costa, the Electoral Reform Society and UCU: consider yourself mildly whinged at. Hurumph.

End point

Just for the record…

Inbox: 0

Action list: 89

Actioned immediately: 34

The take home…

This stuff is boring common sense. It’s motherhood and apple pie. You know it all already. So you’re doing this already, right?

  • Email is a huge sink of time.
  • Process email in batch mode, once or twice a day. Don’t let incoming emails dictacte your work schedule.
  • Unsubscribe to everything you can at the first chance you get. Better still, don’t sign up in the first place.
  • If you use GMail, use the Gmail plus trick.
  • If you sign up to a lot of web apps and different services with logins and passwords, keep confirmation emails in a specific folder or label (I use web-signups) so you can keep track of which services you already have an account for.
  • Filter and label emails automatically whenever you can. Don’t let anything into your Inbox that doesn’t need to be there (looking at you posts to mailing lists).
  • Learn the keyboard shortcuts on your favourite email client. Use them. Banish the mouse.
  • Deal with emails that can be dealt with immediately, immediately.
  • Keep a “next action” folder of emails that cannot be dealt with immediately. Don’t have them hanging around your Inbox making you feel guilty, nervous and demoralised.
  • Keep a sensible hierarchy of folders or labels to organise your email. Or use something like ActiveInbox.

Tagged: email, productivity

What errors does my Python module define and raise?

On StackOverflow someone asked a whileago whether you can find out what errors a module defines and throws.In Python, a function does not declare that it throws a particularerror object, so you need to look inside the module to see whatexceptions it defines, or what exception it raises. You can do this byreading the docs (RTFM!) but of course they may be out of date, orwhat have you, so an alternative is to use the Python API to do lookfor you.

Which errors does a module define?

To first find which exceptions a module defines, just write a simplescript to go through each object in the module dictionarymodule.__dict__ and see if it ends in the word Error or if it is asubclass of Exception:

def listexns(mod):    """Saved as: http://gist.github.com/402861    """    module = __import__(mod)    exns = []    for name in module.__dict__:        if (isinstance(module.__dict__[name], Exception) or            name.endswith('Error')):            exns.append(name)    for name in exns:        print '%s.%s is an exception type' % (str(mod), name)    return

If I run this on the shutils module from the standard library I get this:

$ python listexn.py shutilLooking for exception types in module: shutilshutil.Error is an exception typeshutil.WindowsError is an exception type$

That tells you which errors are defined, but not which ones arethrown. Of course, if the module has errors with funny names, or onesthat are not subclasses of Exception, then this code will miss them.

What errors are thrown by a module?

To find out what errors a module can throw, we need to walk over theabstract syntax tree generated when the Python interpreter parses themodule, and look for every raise statement, then save a list of nameswhich are raised. The code for this is a little long, but prettystraight forward, so first I’ll state the output:

$ python listexn-raised.py /usr/lib/python2.6/shutil.pyLooking for exception types in: /usr/lib/python2.6/shutil.py/usr/lib/python2.6/shutil.py:OSError is an exception type/usr/lib/python2.6/shutil.py:Error is an exception type$

So now we know that shutil.py defines the errors Error andWindowsError and raises the exception OSError and Error. If wewant to be a bit more complete, we could write another method to checkevery except clause to also see which exceptions shutil handles.

Here’s the code to walk over the AST, it just uses thecompiler.visitor interface to create a walker which implements thevisitor pattern from the Gang of Four book:

class ExceptionFinder(visitor.ASTVisitor):    """List all exceptions raised by a module.     Saved as: http://gist.github.com/402869    """    def __init__(self, filename):        visitor.ASTVisitor.__init__(self)        self.filename = filename        self.exns = set()        return    def __visitName(self, node):        """Only called from within a raise statement.        """        self.exns.add(node.name)        return    def __visitCallFunc(self, node):        """Only called from within a raise statement.        """        self.__visitName(node.node)        return    def visitRaise(self, node):        """Visit a raise statement.        Cheat the default dispatcher.        """        if isinstance(node.expr1, compiler.ast.Name):            self.__visitName(node.expr1)        elif isinstance(node.expr1, compiler.ast.CallFunc):            self.__visitCallFunc(node.expr1)        return

Tagged: lint, python, static_analysis

First Pachube Hackathon #pachubehack

The start of April saw the first Pachube (pronounced “Patch Bay”) hackathon in London, Lancaster, New York, Eindoven, Linz and Zurich. Pachube is doing some very interesting and innovative work quite closely aligned to some of the Internet of Things research we are doing in Wolverhampton.

The London event was great fun, and the nice folks at 01zero-one kept us going through the night with pleanty of coffee and pizza — geek fuel! It was good to meet up with some old friends and make some new ones. Our former student from Coventry, and first Nuffield Bursar Tim Churchard is now a founder at Ignoto Consulting and doing some excellent work in embedded systems design. Great to see one of our graduates doing so well in the current economic climate. It was also interesting to meet Sam the Techie, who I’ve followed on twitter for a while now. Sam is the brains behind the now famous Sukey app, which keeps demonstrators in touch with one another in real time. Sukey is probably one of the few IoT apps that has really been used in earnest by large numbers of end-users and it’s a great example of putting online data to real use. The folks behind Nanode were also there, making good progress on their web-enabled Arduino board, which looks like it’s going to be a great boost to hobbyist hackers. You can sign up to purchase one of the first runs of the board on the London Hackspace wiki.

The hackathon itself produced some really interesting applications. Rainycat came up with a great wearable based on the Arduino Lilypad called Yr in Ma Face! which discourages people from invading your personal space. I’d imagine it would go crazy on the London Tube network.

There was a great RFID app called Display Case which coupled simple real-world avatars with a vertical projector and real-time information:

The Nanode guys made quite a bit of progress and the Arkessa team came up with a nice Arduino hack to produce “banana graphs” with a Lego NXT (warning: charts may not be to scale :P ):

and we had a wifi-enabled umbrella, much like the Senz Umbrella, although possibly more likely to electrocute its users!

My own offering was Marvin the Paranoid Android, which Usman very kindly described as “inspiring”. Marvin is an attempt to create an affective interface out of some ostensibly boring data — the temperature, remaining battery power, and so on from my laptop. Affective interfaces are ones designed to elicit emotions from their users, and to my mind, that’s an important part of making the Internet of Things useful, and more than just a technical concern. Marvin is a chatbot interface, in the style of Marvin the Paranoid Android of Douglas Adams fame. You can find the data that feeds Marvin here and the chat interface itself is hosted here. The AI still needs a lot of work to be really usable, but you can already have suitably patronising and miserable conversations with Marvin, like this one:

 

Puny human: hi marvin

Marvin: Life, loathe it or ignore it, you can’t like it.

Puny human: what is your status

Marvin: Current battery capacity is 57667mWh out of a capacity of 57667mWh that’s 100% Currently at 56.0C. When I get to 107.0 I blow up. Currently working at 118.0% load. Call that reasonable working conditions? I don’t.

 

Rain said to me during the day “if you don’t document things, you lose them”, and that’s something I’m slowly trying to learn. This time around I made a simple slide deck to remind myself how the Marvin system worked, hopefully I’ll slowly get better at documenting this sort of work, although the fact that this blog post has come out so long after the hackathon shows I’ve got a way to go yet!

http://www.slideshare.net/snim2/marvin-the-paranoid-laptop-by-his-owner-snim2

 

 


Tagged: affectivecomputing, affectiveinterface, arduino, chatbot, douglasadams, hackathon, hackday, hacking, internetofthings, iot, marvin, pachubehack, pervasivecomputing, robot, usability, wearablecomputing

Why I will not be on strike with @UCU today #ucustrike

Today, the University and College union UCU are holding a strike relating to pensions and pay. If you want to read a good exposition of why lecturers and support staff have voted for this, Phil Wadler has written an excellent piece and UCU have an official announcement [PDF warning]. As always, there’s an active Twitter stream on the action. Of course, any academic should tell you that it’s a good idea to read both sides of any story, so do go and look.

Our own chapter of the student union have an announcement on why they will not be supporting striking lecturers today and, with great reluctance, I will be in agreement with the SU and crossing the picket line, although for rather different reasons than the SU have cited.

This is a tumultuous time for Higher Education in the UK and we have been recently hit with several, potentially very detrimental, policies from government. These include:

  • increasing the level of fees and creating a fees economy at a time when many young people could not hope to gain a job after secondary school because of the global financial recession, leaving many young people with very few life options after their compulsory education has ended;
  • maintaining the tight quotas and financial penalties for breaching quotas on “home” (UK/EU) students whilst making it more difficult for (uncapped) overseas students to get visas (and so maintaining the odd situation that a University is fined by the government for being popular with students). This is a major problem as most universities already have to spend more to teach students than they get from HEFCE. At the very least, most academics work between sixty and eighty hours a week, so the wages bill for academics is really close to twice the figure on the balance sheets. Most lecturers would rather be offering students more and better tuition when they start to pay full fees, rather than being squeezed by finances into providing less;
  • deregulating the tight restraints on which institutions may award degrees and opening the way for non-research based organisations such as publishing houses to grants degree titles, and
  • limiting teaching and research funding, especially for the arts and humanities. 

 

With such huge threats to the excellent reputation that UK higher education has around the world, you might be forgiven for thinking that there is plenty for UCU to strike over. I would certainly agree, but in a time when we are expecting students to contribute ever more to their own education, to strike over our own pensions and pay seems petty, puerile and selfish and I cannot bring myself to support it.

At this time we in academic and UCU in particular desperately need to effectively communicate the value — both the economic value and the social capital — that Universities contribute to national life. We need to argue that the idea of a university still means something. That students deserve to be taught by true experts in their fields. That the idea of the University to train the next generation of factory workers is not acceptable and University should offer more to students than a chance at a job interview, but be an education for life. To my mind, by taking this very limited, selfish strike action at such a crucial time we have lost any moral high-ground with the government and any real opportunity to communicate our message effectively to the public. In years to come, we will look back at this day and say this was the beginning of the end. What a shame.


Tagged: education, highereducation, higher_education, politics, strike, ucu, ucustrike

Adding a minimal online interface to an imified.com chatbot

Recently, the people who brought you the excellent imified service, for creating IM bots, brought out phono, a simple JQuery interface to phone and IM services. Using Phono, you can create a simple front-end to an IMIFIED bot. The following code does this; you will need to replace the string MYBOT@bot.im with the address of your own bot, and you will need a free API key from phono to make this work.

https://gist.github.com/634149


Tagged: ai, artificial_intelligence, chatbot, imified, imifiedcom, javascript, jquery, phono, phonocom

python-csp Europython round-up

Europython was excellent this year and while the range of talks was very wide, the main themes seemed to be web scripting and web applications, virtual machines and concurrency. Russel Winder gave a keynote on the future of multicore computers and their implications, and a longer talk about Python and the CSP style of concurrency, Michael Sparks gave a lightening talk about his work on Kamaelia,??Andrew Francis talked about implementing ALTing in Stackless Python and Tony Ibbs talked about KBus, which is like DBus but sensible, and I gave an introductory talk on our python-csp project. Following Europython, Russel has written up his own overview of the event and Guido van Rossum has a nice post on his experience of the conference, which mentions CSP related work.

http://www.slideshare.net/snim2/pythoncsp-bringing-occam-to-python

??

python-csp sprint report

Post-talks we had two days of Sprints and, having never been to a Sprint before I’m really amazed at how much we managed to get done in the??python-csp??sprint over such a short amount of time. I concentrated on the online tutorial which was well overdue for an overhaul, and the below is just a brief account of all our other activities — apologies if I’ve missed anyone out or mis-attributed anything:

  • Fabian Kreutz fixed and merged Russel’s Python3 port into the default repository, closed a bunch of ancient branches, tidied up our strategy for importing the code library, fixed a whole load of bugs and hosted a Mercurial clone of the main repository on BitBucket for us.
  • Russel started a MacOS port, found a whole world of issues with that, and fixed a few bugs.??
  • Richard Taylor joined us on the Friday and helped configure Linux to solve the “too many open files on disk” OS error that is thrown when too many channels or processes are created. Tony Heskett told us how to fix the same problem on Mac OS. Richard also gave us some really great ideas about how to use the POSIX standard to finish off Sam Wilson’s work on a C implementation of channels.
  • Joe Metcalfe, Wout Tankink, Urban Skudnik and others went through the tutorials in some detail, fixing bugs and posting a bunch of bug reports. Fabian tried to eliminate some of the dependencies from the examples and make them a bit easier to understand. Urban also wrote a channel poisoning example and the tutorial page that goes with it.
  • Michael Sparks had to go home, but joined us over IRC and gave us a better understanding of the differences between Kamaelia and other asynchronous forms of message passing and the CSP style of programming. Later Michael produced a really interesting OCCAM model of one form of Kamaelia synchronisation primitive, which has been a good prompt to sort out guarded ALTing for python-csp.
  • Stefan Schwarzer went through our testing strategy and started formalising a really neat way to unit test python-csp code and wrote up some unit tests for many of the built-in processes we have in the library. Stefan also got us thinking about??licensing issues for python-csp, which probably deserves a wider discussion elsewhere.??
  • Andrew Francis dropped in briefly on his way to the PyPy sprint, and sent over a deadlock detection algorithm and some other ideas.

Thanks to everyone who came along to the Sprint, it was great fun and hopefully we can keep up some momentum. During the Sprint we added six new project members with commit??privileges??and set up a public mailing list. If you were at the Sprint or already had commit access to the repository you should already have received an invite to the list, but if not it is public so feel free to join.


UNIX one-liner to convert .dia files in batch-mode

UNIX one-liner to convert .dia files to PNG (e.g. when switching from LaTeX to pdflatex):

for f in *.dia ; do dia $f -e "${f/.dia/.png}" ; done

Tagged: bash, dia, linux, script, unix

Setting up the Freeduino v1.16 and Nokia 3310 LCD shield on Ubuntu Karmic

This post contains some brief notes on setting up a Freeduino (or Arduino) and Nokia 3310 LCD shield on Ubuntu Karmic, this should probably work OK for other versions of Ubuntu and other versions of the Freeduino or Arduino.

Installing the Arduino SDK

Firstly, install the Arduino SDK. This requires adding a new repository to your list of software sources, installing the Arduino SDK and removing a conflicting package:

$ sudo add-apt-repository ppa:arduino-ubuntu-team/ppa$ sudo apt-get update$ sudo apt-get install arduino$ sudo apt-get remove brtlly

Now you should be able to find an entry for “Arduino” on your Application –> Programming menu (if you are using Gnome, it might be somewhere slightly different with KDE). That is a link to the Arduino SDK which is a modified version of the Proce55ing IDE if you have used that. It should look like the picture below when you start it.

Installing the Nokia 3310 libraries

Next, you need libraries for the Nokia 3310 shield. You can download these directly from NuElectronics or get a slightly updated version from Andrew Lindsey: http://blog.thiseldo.co.uk/?p=383 Either way, download the .ZIP file and unpack it somewhere in your home directory. The next bit isn’t well documented, but what you need to do is to copy the files from the library to the directories that are expected by the Arduino SDK. Firstly, copy everything over to the Arduino library path:

$ sudo cp -a nokia_3310_lcd /usr/share/arduino/libraries/

Now, if you restart the Arduino SDK and look up Sketch –> Import Library on the menu, you should see nokia_3310_lcd as an item on the list there.

Next, you need to put the example Arduino application where the IDE can find it:

$ sudo cd /usr/share/arduino/libraries/nokia_3310_lcd$ sudo mkdir??/usr/share/doc/arduino/examples/Nokia$ sudo mv examples??/usr/share/doc/arduino/examples/Nokia

Try everything out

Now, if you place the Nokia shield on top of your Arduino or Freeduino (it only fits one way), and attached the Arduino to your USB port you should be able to try out the example application. Restart the Arduino SDK, make sure you go to Tools –> Board and select the board you are using — look on the long chip on the board to find out whether you have an ATmega328 or ATmega168 if you are not sure. Also, go to Tools –> Serial Port to select the port that has been assigned to the Arduino. If Serial Port is greyed out on the menu then unplug the Arduino from the USB port and put it back in again (to force the OS to reassign a new virtual USB device to the Arduino).

Now, go to File –> Examples –> Nokia and open up the example “sketch” or program. Press the Verify button (that looks like a triangle) to compile the sketch. If you have placed the libraries in the right place you should get a message like this at the bottom of the GUI:

Binary sketch size: 3858 bytes (of a 30720 byte maximum)

Lastly, press the Upload button (the one with an arrow pointing right) to upload the compiled code to the board, and you should see something like the results in the photo below.


Tagged: arduino, freeduino, howto, lcd, nokia, tutorial, ubuntu