Steve's blog

A blog about what's going on in Analysis UK...

Home Network

I just finished off some updates to my home network so I thought I'd share a few pics of the main switch rack.

Here it is:
Home Network patch panel

The big thing you will probably notice is that most of the switches are not used and some only very sightly, I do have more switches than I really need at present!

Here's what the box contains, working down from the top.

1) APC PDU – Power switcher.
2) Netgear POE switch
3) 3 COM POE switch
4) Netgear 10/100 Switch
5) Patch panel for the 22 outlets in my flat.
6) Netgear Gigabit Switch
7) HP 10/100 Switch.

How my flats split:

Kitchen:
2 Ports over cupboard on outside wall.
2 Ports over extractor hood/cupboards on inside wall.
4 Ports under worktop.

Living room:
2 Ports by TV.
2 Ports by Rear wall.

Bedroom:
2 Ports by door.

Office (Bedroom 2):
2 Ports by door.
4 Ports by Server/workstation PCs.

Airing cupboard:
2 Ports, yes I really do have 2 network ports in the airing cupboard!

Most of the ports come from the main Netgear Gigabit switch. Currently I have 3 ports connected to the 3COM POE switch.

I only intended to buy 1 POE switch but apparently their like buses. Having waited many months to get a good price on eBay the Netgear POE switch came up as a BIN so I immediately purchased it, then a few days latter I realised that I had one the 3COM POE switch I put a low-ball bid on, net result is 2 POE switches.

This has the advantage that I can have one POE switch powering devices that I want on 24x7 and the other powering devices that I might not want on all the time, so giving me better control over power usage.

If you want to know why I wanted POE switches you'll have to wait for another blog post!

The 10/100 Netgear switch was the original switch I purchased to service the flat before it ran out of ports and I wanted something faster than 100M. I'm leaving it in the rack as it might well stay with the flat when I eventually move out and it's filling a hole I'd have to buy a blanking plate for otherwise.

I was lucky enough to be given the gigabit switch and HP switch, currently the HP switch is also not used.

At the top of the rack is my latest purchase, a UPC PDU (Power Distribution Unit), this means that I can switch off all the unneeded network switches and should I need to I can hard reboot any as well – I needed to do that a few months ago before the UPS was connected when a very brief brownout put the Netgear gigabit switch in a funny state and took down my network.

If you look closely enough you will see the obvious problem – the PDU network comes from the gigabit switch, so if I have a dippy moment and power off that switch I can't switch it on again over the network (it would have been nice to see the APC PDU have 2x network ports!), so I will be sticking my head in the loft if that happens. Should the power fail and the UPS battery run out then the device will switch off, but it's set-up to automatically power on the Netgear switch when power is returned so hopefully I should regain control in that situation.

I've got a few little side projects under way and wanted the APC PDU to play with as it was, but it's turned out to be useful as the POE switches can be noisy when switched on (although I've hacked them and replaced the little 40mm fans for quiet ones which makes a big difference), having 3+ switches all running little 40mm fans can be really noisy when it's in the loft and your trying to sleep!

The whole lot is powered through a little APC UPS, I don't care much for the device, mainly because it screams when the power goes off and that's not amusing when it's in the loft – I've got a network monitor card for a SmartUPS so now all I need is to get a SmartUPS to replace the little one and I'll be happy.

The cabinet it's self is a plastic 19” 7U cabinet I got off eBay, sadly most of the Netgear and 3COM switches were to deep for the original configuration of the cabinet – hence the reason the door is not fitted as it won't close – fortunately their were 2 sets of mounts for the mounting brackets and I was able to bring them forward and the switches just about fit now (about 300mm) otherwise I had them resting on top of the case which was a bit naff.

Here's the switch depths of the 2 POE switches, the maximum I can get in my cabinet is 300mm and that has to include the power lead coming out the back of the switches.
uploads/CAT5 exiting network patch

At the back of the case theirs a bit snake of CAT5 that heads off all over the loft:
CAT5 exiting network patch
This was before I got the PDU, hence the mass of mains leads.

Wiring up the patch panel has been interesting:
CAT5 exiting network patch
You can see that was before I rearranged the switches.

Open Plan Offices – What a HUGE Mistake.

I read earlier today on news.com.au that Open-plan offices are making knowledge workers sick, say Australian scientists - No kidding!

Headphones and missing developer

Problems with open plan offices are hardly a secret. Joel has promoted office spaces for developers for a long time, it's also covered in PeopleWare - although sadly I don't think many managers actually read that book, Jeff Atwood of Coding Horror covered it and I'm sure there are many more instances.

I think the whole office thing is back to front, if you insist on having an open plan office then the managers should be in the open plan parts and the knowledge workers should have the separate quiet offices – managers have to communicate more and know what's happening much more than the workers. Knowledge workers need to be productive and granted communications is really important but not as important as being able to focus on the work.

Now I'm sure most companies would want better value for money out of their knowledge workers and to have a better product on the market. I see a quiet working environment as a major step towards that.

So employers next time you are wondering why your software project cost so much money, why it was so late, why it's so buggy and not as good as the competitors and why there appears to be a skills shortage start by think a bit closer to home and how the business uses it's resources (sorry employees).

Sadly having an office has been seen as a status symbol. More fool the companies that make their knowledge workers work in a noisy office and tuck their managers away in nice quiet offices – You are wasting a fortune in employee productive. With the exception of a few, generally managers are only their to support the workers – without the workers the manager is pointless – the workers are the important bit! (Hint: Think about small companies, they do really well given the lack of managers).

I've had the miss-fortune to work in an open plan office situation for my last 5 proper jobs (I don't count my own business) over the previous 8 years and I'm one of those people who is really sensitive to the noise around me so I can totally agree with the findings.

Noisy environments are stressful, frustrating and prevent you from doing your job to the best of your abilities.

Most of my previous employers have been biotech, pharma or life science instrumentation but my current employer is a large IT focused software company and of all the places I expected to understand about the damage noise does I would expect my current employer to understand(*), sadly this is not the case.

Now the sound of developers working hard is quietness with a few keyboard strokes and the occasional conversation. If like my current position your do code reviews prior to checking in code then this adds to the background noise. If like my current position you have more than 1 person who loves the sound of their own voice and is loud then you are doomed.

Loud person.

Take the bug fixing part of the project when your trying to get the application out of the door (and probably didn't budget much time for bug fixing so it's critical to get it done asap). All the developers are fixing bugs, if you have an office of 20 developers, each fixing 1 bug/day which results in a 10 minute code review. That's 20 * 10 minutes of conversation about code reviews per day. Or put it another way 3 1/3 hours worth of background conversations happing every day.

If those code reviews are about 10 minutes apart then you get a full day of distractions for all of the 20 developer in that one office.

Guess what, it's so easy to introduce side effects and bugs whilst fixing a bug, especially if you are not concentrating, so whilst everybody is trying hard to concentrate to fix the bug and not introduce more they are subject to 50% of the time being a distraction caused by a code review happening in the office (and most likely once the quietness is broken other people will start chatting as well which makes it even noisier). Any then we wonder why so many extra problems get introduced during the bug fix cycle!

Personally I'm a late starter, I like working latter in the day when everybody has gone home and the office is quiet – I generally get more done during the last 1-2 hours than I'm able to do for the bulk of the day because of the background distractions. Many friends criticise me for being late, having the pleasure of missing the rush hour traffic to and from work, but you know what, it lowers my stress levels, I get more done and I'm happier and I guess whilst I'm not stuck in traffic that helps lower my carbon footprint.

Here's some hints to employers looking to get better value for money from developers (I'm sure this or variations of this apply to a lot of developers):


  • I will work for a lower salary at a place that I am able to be in late.

  • I will work for a lower salary at a place that's quiet.

  • I work better latter in the day so you get better value for money if I'm working latter.

  • I'm not a morning person and mornings == stress for me.

  • I get better work done in a quiet office so if you can't offer a quiet office then make sure I can work from home or work late when everybody else has gone.

  • I happy when I'm able to give my best. Background noise causing me to work below par stresses me out, I'm more likely to leave if I'm stressed and unhappy with my work.

  • I'm much more productive and happier given reasonable decent hardware and a few extra dev tools (R# etc).


Here's what doesn't work:


  • Listen to music to drown out the background voices:

    • This doesn't drown out the low pitch part of the voice.

    • It is also uncomfortable to listen to headphones all day long.

    • It discourages communication.

    • If we are listening to internet radio your not going to like the bandwidth usage.

    • To get a good cancelling effect you have the music loud, that annoys others and damages hearing(**).


  • Noise cancelling headphones to drown out the noise in the office.

    • These just don't work for voices.

    • They also suffer from the same problems as music (except the bandwidth usage!)

  • Lots of people in one big office trying to work with more than 1 loud person.

  • Never ever ever combine sales or marketing people in the same office as developers.

  • When employing someone think how loud and chatty they are and what effect that will have on the rest of your team.

  • Please don't reward the loud chatty people by putting them in an office, loud and chatty people are having a negative effect on the rest of your team!

    Loud person distracting worker.

    If you have 2 loud chatty people and they chat for about an hour over the course of a day and this disrupts just 6 other people close by guess what: that's a full day's worth of 1 persons work LOST, you've managed to employ 2 people but only get the benefit of one, and with it irritate the other 6, and guess who's likely to leave first – the chatty ones or the ones trying to work and getting irritated by the others? Guess who feels punished? Not the people chatting!


Not long ago I changed jobs because my previous employer went into administration and at the end of the day I had 3 offers to choose from.

The first of these was offering £5k more than the one I accepted. Here's why I turned it down:


  • It was an 8 am start along with everybody else, no flexibility (despite being a 24 hour operating plant), so if I did have a problem with noise their was no chance of shifting my hours to get a quieter time of day to work in.

  • They also wanted me to work late to communicate with the US – now they said I could occasionally start latter after the initial probation period if I was working a lot with the US and going home late. That just ends up confusing your body as to what's going on.

  • The office didn't look particularly pleasant to work in from the bit I saw (and actually they didn't show me the actual office area during the interview)

  • The coding part of the interview was done in a horrible meeting room and I was given a small screen that wobbled like crazy (I was nearly sea sick) – hardly a good sign.


So how many employers would like to get someone at a discount of £5,000/year? I'm guessing quit a lot. Share holders – how happy would you be that the company you own part of is paying a £5,000 premium? That little office space is going to pay for it's self really quickly and it's highly likely that the cost of flexible working hours is nothing – sounds like a bargain to me.

So improved productive, cheaper staff, less stress and most likely lower employee turn over can all be achieved for free, all that needs to be changed is the mindset, so it's never going to happen is it.

Not listening.

If like me you are a developer and struggling in a noisy office for a company that doesn't get it and your kicking your self for taking a duff job and your now stuck finding something you prefer better because the economy fell apart then check out ChatterBlocker it works much better than music at drowning out background voices, it's not distracting, you can put it up loud if you need to without effecting others and it also works great in the background when listening to podcasts to drown out the noisy people in the office!

(*) although having said that they also think that paying for an employees eye test means paying the legal minimum and saving about £10 on the cost of a normal test, which given us developers spend the day staring at the monitor you'd think they would care about out eyes – they pay for Bupa, provide tea, coffee, fruit but save a few quid on the eye test – go figure! (Guess which bit HR are responsible for!)

(**) I wonder if in a few years time we will see a new set of health and safety litigation where knowledge works sue employers for damaged hearing caused by the constant use of headphones + music used on recommendation by their manager to drown out the background noise of the open plan office.

Build Indicator - Part 3 (The software)

This is part 3 of the Build Indicator series. In this part I describe the communications library and using this as part of a MSBuild task as well as the test harness.

Previous Parts :



License : Please use, copy and modify this code as you wish, all I ask is that you don’t take credit for the bits I wrote. You should ensure it’s fit for purpose before using it.

The Arduino build indicator works via fairly simple RS232 communications so you can adapt your own build monitor (or other system) to use the indicator easily, or download the Arduino build indicator library and use/modify to suite your needs. You can also download the firmare for the Arduino from here.

The library consists of 3 projects at this time :


  • The main communications project.

  • A MSBuild task project.

  • A test harness.



All the software described here is written in C# and targets .NET 2.0 so it should be usable from any .Net 2.0+ project, you can add the AnalysisUK.BuildIndicators.Arduino.dll as a reference or include the project and reference that as part of the solution.

In the download is a Arduino.sln Visual Studio 2005 solution file which includes the main communications project, the MSBuild task project and the Test Harness WinForms program.

The Communications project :



This project consists of four classes and one enumeration.


  • ArduinoController – this is the main class to use for communicating with the Arduino.

  • ArduinoSimulator – this is a mock of the main controller class which does nothing other than to write the command to the debug window, but is useful when hardware isn't available. It is a subclass of the main ArduinoController class.

  • ProjectStatus – this is an enumeration detailing the project status.

  • CommandBase – this is a base class which all commands to be sent to the Arduino should inherit from. Currently there is only one command but it may well be extended in the future.

  • SetProjectStatusCommand – this is a command class which should be sent to the Arduino via the controller to set the project status.



Using the controller :

The below code is from the MSBuild task and shows how to use the command and controller.


SetProjectStatusCommand command = new SetProjectStatusCommand(ProjectNumber, (ProjectStatus)Status);

using (ArduinoController controller = new ArduinoController())
{
controller.CommPort = CommPort;
controller.Open();
controller.SendCommand(command);
}


When the SendCommand method is called with the command this is sent to the Arduino which updates the output corresponding to the ProjectNumber to show the Status.

Using MSBuild :



Included in the download is a MSBuild task. This can be included in a MSBuild project and called to update the status.

You can either copy the targets and task reference from the TestBuildStatusIndicator.proj MSBuild file or use the file directly. You will need to correct the AssemblyFile location.

The ProjectNumber and CommPort should be updated to the Comm port the Arduino is on and the appropriate project number.

To call the sample MSBuild tasks from a Visual Studio command line use :

MSBuild TestBuildStatusIndicator.proj /t:IndicateBuildGood

MSBuild TestBuildStatusIndicator.proj /t:IndicateBuilding

MSBuild TestBuildStatusIndicator.proj /t:IndicateBuildFailed

The MSBuild targets are defined as :


<Project DefaultTargets="IndicateBuildGood" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<UsingTask TaskName="AnalysisUK.BuildIndicators.Arduino.MSBuild.BuildStatusIndicator" AssemblyFile=".\bin\Debug\AnalysisUK.BuildIndicators.Arduino.MSBuild.dll"/>

<PropertyGroup>
<ProjectNumber>1</ProjectNumber>
<CommPort>COM5</CommPort>
</PropertyGroup>

<Target Name="IndicateBuildFailed">
<BuildStatusIndicator CommPort="$(CommPort)" ProjectNumber="$(ProjectNumber)" Status="1" />
</Target>

<Target Name="IndicateBuildGood">
<BuildStatusIndicator CommPort="$(CommPort)" ProjectNumber="$(ProjectNumber)" Status="2" />
</Target>

<Target Name="IndicateBuilding">
<BuildStatusIndicator CommPort="$(CommPort)" ProjectNumber="$(ProjectNumber)" Status="6" />
</Target>
</Project>


Using the Test Harness :



Also included in the project is a test harness, this is a simple WinForms application which again uses the main communications project and provides a simple UI to exercise the build indicator.



Future parts :



I'm currently working on including the Arduino build indicator into CCTray for use with CCNET so that will be available in a future posting.

Analysis UK email problems

Apologies to anybody that's tried to email me in the last week but my emails been broken.

It turns out that the email service I use as a front end had an old personal email address in their billing information for me, so when my annual subscription was due I didn't get a reminder because I no longer have the personal email address I used (I finally ditched Demon and sadly lost the email address I had with them since about 1998 – my advice is don't get an email address tied to your internet provider – better yet, get your own domain name and use that for email so you are not tied to any company – but be sure to remember to renew your domain name!).

Having had lots of spam recently I through that the reduced level of emails was just because the spam was slowing down – the automated status emails from my web sites were still coming through because they went directly to the mail server and not via the front end thing, so it looked like I was still getting emails on that account, hence it wasn't until I sent my self an email from a separate account (I know – I need to get out more) and it bounced that I realised something was wrong.

Hopefully all fixed now.

The irony of the situation is that I signed up with the service so that I wouldn't loose emails if my email server went down. They provide 2 front end mail delivery servers that forward it onto the real mail server when it's running. I think I've lost more email because of it than I ever lost because my server was down.

Vista 64 Blue Screen Hell

I recently updated my development box to a nice new quad core processor and with it stuck in 8Gigs of ram. I would have been more than happy to stick with Windows XP as I had on my old dev box but the 32 bit version is limited to 4G (more like 3.5G) of ram so all that extra goodness would have been wasted, hence I crazily decided to opt for Vista 64.

What a mistake! It's like using Windows ME all over again and we all know what a terrible product that was.

So to start with the motherboard an Asus P5Q PRO for some reason doesn't support sleep which is a big thing with Vista, I would go off to have dinner and come back to find the PC rebooting because it had gone to sleep. Sadly I wasn't always that lucky – it would often corrupt the CMOS and loose the date/time. If I had one of my Arduino based projects such as the connected it would also be frozen at the Bios Legacy USB detect stage.

I can't really blame Vista for what is a motherboard problem so I've disabled the sleep function and replaced it on the Start menu with Shutdown. When I wrote LazyLoad I didn't think it would be useful on Vista because of the improvements Microsoft made – It hasn't taken long for me to realise LazyLoad is still well worth running on Vista!

So onto the real big problem I'm having, almost daily blue screen of death's. This appears to be caused by the ATI graphics card – a Radeon HD 3650, just great. I regularly get a blank screen followed by Vista telling me it's recovered from a stopped graphics driver. However almost daily the screens start blinking darkness and then when I've had enough time to glimpse at the work I'm about to loose it all goes blue claiming an ati driver failed.

Just to really annoy me when the machine reboots Vista prompts with it's “Windows has recovered from an unexpected shutdown” and gives me a “Check for solution” option, it then appears to do something, followed by quietly hiding it's self never to be seen again, not a sorry we couldn't find anything, or a try the vendors web site for the latest drivers, or a yep we know another ati driver problem, nope, it just disappears as if it's embarrassed and wants to quietly leave the room having wet it's self.

Windows has recovered from an unexpected shutdown

I've had ATI cards before and not liked them, I really should have known better. Whilst looking for the link for the 3650 on the ATI site the search summed ati up for me. I entered hd 3650 and hit enter to search, not realising I had to change the “Select Site:” drop down. I got a JavaScript box saying “Please select a site.” and they kindly cleared my search text so I had to enter it again (whilst not making the same mistake of hitting enter) and then select the ATI site. How could something so simple be so unfriendly?

And what's with the improved TCP/IP stack in Vista. I though networking with Vista was supposed to be much improved. If I watch a movie that's on another machine one of two things happens, either the file explorer will freeze and show the green progress bar whilst trying to browse the folders or when I finally open the file my whole PC will freeze whilst Windows Media player opens the file. And if the other machine is busy doing something like a backup I really know about it on my Vista box (BTW – often the other machine is a Vista box!). I thought with 4 cores a gigabit network and an improved TCP stack Vista would still be usable whilst it tried to sort out connections with networked machines. My old XP box with it's single processor was is so much better for networking.

As for the new “improved” windows explorer, I so hate it, I mean really hate it. If I'm trying to copy files or folders with Explorer in details view (which I prefer) from one location to another I regularly end up with them going into a sub folder of the destination because of the change in the way the hover selection works as it's really difficult to get exactly between the folders when dropping. As for default view (list view) that's just to annoying, You've got loads of extra column headings and if you have a long file name it's often obscured, it looks like you can resize the columns but that doesn't work – you have to change to details view to do that – it gets me EVERY time and annoys me intensely every time.

Is it just me or has the audio stuff got worse, my last box (XP) pushed out the audio via the SP/DIF and headphones socket at the same time, I can't see how to do that in Vista, so if I want to switch from headphones to speakers I have to stop what I'm listening to, change the default or use something like WinAmp's settings to change the output (not easy to get to) then change to the RCA Digital output. What a pain in the ****, I want both outputs together – is that such a stupid requirement? I wonder if that's another Asus special.

I'm so very glad FireFox remembers the pages I had open, all to often I've been part way through reading an article for the PC to blue screen on me and by the time I'm back up and running I've forgotten where I found the article. Fire up FireFox and restore - magic! I so wish IE did the same, especially as it's a lot less stable than FireFox and crashes it's self frequently.

So in conclusion, it's really great so much effort has gone into the Aero to make Vista look nice whilst introducing whole new instability issues, revaming Windows Explorer to take annoying to a whole new level whilst totally defeating usability and that the TCP has been speeded up to the point that Vista to Vista networking freezes the machine and browsing a file share regularly messes up, that's on top of the slew of security measures which resulted in me being unable to browse my NAS without having to get into the depths of Vista settings.

I appreciate most of the problems are actually hardware (MB/Graphics card) but it's still annoying to have seen so much effort go into making the thing look nice only to have it fall over, I've seen it all to often with various products where the manufacture has put lots of effort into making the thing look really nice but failed to make a usable product (more on that and my home automation problems latter). Take for example software products that have their window an unusual shape - I know instantly that I'm not going to be able to use it, all to often I've tried software where the products a funny shape and the functionality and usability of the product are just so poor – please please please lets get back to making usable products and get over our obsessive desire for things to look pretty whilst not worrying about being able to use them.

Well the good news is in the hour it's taken me to write this the machines not blue screened!

Build Indicator – Part 2 (The firmware)

This is part 2 of the Build Indicator series. Part 1 – the construction of the hardware is here.

The firmware is written using the Arduino’s own programming language which is much like C/C++, using the IDE provided it’s easy to develop the code and push it down to the Arduino.

I decided that as the Arduino has 13 IO pins it would be a shame not to make these available for 6 build indicators so 6 individual projects could be monitored. I’ve not used OO to implement the code so it’s a little messy with individual arrays for project status, red and green led pins which are indexed based on the project number. I think you can create classes but this has to be done in external C++ files so for a simple application like this I didn’t worry to add that extra complexity.

Serial (RS232) communications is used to send a status message down to the Arduino build indicator to update the project status.

The full Arduino build indicator code can be download here.

License : Please use, copy and modify this code as you wish, all I ask is that you don’t take credit for the bits I wrote. You should ensure it’s fit for purpose before using it.

Variable declaration :


    1 /*


    2   Build Indicator (c) Analysis UK Ltd 2008


    3  *


    4   Digital Pin Assignments:


    5   0 - RX


    6   1 - TX


    7   2 - Project 6 - Green LED


    8   3 - Project 6 - Red LED


    9   4 - Project 5 - Green LED


   10   5 - Project 5 - Red LED


   11   6 - Project 4 - Green LED


   12   7 - Project 4 - Red LED


   13   8 - Project 3 - Green LED


   14   9 - Project 3 - Red LED


   15   10 - Project 2 - Green LED


   16   11 - Project 2 - Red LED


   17   12 - Project 1 - Green LED


   18   13 - Project 1 - Red LED


   19  */


   20 


   21 #define VERSION "1.0"


   22 


   23 // Project not enabled of not connected.


   24 int PROJECT_OFF = 0;


   25 


   26 // Project build failed


   27 int PROJECT_FAIL = 1; // 001


   28 


   29 // Project build good


   30 int PROJECT_GOOD = 2; // 010


   31 


   32 // project building from a failed project.


   33 int PROJECT_BUILDING_FAIL = 5; // 101


   34 


   35 // project building from a good build.


   36 int PROJECT_BUILDING_GOOD = 6; // 110


   37 


   38 // Maximum number of projects.


   39 int maxProjects = 6;


   40 


   41 // Project status codes.  Indexed by project.


   42 int projectStatus[] = {


   43   0, 0, 0, 0, 0, 0};


   44 


   45 // Pins for the Red LEDs.  Indexed by project. 


   46 int redLEDPin[] = {


   47   13, 11, 9, 7, 5, 3};


   48 


   49 // Pins for the Green LEDs.  Indexed by project.


   50 int greenLEDPin[] = {


   51   12, 10, 8, 6, 4, 2}; // pins 0 and 1 reserverd for RS232.





The arrays redLEDPin and greenLEDPin represent the pins to use for the red/green leds and are indexed on the project number (i.e. project 0's red led is on pin 13). The array projectStatus holds the status of the project and again is indexed by the project number.

Setup:


   54 // run once, when the sketch starts


   55 void setup()                   


   56 {


   57   // Initialise the ports for output to drive the LEDs


   58   for (int i=0; i<maxProjects; i++) {


   59     pinMode(greenLEDPin[i], OUTPUT);    // sets the digital pin as output for the green/blue part of the tri color LED


   60     pinMode(redLEDPin[i], OUTPUT);      // sets the digital pin as output for the red part of the tri color LED


   61   }


   62 


   63   // Setup Serial communications


   64   Serial.begin(57600);


   65 }




The setup method iterates through all the projects setting up the pins designated as led’s for output and then sets up serial communications at a baud rate or 57,600. Fortunately the Arduino takes care of the difficult serial comms bits for us.

Main Loop:


   67 // Main loop, runs over and over again


   68 void loop()                   


   69 { 


   70   // Check and Read settings from PC


   71   ReadCommands();


   72 


   73   // Update the LED's to indicate project status'


   74   UpdateLEDs();


   75 


   76   // Idle.      


   77   Idle();


   78 }


   79 




The loop method is the main application loop that the Arduino will enter once setup is complete and will keep repeating.

Within loop we call 3 basic methods, ReadCommands() which will check the serial port for commands from the host, UpdateLEDs() which will update the leds based on the project status and Idle() which just inserts a small delay but can be used for other background tasks.

The comms protocol is a fairly simple one. All messages should start with a byte value of 2 and terminate with a byte value of 3 so the Arduino can easily know when a instruction has been received.

To update a project status send the ascii string “@P[x]=y” with x being the project number 1-6 and y being the status (0, 1, 2, 5, 6).

To query the version number of the firmware send ?V.

I’ve stolen the comms protocol from another project I’m working on with the Arduino that has more commands and queries so I’ve based all commands where the Arduino has to do work on the @ character and all queries on the ? character to help separate out the commands and queries.

RS232 Message handling:


   86 // Read commands sent from the PC


   87 void ReadCommands()


   88 {


   89   // Check if serial data available, if so then read this in


   90 


   91   // Read all from the serial port until no more bytes available looking for the


   92   // start byte (1) of a message.


   93   while (Serial.available()) {


   94     //read the incoming byte:


   95     int incomingByte = Serial.read();


   96 


   97     // Start identifier.  STX


   98     if (incomingByte == 2) {


   99       // Found start byte now read in until we get the end of message byte.


  100       ReadSeialCommand();


  101       return;


  102     }


  103   } 


  104 }


  105 


  106 // Read a command from the serial port.  Read until the read byte


  107 // is an end of message (new line) indicator.


  108 void ReadSeialCommand() {


  109   // Expect maximum of 25 bytes (normally 6)


  110   byte buffer[25];


  111   int index=0;


  112 


  113   while (true) {


  114     if (Serial.available()) {


  115       // read the incoming byte:


  116       int incomingByte = Serial.read();


  117 


  118       // Terminating byte


  119       // Wait for ETX (End of text - transmision)


  120       if (incomingByte==3) {


  121         ProcessRequest(buffer);


  122         return;


  123       }


  124       else {


  125         buffer[index] = incomingByte;


  126         index++;


  127       }


  128 


  129       // Check for buffer overflow and give up if it has.


  130       if (index>25) {


  131         Serial.print("Error:Buffer Overflow.\n\r");


  132         return;


  133       }


  134     }


  135   }


  136 }


  137 


  138 void ProcessRequest(byte request[]) {


  139 


  140   boolean processed = false;


  141 


  142   // Check for Query commands (? at the start)


  143   if (request[0] == 63) {


  144     // Query


  145     processed = ProcessQuery(request);


  146   }


  147   else if (request[0] == 64) {


  148     // Set (@P[x]=0) - Set Project x = status.


  149     processed = ProcessSetValue(request);


  150   }


  151 


  152   if (!processed) {


  153     Serial.print ("Error:Unknown Request.\n\r");


  154   }


  155 }


  156 


  157 boolean ProcessQuery(byte request[]) {


  158 


  159   boolean processed = false;


  160 


  161   switch (request[1]) {


  162   case 86: // ?V - version


  163     processed = SendVersion();


  164   default:


  165     Serial.print ("Error:Unknown Query.\n\r");


  166   }   


  167   return processed;


  168 }


  169 


  170 boolean ProcessSetValue(byte request[]) {


  171 


  172   boolean processed = false;


  173   byte command = request[1];


  174   // Allow ascii version of the fan number.


  175   //Position 2 should be [


  176   byte project = request[3] - 48; // 48 = 0


  177   //position 4 should be ]


  178   //position 5 should be =


  179   //position 6 should be the raw value.


  180   byte value = request[6];


  181 


  182   switch (command) {


  183   case 80: //@P[x]=y Set project x status y.  y is ascii version of the status (0-9).  so subtract 48.


  184     processed = SetProjectStatus((int)project, (int)value - 48);


  185     break;


  186   default:


  187     Serial.print ("Error:Unknown set command.");


  188   }


  189 


  190   return processed;


  191 }


  192 


  193 boolean SendVersion() {


  194   Serial.print ("Version=");


  195   Serial.print (VERSION);


  196   Serial.print ("\n\r");


  197   return true;


  198 }


  199 


  200 // Set the status for the project.


  201 boolean SetProjectStatus(int project, int status) {


  202 


  203   if (projectStatus[project-1] != status) {


  204     projectStatus[project-1] = status;


  205 


  206     // Build failed.  Flash the red LED briefly to get attention.


  207     if (status == 1) {


  208       digitalWrite(greenLEDPin[project-1], LOW);


  209 


  210       for (int i=0; i<6; i++) {


  211         digitalWrite(redLEDPin[project-1], HIGH);


  212         delay(100);


  213         digitalWrite(redLEDPin[project-1], LOW);


  214         delay(100);


  215       }


  216     }


  217   }


  218 


  219   return true;


  220 }


  221 




The method ReadCommands() will read the input buffer until it receives the start byte then call ReadSerialCommand() which reads the rest of the command into a buffer until it received the end byte. I’ve limited the buffer to 25 bytes which should be plenty and if this overflows then we just abandon it. Their is no timeout between receiving the start and end bytes so this could cause a problem if the end byte is not received.

Notice in the method SetProjectStatus() that the project index used is -1 from the project value sent. When sending commands the first project is project 1 however the Arduino uses 0 based arrays.

In SetProjectStatus() if the project state changes to be failure (value 1) then the red led is flashed 6 times to draw attention to the indicator.

Project State Indication:


  222 boolean UpdateLEDs() {


  223 


  224   for (int i=0; i<maxProjects; i++) {


  225     int greenLEDStatus = LOW;


  226     int redLEDStatus = LOW;


  227 


  228     switch (projectStatus[i]) {


  229     case 0: // NC


  230       // No acton


  231       break;


  232     case 1: // Fail


  233       redLEDStatus = HIGH;


  234       break;


  235     case 2: // Good


  236       greenLEDStatus = HIGH;


  237       break;


  238     case 5: // Building from a Fail build


  239     case 6: // Building from a good build


  240       greenLEDStatus = HIGH;


  241       redLEDStatus = HIGH;


  242       break;


  243     default:


  244       redLEDStatus = HIGH;


  245       break;


  246     }


  247 


  248     // Determine project LED pins and set them appropriatly.


  249     digitalWrite(redLEDPin[i], redLEDStatus);


  250     digitalWrite(greenLEDPin[i], greenLEDStatus);


  251   }


  252 }




In the method UpdateLEDs() we update the led status based on the project status.

If you are wondering what happened to status codes 3 & 4 I’ve used a bit based project status. 0001 (1) is fail, 0010 (2) is good, 01xx is building so 0101 (5) is building from a previously failed state and 0110 (6) is building from a good previous good state.

If you want to use indicators other than leds for your project state then you can update the UpdateLEDs() method with another way to indicate the project status (maybe a LCD panel?).

That’s basically the firmware, not much to it, the Arduino does most of the work for us which is the best bit!

To program the Arduino connect it up, install the drivers (my Vista x64 and Vista x86 installs got the drivers from Windows Update without a problem and also installed the VCP virtual com port drivers). Open up the IDE, ensure the board and serial port are correct and load the build indicator firmware, then hit the upload to I/O board button.

In the next entry I’ll talk about the PC application to drive the Arduino.

Build Indicators revisited

Arduino controlled X-Mas tree.

Some time ago I posted about a USB Snowman build indicator, the problem with the first version was the USB IO board I used, its availability was limited and the output was designed as a current sink rather than source, so some modifications had to be made to the board, which isn’t really ideal.

Recently I came across the Arduino project, an open source hardware solution and one of the little Diecimila boards provides a perfect base for revisiting the build indicator. The SnowMan is still in use at home and I wanted one for work as well so I figured Id make another build indicator based on the Arduino.

Arduino Diecimila.

The 13 IO pins can sink or source up to 40mA which is ideal for driving the tri-color led used by the build indicator. The led requires 2 current sources and has a common cathode. The Arduino has a USB interface that provides normal serial port communications to the host PC so interfacing is easy as well.

This time instead of a snowman I decided to use a Xmas tree. They are very similar, basically a lump of plastic with a 5MM LED mounted inside. The Arduino provides multiple IO ports of which I’m using only two and the intention here is to provide some common functionality so that the device could be easily adapted to other forms of build indication (Switching relays, multiple project build indicators, other led’s, buzzers etc).

X-Mas tree as new.

Removing the base and replacing the led is a simple job, either use a flat screwdriver or use the cable exit to push off the base off.

X-Mas tree from underneath.

X-Mas tree base removed.

Pull out the led fitted into the tree using the cable. This is no longer needed.

X-Mas tree led removed.

Now glue the base onto the top of the box the tree is to be mounted on. Previously I used a black ABS box but this time I’m using a ice blue box and this has worked out much better for aligning the parts and seeing the led’s on the Arduino board (RX/TX when programming), and also appeals to the inner geek a little more now that the workings can be seen.

Plastic case with X-Mas tree base glued in place.

Drill a hole through the middle of the base so that it will line up with the middle of the x-mas tree. This is best done with the base stuck to the box as it holds it in place and ensures every thing lines up. The hole should be about 7-8mm so that the LED + resistors pass thought easily.

Hole through Xmas tree base and case.

Now we need to prepare the led. Using a standard Tri-Color led (I’ve used Red + Green) we need to fit a current limiting resistor to the supply legs. One for the red and one for the green component of the led.

Using the datasheet for the led the voltage drop across the red Led is about 2V, this leaves a drop of 3V across the current limiting resistor as it’s driven from a 5V source. I’m going to drive the Led’s at 30mA, so we will need a 100R resistor for the red Led.

The green led has a different voltage drop across it (3.4V) so we need to do the same calculation for that and again aim to drive it at 30mA which means we need a 53R resistor, as I only had a 56R resistor to hand I’ve used that which gives us about 29mA current flow.

The data sheet gives luminous intensity for both red and green at 20mA and the green is much brighter than the red so we may wish at a latter date to play around with the drive current to get a better balance when both red and green are on.

Trim the red and green legs of the led fairly short but leave enough to solder on the resistors and attach these. Next connect a cable to the other side of the resistors and to the common pin on the led. If you prefer you can attach the resistors to the Arduino connector and solder the cable directly to the led.

The Tri-color led.

I used 2 core screened cable as this happened to be what I had to hand and as it turns out by tinning the screen and soldering to the led common pin gives a good sturdy way to physically push the led into the socket in the tree (and pull it out again!). I also put a bit of heat shrinking around the connections to prevent them shorting out.

Led with resistors and wires connected.

Now we need the connection to the Arduino board, the led is connected to pins 12, 13 and GND. This is easy as they are all close together and as an added bonus the Arduino already uses an onboard led on pin 13 for status when starting up which means that the tree flashes when the Arduino is starting up, it’s easy to use other pins if you prefer.

I’ve used a standard 0.1" Molex connector (The type used for 3 pin PC fans), the PCB version is ideal, but soldering the led connecting wire to the PCB side and plugging it into the header in the Arduino rather than mounting it on a PCB.

Connector for the led to Arduino controller.

Led connector plugged into the Arduino.

Note that in the photo’s the red cable is actually for the green led and the blue one is for the red led. It doesn’t really matter a great deal which way round they go as long as you get the correct resistor matched up with the appropriate led. However the default in the firmware is that the red led is on pin 13 and green on pin 12.

Next drill some holes in the base of the box and mount the Arduino. Note that one hole is smaller than the others so I ended up using only 2 mounting points due to my lack of any 2mm bolts.

Arduino mounting points.

The advantage of using a translucent box is finding the place to drill a hole of the USB connector. I elected to use a cone drill and just have a circular cut out for the USB cable to go through, it doesn’t look all that professional but it was quick and it worked a treat!

Hole for the USB connector

Next it’s just a matter of screwing everything together.

X-Mas tree build indicator assembled.

A Green X-Mas tree.


I put 6 small feet on the base of the box as well. Why 6? With sticky feet one always falls off (especially with commercial products!) and then it rocks, with 6 you still have some stability to the device if one falls off.

Now all that’s needed is a little firmware to run the Arduino and some software for the PC to put it to use but that’s going to have to be the subject of the next posting(s).

Recent Site Outages

Apologies for the recent outages on a number of the Analysis UK websites, these included BookSwap.ws, Dollars2Pounds, Pounds2Euro and all the other exchange rate sites as well as this blog.

On Saturday the hosting provider had an explosion and fire at one of it's data centers hosting one of servers. Initial estimates that were given made it look like it would be quicker to leave the sites (it was a Sunday and their usually quiet on Sundays) and wait for the host to get the power back on.

Unfortunately it didn’t resolve that well, after many hours of delays some power was restored but floor 1 had even more damage than was anticipated and power was much slower at being restored, this unfortunately eat into most of Monday (UK time), however Monday evening all was back and well.

I got home Tuesday tonight to find yet another apology from the company saying that this time the generator powering floor 1 had failed and they were sourcing a new one, this took a significant amount of time, especially given how much they like to state N+1 redundancy (i.e. a spare generator should have been to hand anyway). Updates were slow, uninformative, vague and at the point of being misleading – I’ve have yet to see any photo's of anything as well. Eventually power returned at about midnight UK time on Tuesday/Wednesday, so fingers crossed nothing else can go wrong in this world class N+1 redundancy data center!

Sincere apologies to all those affected, this one is going firmly into the experience category and I’m extremely unhappy this has taken so long to resolve, I will look to do more to improve this and hopefully The Planet will learn and improve (if they have any customers left after this!).

I read on GoDaddy some time ago about a problem they had and that they didn’t have geographical redundancy, if your running a serious e-commerce operation and have enough cash for some spare servers get them now and with a different host in a different [part of the] country.

BTW - If you have .co.uk domain names with GoDaddy be sure to renew them extra early as they claim they have to renew them at least a month early, then before the 20th of that month (unless I was getting some BS from the customer support as to why they canceled 4 of my domains over 1 month before the renewal date!).

Earthquake – in the UK!

Minor tremors felt here in Cambridge, thought I was going crazy and fired up Twitter to see other reports, news starting to come through on sky news sometime after.

Turns out I wasn’t imagining things! Apparently 4.7 on the Richter scale.

Unusual to get this in the UK. Only minor here in Cambridge, like a helicopter flying over the house and the only thing to shake was me and the study lamp!

Just woken up and want to get your PC fired up quickly to check out Sky News, BBC News or Twitter? Waiting for lots of background applications starting that you don’t need and just want to fire up a browser quickly? Check out LazyLoad to delay the stuff you don’t need immediately so you can get started sooner.