Category: Sci/Tech

AVR microcontrollers and Arduinos. (by )

I'm a fan of the Atmel AVR microcontroller. The main competitors in its area are the older 8051 and PIC architectures, which have less pleasant instruction sets and are generally harder to program.

Ease of programming is key. Most AVRs can be programmer via a SPI link, which is just four digital I/O pins following a widespread standard that most microcontrollers can drive, and there are widespread interfaces to drive an SPI bus from a PC. It's almost as good as the LPC2000 series 32-bit microcontrollers' asynchronous serial programming interface, which can be driven from an RS-232 port with a little bit of level shifting. I'm also a fan of the LPC2000s, but they fit into a higher-powered niche than the AVRs!

A long time ago I did some AVR development professionally, with a programming board driven from a PC parallel port by some Windows software. I still have the board, and a windows PC with a parallel port and the software installed sitting under a desk, but the "activation energy" of getting the PC powered up and plugged into a keyboard and monitor, and digging out the board, and having to deal with Windows-based development software and all that has stopped me from doing anything with AVRs for a while, given my shortage of time.

However, Sarah has tasked me with developing some electronics for her, as part of a project she's working on. And it looked like the easiest way of doing what's required will be to drop an AVR in.

But rather than dig out the Windows-based dev environment, I've just picked up a USBtiny ISP kit for less money than my original AVR dev system cost. It runs off of a USB port, and supports an entirely open-source AVR toolchain that I can run on my laptop. Inside, it's just an AVR itself, with a USB interface on one end and a SPI interface on the other; everything that I need in one neat little package.

As a plus, it has a cable coming out that I can plug into a header on the board the AVR is part of; my old dev board needed me to pull the chip out of its circuit and put it into the board to program it. Pah!

But while I was there, I also picked up an Arduino Uno. This is a little gadget that has been taking the hobbyist electronics world by storm lately; it's basically an AVR on a board with an inbuilt USB programming interface and a bunch of female headers to make it easy to wire up to various things, and some software to let you program it in C easily with a useful library. There's a wide range of boards that plug directly into the headers to do all sorts of fun stuff, too.

Now, I'm a bit disdainful of the Arduino; given the ability to program bare AVRs directly and to assemble my own circuits on protoboard, I can easily do all sorts of stuff that Arduinos can't, at a fraction of the cost.

However, they're great for beginners, as they are plug and play devices; you can get started without touching a soldering iron or having to work out which pin is which. My disdain is purely personal, I think they're a great thing for the community as a whole 🙂

So why am I getting one, I hear you ask? Well, I have a wife who wants to be able to control LEDs and a six year old daughter who is passionate about building a robot, so I'll be glad to have an easy-to-use module I can just hand them rather than needing to build AVR boards for them all the time; but mainly, I plan to use it as a Bus Pirate clone by putting a FORTH on it along with some words to do things like I2C and SPI...

Goldy (by )

Goldy the Fish

This is a rubbish photo of the fish but until he becomes a bit more accustomed to things it is probably all we are going to get - his name is Goldy the Goldfish and Jean won him at the Fair. We were a bit alarmed to see that this was still going on and the more we explained why it wasn't a good idea to get one of the fish the more determined she became to get one as they looked so sad :/

So to cut a long story short she had a set budget for the Fair - she got a goldfish - we all went home to sort the gold fish out - she insisted on carrying him home herself and fretted about weather he could breath and showed him to any and all other children we passed along the way.

I told of my carnival fish Sandy and Shelly that I had at her age and Daddy spoke of how he and his mother used to win as many of them as they could in order to save them when he was little.

Alaric turns out to be a fish expert (at least as far as goldfish are concerned) and we had wanted to get fish as the New House Pets as there had been fish here when we came to look around.

Once home Alaric and Jean set about equalising temperatures of water with the bag in a bowl - so that the poor thing wouldn't get shocked being put in new water. Then we zoomed out to buy supplies. Which being a bank holiday wasn't that easy!

It is only a small tank for now as we just don't have the money but hopefully say next month we can get a larger one - Goldy seems abit worried about the space to be honest and has mainly hidden behind the plastic plant and dug himself a little whole in the gravel.

Today we went to the Aquatic Habitate to get a real plant and a snail - Jean wanted a shrimp but apparently Goldy would eat it (it was not much smaller than Goldy!). Anyway Jeany has named the snail Slimy and is now obsessed with alliteration :/

Again Jean insisted on carrying the snail and has been very militant about feeding the fish and has even taken to remembering to feed her rabbit without being reminded.

I'm glad we have the fish and we are all looking forward to establishing an ecosystem but we were not happy to find them at the Fair and worse than that - in rescuing Goldy we are supporting the trade :/ But Goldy actually came out to see us today when we came in which we think is a good sign 🙂

The Tooth Fairy Left a Letter (by )

The Tooth Fairy's response to Jean's letter in Tooth Fairy Language

Jean lost her second tooth in the new house yesterday and spent the day worrying that they wouldn't find it as we still haven't found the tooth cusion I'd made her. She was also doing lots of wondering about how the tooth fairy would get into the house and lift the tooth and swap the money and did they go big/small, or could they walk through walls and were they a boy or a girl?

So she left a letter.

And the tooth fairy answered it. I thought it was just pictures but Jean pointed out it was a letter written in Fairy Language so she immediatly demanded to go on the computer to see if wikipedia could help her translate it. But after some google searching it became evident that there are lots of different fairy languages and dialects and when Jean looked closer she found that the symbols were very toothy and so we came to the conclusion that this is a specific tooth fairy language.

There are teeth and pliers and ladders and pillows and moons.

I told Jean we would probably have to wait until Daddy got home and she could work at translating it with him. She looked very serious and took the letter and sat staring at it about ten minutes later she announced that this symbol was M and this symbol N and before long she had worked out the second word was Jean.

'It now sort of looks like Jean as well Mummy' and she's right it does. She got the first few lines translated before school. And there was me thinking I would have to phone Tooth Head Quarters and ask for a key so we could find out what the letter ment.

Of course as the fairy borrowed one of mummy's pens Jean did initially accuse me of writing the letter until I pointed out I couldn't read what it said.

zmiku: An automation daemon (by )

A few years ago, I wrote my own service monitoring system for my servers and networks; I did this because Nagios, the common choice, was just too complicated for my tastes and didn't cleanly fit my needs. And so, The Eye of Horus was born, and has been monitoring my servers ever since. I open-sourced it, but I've not migrated it to the new Kitten Technologies infrastructure yet, so I don't have a link.

A design goal for Horus was to limit what needed to be installed on the monitored servers; it's a Python script that you run from cron which sshes into the servers and runs shell commands directly; the results are sucked back from standard output. The configuration file format is easy to work with, and it's modular - the python script spits out a new status file listing the status of all the services that a set of CGIs uses to produce HTML reports on demand and to update rrdtool logs of measurables, and produces a list of changes to be fed to a notification system.

However, it has some rough edges - I decided to make the shell commands run on the remote servers all output a standard format of report, which means mangling the output of commands such as pidof with sed and awk in order to produce them, which is a pain to do portably. In general, support for generating different commands to get the same report on different platforms is poor, too. I never got around to implementing hysterisis in the change detectors to put a service that's rapidly failing and recovering into an "unstable" state. And it's written in Python, when I've migrated all of my new development into Scheme.

I was tinkering with the idea of a straight rewrite in Scheme, with the rough edges fixed up, when I noticed a convergence with some of my other projects beginning to form.

I've long wanted to have a system where some small lightweight computer (perhaps a Raspberry Pi), attached to the home LAN, drives speakers as a music player, streaming music from the home file server. There's off the shelf stuff to do that, but I wanted to go a little further and also provide a text-to-speech notification system; the box would also have a queue of messages. If the queue was not empty, it would pause the music (perhaps with a nice fade), emit an announcement ding sound, then play the messages in turn via a text-to-speech engine. I had previously had some success in helping my wife manage her adult ADHD by putting a cronjob on her Mac that used the "say" command to remind her when it was time to have lunch and the like, as she easily gets too absorbed in something on her laptop and forgets everything else; I thought it would be good to extend that so it worked if she wasn't near her laptop, by making it part of a house-wide music system composed of music streamers in many rooms. And it would be a good place to route notifications from systems like Horus, too. And as the house we lived in then had a very long driveway, we could have a sensor at the end of the drive speak a notification if a car entered the driveway (in the new house, we have a similar requirement for a doorbell that can be heard in distant rooms...). And so on.

But that started to lead to similar design issues as the notification system in Horus; sometimes a single event causes a lot of notifications to be generated, which spam the user when you really just want a single notification that tells them all they need to know. Horus has some domain-specific knowledge about what services depend on what listed in the configuration file, and it automatically suppresses failures that "are to be expected" given root failures, but it could be smarter (for instance, if the failure occurs after the root service has been checked and is fine but before the child services have been checked, then it will notify of the failure of all the child services, rather than noticing the suspicious trend).

And when multiple events occur in the same time span, yet are unrelated so such tricks can't be applied, some notion of priority and rate limiting need to be applied. If ten thousand notifications suddenly appear in the queue in a single second, what's the system to do? Clearly, it will start fading the music down the very instant a notificatoin arrives, but by the time it then gets to start talking a second later, it may have recevied a lot of messages; now it needs to decide what to do. Repeated messages of the same "type" should be summarised somehow. A single high-priority message should be able to cut through a slew of boring ones. And so on.

At the same time, I was looking into home automation and security systems. There you have a bunch of sensors, and actions you want to trigger (often involving yet more notifications...) in response to events. And similarly I wanted to try and automate failover actions; host failure notifications in Horus should trigger certain recovery activities - but only if the failure state lasts for more than a threshold period, to make sure expensive operations are not triggered based on transient failures.

Programming these complex "rules", be they for automation, analysing the root cause of failures from a wide range of inter-dependent service statuses, or deciding how best to summarise a slew of messages, is often complex as they deal with asynchronous inputs and the timing relationships between them, too; specialist programming models, generally based around state machines, help a great deal.

Also, having a common infrastructure for hosting such "reactive behaviour" would make it possible to build a distributed fault-tolerant implementation, which would be very useful for many of the above problems...

So, I have decided, it would be a good idea to design and build an automation daemon. It'll be a bit of software that is started (with reference to a configuration file specifying a bunch of state machines), and then sits there waiting for events. Events can be timers expiring, or external events that come from sensors; and the actions of the state machines might be to trigger events themselves, or to activate external actuators (such as the text-to-speech engine or a server reboot). And a bunch of daemons configured to cooperate would all synchronise to the same state in lock-step; if daemons drop out of the cluster, then all that will happen is that sensors and external actions attached to that daemon will become unavailable, and state machines which depend on them will be notified. In the event of a network partition separating groups of daemons, the states can diverge; a resolution mechanism will need to be specified for when they re-merge.

Having that in place would mean that building a service monitoring system would merely involve writing a sensor that ran check commands, and a standard state machine for monitoring a service (with reference to the state machines of services it depends on), generating suitable events for other consumers of service state machine to use - and human-level notification events in a standard format recognised by a general human notification handler running in the same automation daemon cluster.

The shared infrastructure would make it easy to integrated automation systems.

Now, this is a medium-term project as what I have is working OK for now and I'm focussing on Ugarit development at the moment, but I am now researching complex event processing systems to start designing a reliable distributed processing model for it. And I've chosen a name: "zmiku", the Lojban word for "automatic" or "automaton"; its goal is, in general, to automate complex systems. As I apply it to more problems, I'd like to bring in tools from the artificial intelligence toolbox to make it able to automate things in "smarter" ways; I feel that many of these techniques are currently difficult to employ in many cases where automation is required, so it would be good to make them more available.

Science the Universe and Everything erm… including Cake Pops (by )

The Death of Cake Pops

So I have had my eye on a cake pop machine since before christmas and have bought one for basically £20 from lakeland as the amount of ideas I am having for them means I can't sleep and Jeany wants a darleck cake for her birthday so I would have to get one then!

But I have also been thinking on science and science communication and things right so two creative things that aren't cooking have come out of this already.

One is a bizar video of the cake pop characters that Jean and Alaric made called The Gape Mouthed One and is obviously part of a series not to mention the stills I tool will be finding their way onto the Wiggly Pets blog.

Then there is a poem. It is about the way I think basically and came out of Alaric's impression of me talking just after we got the cake pop machine. I have recorded as it was only written last night and I haven't had a chance to sort out the spelling issues yet 🙂

It is called ADHD The Polymath Dream.

On top of that I have found myself looking at Science Communication courses which is probably nuts but it occured to me that I now live in walking distance of a train station that can get me at least to either London or Bristol.

WordPress Themes

Creative Commons Attribution-NonCommercial-ShareAlike 2.0 UK: England & Wales
Creative Commons Attribution-NonCommercial-ShareAlike 2.0 UK: England & Wales