Author Archive

Arduino, avr-gcc, Eclipse and Windows 8.1

October 31st, 2013 12 comments

Recently I upgraded – and I use the word with some reluctance – to Windows 8.1 and found that in this environment I couldn’t successfully use the avr-gcc compiler (that ships with the Arduino 1.0.5 package) from Eclipse with the AVR Eclipse Plugin because attempts to Build from Eclipse resulted in a failure to start the avr-gcc compiler with the error:

avr-gcc.exe – Application Error

The application was unable to start correctly (0xc0000142). Click OK to close the application.

avr-gcc failing in Eclipse on Windows 8.1

The application was unable to start correctly (0xc0000142). Click OK to close the application.

Setting up my PATH and running the failing avr-gcc on the command line worked fine, but attempting to run avr-gcc via make all from the command line resulted in the same error as when running from Eclipse. At least that eliminated Eclipse from the equation.

Eventually I stumbled across a workaround which is to use a different build of make. I downloaded and installed GNU “make“ for Windows from the GNU Win32 project which installs make.exe into the C:\Program Files (x86)\GnuWin32\bin\ directory.

A quick change of PATH demonstrated this would allow a successful compile from the command line and so I made the equivalent change in Eclipse:

1) Go to Window->Preferences and then to the AVR->Paths section. Here select the entry for GNU make

Eclipse AVR Paths

2) Click Edit… and then Browse… and navigate to the path to the newly installed make.exe


which should leave you with:


3) It should now be possible to do a successful build!

I’m none the wiser to as the actual cause of this problem which doesn’t occur on earlier releases of Windows, so this is a workaround, rather than a true solution.

Categories: Arduino, C++, computing, software Tags:

Typogenetics in F# – Part I

Author’s note: I originally wrote this back in 2009, but never got around to publishing it.

Gödel, Escher, Bach: an Eternal Golden Braid is Douglas Hofstadter’s tour de force of formal systems and the ‘strange loops’ that can arise within them.

Gödel, Escher, Bach

Gödel, Escher, Bach

Such strange loops can, it is claimed, give meaning to symbols where none existed. Written in 1979 it has become classic in its time and a must read for anybody with an interest in computation, computability or the nature of intelligence. If you haven’t read GEB, you should order it now, and take a relaxing vacation for a week or so, where you’ll have the time and mental capacity to internalize its contents, before reading on…

In Chapter XVI of GEB, Self-Ref and Self-Rep, Hofstadter introduces a simple game called Typogenetics — short for Typographical Genetics — which is inspired by the real-world workings of molecular biology. Although vastly simplified, typogenetics captures some essential aspects of cell biology whilst jetissoning the messy biochemical reality. In essence the model is this: Strands consisting of a sequence of bases are translated through a fixed coding into the sequence of amino acids in an enzyme. Enzymes then in turn act upon strands, manipulating the sequence of bases in the strand, copying to new strands and splitting strands. These new strands can also be expressed into enzymes, which act upon them to create new strands, and so on.

In parallel with ploughing through GEB, I’ve been experimenting with F# for software development. First-class functions, partial application and pattern matching — all core features of the F# language — are useful abilities when symbolic manipulation is called for, and the techniques I’ve picked up from Expert F# seemed directly applicable to an functional software simulation of the Typogenetics system.

The typogenetic code in F#

The typogenetic alphabet has only four letters, A,C, G and T – which represent the four chemical bases of classical genetics, Adenine, Cytosine, Guanine and Thyamine.

The structure of DNA. From the U.S. National Library of Medicine.

The structure of DNA. From the U.S. National Library of Medicine.

We can represent this in F# as a discrimiated union,

type Base =
    | Adenine
    | Cytosine
    | Guanine
    | Thyamine

However, writing out literal strands of bases as lists of Bases would soon become tedious, so we provide a convenience function strand, which constructs a list of bases from a character string,

let strand s =
    let fromLetter c =
        match c with
        | 'A' -> Adenine
        | 'C' -> Cytosine
        | 'G' -> Guanine
        | 'T' -> Thyamine
        |  _  -> failwith("Invalid Base code") fromLetter s |> Seq.toList

which can be used thus in F# Interactive,

val it : Base list =
  [Thyamine; Adenine; Guanine; Adenine; Thyamine; Cytosine; Cytosine; Adenine;
   Guanine; Thyamine; Cytosine; Cytosine; Adenine; Cytosine; Adenine; Thyamine;
   Cytosine; Guanine; Adenine]
F# offers special short syntax for functions which consist only of a match, using the function keyword. Using this the above function can be shortened to,

let strand s =
    let fromLetter = function
        | 'A' -> Adenine
        | 'C' -> Cytosine
        | 'G' -> Guanine
        | 'T' -> Thyamine
        |  _  -> failwith("Invalid Base code") fromLetter s |> Seq.toList

Enzymes are sequences of amino acids and in typogenetics there are 15 different amino acids from which these sequences can be constructed. Each amino acid has a three letter name. This can also be represented in F# as a discriminated union,

type AminoAcid =
    | Cut
    | Del
    | Swi
    | Mvr
    | Mvl
    | Cop
    | Off
    | Ina
    | Inc
    | Ing
    | Int
    | Rpy
    | Rpu
    | Lpy
    | Lpu

When strands of bases are transcribed into enzymes, the units of coding are called codons — each consist of duplet (2-tuple) of consecutive bases on the strand, starting from the beginning of the strand. Since a stand may have an odd number of bases, a singlet may be left over at the end of the strand. We represent duplets and singlets in F# as a discriminated union, with parameterised type-constructors taking one Base in the case of Singlet, and two in the case of Duplet.

type Codon =
    | Duplet  of Base * Base
    | Singlet of Base

We can now use pattern matching, using the function sugar, to convert a list of Bases representing a strand into a list of Codons.

let rec codons = function
    | x0::x1::xs -> Duplet(x0, x1)::(codons xs)
    | x::xs      -> Singlet(x)::(codons xs)
    | []         -> []

We can test these functions in F# interactive,

> strand "TAGATCCAGTCCACATCGA" |> codons;;
val it : Codon list =
  [Duplet (Thyamine,Adenine); Duplet (Guanine,Adenine);
   Duplet (Thyamine,Cytosine); Duplet (Cytosine,Adenine);
   Duplet (Guanine,Thyamine); Duplet (Cytosine,Cytosine);
   Duplet (Adenine,Cytosine); Duplet (Adenine,Thyamine);
   Duplet (Cytosine,Guanine); Singlet Adenine]

Each codon duplet in typogenetics codes for a specific amino acid. Trailing singlets are ignored. The genetic code is defined by the following matrix.

An Adenine, Adenine pair is defined as a ‘punctuation mark’ which marks the boundary between two genes. Each each gene translates into a single enzyme.

The following matrix specifies the coding:

The typogenetic code

The typogenetic code

This information can be encoded by the following function,

let decode = function
    | Duplet(Adenine,  Adenine)  -> None
    | Duplet(Adenine,  Cytosine) -> Some(Cut)
    | Duplet(Adenine,  Guanine)  -> Some(Del)
    | Duplet(Adenine,  Thyamine) -> Some(Swi)
    | Duplet(Cytosine, Adenine)  -> Some(Mvr)
    | Duplet(Cytosine, Cytosine) -> Some(Mvl)
    | Duplet(Cytosine, Guanine)  -> Some(Cop)
    | Duplet(Cytosine, Thyamine) -> Some(Off)
    | Duplet(Guanine,  Adenine)  -> Some(Ina)
    | Duplet(Guanine,  Cytosine) -> Some(Inc)
    | Duplet(Guanine,  Guanine)  -> Some(Ing)
    | Duplet(Guanine,  Thyamine) -> Some(Int)
    | Duplet(Thyamine, Adenine)  -> Some(Rpy)
    | Duplet(Thyamine, Cytosine) -> Some(Rpu)
    | Duplet(Thyamine, Guanine)  -> Some(Lpy)
    | Duplet(Thyamine, Thyamine) -> Some(Lpu)
    | Singlet(_)                 -> None

Since two of the codons do not code for an amino acid, an option type is used to wrap the return value.
The transcript function, shown below, applies this decoding to the list of codons to produce a list of amino-acid elements — in fact option AminoAcid elements — since the result may contain None values.

let transcript = decode

Referring back to the decode function, we can see that None is returned for the Duplet(Adenine, Adenine) punctuation mark and for any Singlet. We now need to split the list of amino acids into separate enzymes on the None delimiters using this function,

let split delimiter list =
    let rec split' list' =
        match list' with
        | []                       -> [[]]
        | x::xs when x = delimiter -> [] :: split' xs
        | x::xs                    -> let sxs = split' xs
                                      (x :: sxs.Head) :: sxs.Tail
    split' list

used like this,

> strand "TAGATCCAGTAACCACATCGA" |> codons |> transcript |> split None;;
val it : AminoAcid option list list =
  [[Some Rpy; Some Ina; Some Rpu; Some Mvr; Some Int];
   [Some Mvl; Some Cut; Some Swi; Some Cop]; []]

As you can see, this may result in empty lists, which we can filter out using the standard List.filter function

strand "TAGATCCAGTAACCACATCGA" |> codons |> transcript |> split None
                               |> List.filter (fun x -> not x.IsEmpty);;

val enzymes : AminoAcid option list list =
  [[Some Rpy; Some Ina; Some Rpu; Some Mvr; Some Int];
   [Some Mvl; Some Cut; Some Swi; Some Cop]]

and then we unwrap the element values from the now unnecessary option types with the help of a small function,

> let unpack list = Option.get list

> strand "TAGATCCAGTAACCACATCGA" |> codons |> transcript |> split None
                                 |> List.filter (fun x -> not x.IsEmpty)
                                 |> unpack;;
val it : AminoAcid list list =
  [[Rpy; Ina; Rpu; Mvr; Int]; [Mvl; Cut; Swi; Cop]]

giving us a tidy list of the enzymes, each of which is in turn a chain of amino acids, produced by translation of the genes in the original strand of bases. The single strand in our example contains two “genes” which express two different enzymes. Finally, we wrap all this up in a single function called express as we’ll be needing this gene expression machinery later.

Next time, we’ll look at how to model binding of the enzymes we have expressed back to strands of bases, the next step in closing the Strange Loop of typogenetics.

Categories: .NET, computing, F#, software, Uncategorized Tags:

Inadvertent psychometric testing with Python

At some point – such as during the course of a job interview –  you’ve may have taken a numerical reasoning test with questions such as this:

Q. What is the next number in the sequence 81, 87, 84, 90, 87, ?

See the end of article for the answer.

Now, another one, this time in your Python interpreter.

>>> s = 'python'
>>> s[:-5]
>>> s[:-4]
>>> s[:-3]
>>> s[:-2]
>>> s[:-1]

and the next is the series is…

>>> s[:-0]


The surprise happens because of course the zeroth character is at the beginning of the string, rather than one beyond the end. It took me quite a while today to locate a bug caused by this negative indexing combined with slicing effect, subtly concealed as s[:-x] because intuitively we think that the identity:

s[:len(s) - x] == s[:-x]

is true for all x, when in fact it’s only true for 0 < x <= len(s). If Python was always based on one's complement binary representations I'd suggest that we use negative zero to represent the virtual character one beyond the end of the string and positive zero to represent the character at the beginning. I suspect however that my PEP would be short-lived. And rightfully so!

˙Ɛ6 sı ɹǝʍsuɐ ǝɥ⊥

Categories: Python Tags: ,

Manual upgrade of CrashPlan on NexentaStor

March 31st, 2012 No comments

Thanks to some useful recipes and particularly these concise intructions I’ve been successfully running CrashPlan on my NexentaStor NAS server for a good while now, and very reliable it has been too. Although CrashPlan is not supported on Nexenta (Solaris kernel with Debian userspace) it’s straightforward to select the right components from the Linux and OpenSolaris installers and get a working system.

The only aspect of this hybrid install the doesn’t work correctly is the auto-upgrade feature of CrashPlan. Occasionally, CrashPlan will fail because of the autoupdate process. Sometimes, a simple server restart – skipping the upgrade – is sufficient, but other times it’s actually necessary to upgrade the server. This process is documenting below.

This shows a manual upgrade from CrashPlan 3.0.3 to CrashPlan 3.2.1.

Login as root into the Nexenta Management Console (nmc) and take a ZFS snapshot in case we screw up:

nmc@manod:/$ setup appliance checkpoint
Option ? create
Created rollback checkpoint 'rootfs-nmu-003'

Then, as logged in as admin at a regular bash shell, remove the unpacked previous versions:

$ cd downloads/
$ rm -rf CrashPlan
$ rm -rf CrashPlan-install

Next, download the latest CrashPlan installers for both Linux and Solaris:

$ wget
$ wget

Now untar the Linux version, which results in a Crashplan-install directory,

$ tar zxfs CrashPlan_3.2.1_Linux.tgz

and the Solaris version which creates a Crashplan,

$ tar zxfs CrashPlan_3.2.1_Solaris.tar.gz

Open a second shell as root and prepare the ground for installing the new Crashplan:

The CrashPlan installer doesn’t like installing a newer version over the top of an existing version, so you’ll have to remove the old version, taking care to preserve your configuration. Previously, I’d installed CrashPlan into /opt/crashplan, so I did:

% cd /opt/
% mkdir crashplan-conf.old
% cp -R crashplan/conf/* crashplan-conf.old

The remove the original installation:

% rm -rf crashplan

Back in the original admin shell run the installer. Refer to your existing my.service.xml in crashplan-conf.old file to help you recall the answer to the questions the installer will throw at you.

$ cd CrashPlan-install
$ sudo ./

After the lengthly EULA you’ll get:

Do you accept and agree to be bound by the EULA? (yes/no) yes

What directory do you wish to install CrashPlan to? [/usr/local/crashplan] /opt/crashplan
/opt/crashplan does not exist. Create /opt/crashplan? (y/n) [y] y

What directory do you wish to link the CrashPlan executable to? [/usr/local/bin]

What directory do you wish to store backups in? [/opt/crashplan/manifest] /volumes/welshpool/crashplan/backupArchives

What directory contains your SYSV init scripts? [/etc/init.d]

What directory contains your runlevel init links? [/etc/rc.d] /etc/rc3.d

Your selections:
CrashPlan will install to: /opt/crashplan
And put links to binaries in: /usr/local/bin
And store datas in: /volumes/welshpool/crashplan/backupArchives
Your init.d dir is: /etc/init.d
Your current runlevel directory is: /etc/rc3.d

Is this correct? (y/n) [y] y

Unpacking /./CrashPlan_3.2.1.cpi ...
44127 blocks
ln: creating symbolic link `/usr/local/bin/CrashPlanDesktop' to `/opt/crashplan/bin/CrashPlanDesktop': File exists
ln: creating symbolic link `/etc/rc3.d/S99crashplan' to `/etc/init.d/crashplan': File exists
cat: /proc/sys/fs/inotify/max_user_watches: No such file or directory

Your Linux system is currently configured to watch files in real time.
We recommend using a larger value; see the CrashPlan support site for details

ps: unknown output format: -o cmd
usage: ps [ -aAdefHlcjLPyZ ] [ -o format ] [ -t termlist ]
[ -u userlist ] [ -U userlist ] [ -G grouplist ]
[ -p proclist ] [ -g pgrplist ] [ -s sidlist ] [ -z zonelist ] [-h lgrplist]
'format' is one or more of:
user ruser group rgroup uid ruid gid rgid pid ppid pgid sid taskid ctid
pri opri pcpu pmem vsz rss osz nice class time etime stime zone zoneid
f s c lwp nlwp psr tty addr wchan fname comm args projid project pset lgrp
Starting CrashPlan Engine ... Using standard startup

CrashPlan has been installed and the Service has been started automatically.

Press Enter to complete installation.

Important directories:
Default archive location:

Start Scripts:
sudo /opt/crashplan/bin/CrashPlanEngine start|stop

You can run the CrashPlan Desktop UI locally as your own user or connect
a remote Desktop UI to this Service via port-forwarding and manage it
remotely. Instructions for remote management are in the readme files
placed in your installation directory:

To start the Desktop UI:

Installation is complete. Thank you for installing CrashPlan for Linux.

Actually, CrashPlan will not have started at this point. First we need to fix our installation by copying a couple of files from the Solaris installer over the top of those the Linux installer has just put in place:

$ cd ../CrashPlan
$ sudo cp root/opt/sfw/crashplan/bin/CrashPlanEngine /opt/crashplan/bin/CrashPlanEngine
$ sudo cp root/opt/sfw/crashplan/ /opt/crashplan/

Then, back in our root shell, we copy our original CrashPlan configuration back into the new installation.

% mkdir
% cp -R conf/*
% rm -rf conf
% mv ../crashplan-conf.old/ ./conf

and start CrashPlan,

% /etc/init.d/crashplan start

CrashPlan GUI

I’m running a headless CrashPlan server with the graphical client running on Windows. The client manages to update itself without incident, so no further action is needed.

Categories: nexentastor Tags: ,

An Atlas of Arduino Ethernet Shields

January 1st, 2012 9 comments

Have you ever wanted to find the schematic or PCB layout for your Arduino Ethernet shield, but been frustrated by the lack of version or revision information printed on the shield itself? Have you found the version numbering terminology for Ethernet shields confusing and inconsistent? The Atlas of Arduino Ethernet Shields is here to help!

The folks managing the Arduino website seem to have a penchant for showing pictures of one shield and offering schematics for another right along side or even showing pictures of different shields with incorrect labelling. This is compounded by that fact that many shields don’t have useful version or revision information printed on the shield itself. Finally, there seems to be an element of folks in the community second-guessing or inventing shield version numbers (if it came just before 5.0, it must be 4.0, right?) which just makes a bad situation worse. Until the Arduino folks get their change management practices in order, pages like this will be needed to clear up the confusion. I hope you find it useful!

Any errors below are my own, and I’ll be happy to correct them if you can provide information with a more reliable provenance than “off the Internet”.

This guide includes pictures of the Ethernet shields and links to the corresponding schematics and board layouts.

The following shields are presented, in order of age:
Official Arduino Shields

  • Ethernet Shield 01
  • Ethernet Shield 05 or Ethernet Shield V5
  • Ethernet Shield 06 or Ethernet Shield V6
  • Ethernet Shield R3

Unofficial or Impostor “Arduino” Shields

Regrettably, some shield have been released using the “Arduino” name, although they are not offical Arduino designs. These shields use a different chipset and are not (yet) documented here. This further confuses an already murky picture and is misleading to consumers.

  • Arduino Ethernet Shield V1.0
  • Arduino Ethernet Shield V1.1

Read more…

Categories: Arduino, Electronics Tags: ,

My first Printed Circuit Board arrives

September 10th, 2011 1 comment

Followed my recently renewed interest in hardware and electronics—a hobby which has been dormant for about twelve years— I’ve had my first printed circuit board (PCB) made commercially. I’ve always made my own PCBs before, starting with pressing Letraset symbols directly onto copper boards for etching in a ferric chloride solution back in the 1980s. Later I graduated to photoresist based techniques, which at least meant I could re-use my designs. Today there is little point in doing this stuff at home when commercial services are available – you get much better results and you avoid also that messing about with chemistry.

I’ve been using the free Eagle CAD to design my PCBs and used PCB Train in the UK for manufacturing. My first design is a bidirectional optoisolator for the I²C bus. See below for both the design and the reality.

I obviously still have a something to learn because although the component outlines and some of the labels made it through to the end result the component names did not. Fortunately there are only a few components! Also, I notice that my font does not match the manufacturers font.

Eagle CAD design for an I2C optoisolator

Eagle CAD design for an I2C optoisolator

I2C optoisolator PCB

Categories: Electronics Tags: ,