Old Money

Have you ever been reading an old novel and come across a monetary amount and thought “how much is that equivalent to today?”. Well wonder no more.

Old Money will tell you how much a specified historical amount is equivalent to at any other point (1264 – 2008). It presents two figures; one based on the Retail Price Index and another based on average earnings.

The data is derived from the data available on MeasuringWorth. The full data set isn’t used – I took 5 year averages to reduce the size, so I recommend you visit the original source if you want more accurate figures.

Created in response to a request in the B3ta newsletter.

Posted in Web | Tagged , , | Leave a comment

DOOMWATCH

Short of time? Life too hectic? Remove the daily chore of reading the news; simply use DOOMWATCH.

DOOMWATCH removes the hassle of having to actually read the news to find out what you need to be afraid of. Using state-of-the-art Science™ it analyses various news sources to determine exactly what will cause the downfall of society today.

By default it uses the BBC News service, but if you need an extra dose of pessimism, it also include a Daily Mail mode – guaranteed to included 150% extra baseless panic!

Update: Now with extra features, and default Daily Mail. Woo!

Posted in Web | Tagged , , , | Leave a comment

Tea Desktop Wallpaper

I’m quite fond of tea.

Tea Desktop Wallpaper

Tea Desktop Wallpaper

Posted in Images | Tagged , | Leave a comment

PHP and the Arduino – Follow-up

I’ve had a bit of interest on the original entry, asking for more detail on the code used in the video demonstation at the end.

Download the relevent files here: arduinophp.zip

The zip file contains three files: index.php, serial.php and arduino_serial.pde. Two more files are required: the jQuery JavaScript library, and the PHP Serial class.

The code isn’t exactly elegant. It was just something I was playing around with, so there is probably scope for a lot of improvement. I’m not always great at explaining things like this, but I’ll give it a crack:

index.php

This doesn’t actually need to be a PHP file, since it only contains HTML and JavaScript. It’s just force of habit that caused me to save it as .php instead of .html.

This is the file I navigated to on my iPod touch. It consists of a HTML form containing two option boxes; one to select the LED and another to select the brightness. The value attributes on the options contains the actual data that’s sent to the Arduino.

An onClick event is added to the submit button that triggers the AJAXness, which is done using jQuery’s getJSON function. It calls serial.php with the values from the option boxes as GET variables. It also displays the returned values from serial.php on the page.

serial.php

This file does the actual communication with the Arduino. If first checks that the necessary GET variables are set, then does a bit of input sanitising and then constructs a packet to send via the serial port to the Arduino. The packet is three bytes:

  • The first byte is an @ symbol, which denotes the start of the packet to the Arduino.
  • The second byte is the index (0, 1, 2) of the LED to adjust, encoded to ASCII using PHP’s chr function.
  • The third byte is the desired brightness (0 – 255), similarly encoded using chr.

This is then sent, and the response from the Arduino is echoed.

arduino_serial.pde

This is the code loaded onto the Arduino itself. The most important part of it is the nest of ifs that check for and interpret the data packet sent by serial.php:

if (Serial.available() > 2) { // if there are at least 3 bytes in the serial buffer
  int p,i;
  incomingByte = Serial.read(); // read first byte
  if(incomingByte == 64){ // check if it is packet start (@ = 64 in ASCII)
    p = Serial.read(); // read second byte
    if(p >= 0 && p < numPins){ // check it is within a valid range
      i = Serial.read(); // read the third byte
      if(i >=0 && i <=255){ // check it is within a valid range
        set(p,i); // set LED p to brightness i
        printVals(); // respond with status
      }
    }
  }
}

That’s basically it. Hopfully that makes sense…

Posted in Hardware | Tagged , | 8 Comments

Window 7 Beta: Boot Camp & VMware Fusion

After reading various articles about Windows 7, curiosity got the better of me and I downloaded the beta from Microsoft. Since I have (nearly) sold my little gaming PC in anticipation of replacing it and my MacBook Pro with an iMac that can handle all my computing duties, I was also hoping that Windows 7 would be a good base for Steam and the associated games.

I followed the instructions I found on Simple Help.net, although there’s not much difference in installing Windows 7 than XP or Vista. Basically:

  1. Use Boot Camp Assistant to partition your drive (make sure you have a back-up first!).
  2. When that’s done, insert the Windows 7 beta DVD and click ‘Start Installation’.
  3. Format and install Windows to the drive that has ‘BOOTCAMP’ next to it.
  4. Let the installer do its thing.
  5. When you’re at the Windows desktop, use Windows Update to get graphics drivers, etc. Sound probably won’t be working at this point.
  6. Insert your Leopard installation DVD and install the drivers from there. Done.

Assuming that all went well, you now have your Mac dual-booting with Windows 7. Hurrah.

I use VMware Fusion on my Mac to run various other operating systems, and it has a rather nifty feature whereby it can boot the operating system installed on your Boot Camp partition as a virtual machine. Very handy indeed, and I wanted to make use of this with Windows 7 so I could let Steam download game content without having to spend hours away from OS X.

Firing up Fusion, it detected the Boot Camp partition and without any setting up I could boot straight into Windows. Neat. On the first boot it detected and installed drivers for various (virtual) hardware devices and requested a restart. After that, I installed VMware Tools, which requires another restart. Finally, I have a working system. Or do I? No, because it hasn’t installed any drivers for the ethernet controller and as such has no network connectivity.

Googling yielded some results suggesting a similar problem can exist in Vista under VMware (not necessarily Fusion). The solution is to install the AMD PCnet drivers in the virtual machine; they can be found here: AMD PCnet Windows Drivers. Download the latest version (4.5.1) and transfer to the Windows 7 virtual machine (you can drag-and-drop the folder from OS X into the virtual machine if you have VMware Tools installed). Find the errant Ethernet Controller in Device Manger, right-click and select ‘Update Driver Software’. Point the driver wizard at the folder containing the AMD drivers and bingo. It should be recognised as an ‘AMD PCNET Family Ethernet Adapter (PCI)’, and we should now have Internets!

Install the driver via the Device Manager

Install the driver via the Device Manager

Performance inside the virtual machine isn’t great on my machine (2.0GHz Core Duo, 2GB RAM, of which I’ve given Windows 7 1GB), but it’s adequate for what I want it for. It certainly seems happier than Vista did when I tried it in a virtual machine, and it takes up far less space – 7.8GB with Boot Camp utilities, VMware Tools, Firefox and Steam (no games yet) installed. If I recall correctly, Vista was pushing 14GB on a fresh install alone.

Success.

Success.

I’ve yet to really give it a proper test run, but so far it seems like a nice improvement on Vista, which despite improving hugely since launch is still quite capable of making me want to tear all my body hair out. The interface looks smart, and the graphical effects are much more dignified. As much as I’m a Mac fan now, I really want Windows 7 to be a good OS. I doubt it’ll tempt me back to the fold, but without competition and choices life would be dull.

Plus, at the end of the day, I still need something to run Team Fortress 2 on.

Posted in Software | Tagged , , | 4 Comments

Breaking News

Due to the recession the Highways Agency are cutting back on spending on road signs. From now on there’ll only be one little silhouette man per town, so he’ll have to divide his time between the signs.

Breaking News

Posted in Images | Tagged , | Leave a comment

Interfacing PHP with the Arduino (with a splash OS X)

A while ago I bought an Arduino Diecimila, which is an open-source electronics prototyping platform. It’s a very easy to use programmable micro-controller with a bevy of digital and analogue inputs and outputs. It is programmed via USB using the cross-platform Arduino software. The language is C-like with plenty of documentation available online. The Arduino appears to the OS as a serial device which makes two-way communication very easy indeed.

Whilst I really haven’t got a clue what I might use it for, I thought it would be cool if I could create a simple web-based system to control hardware attached to the Arduino. My server-side language of choice is PHP, so I looked for a way to allow it to send and receive data from a serial port. I didn’t have to look very far before I found the PHP Serial class, which looked just the ticket. Unfortunately whilst it caters for Windows and Linux, it doesn’t work under OS X. Fortunately it was just a matter of adding a few more else if‘s to allow for the slight differences in the way stty works in OS X.

I thought it would all be plain sailing from here, but this was not the case. The Diecimila resets whenever a serial connection is opened, so it can be ready to receive a new program. However this can be a problem; suppose I open a serial connection to the Arduino and tell it to light up an LED at 50% brightness. Then later I decide I want it at 100% brightness, so I open up a serial connection again, at which point the Arduino resets and the LED goes out. Not very desirable, and positively useless if the Arduino has been collecting data that you wanted to retrieve.

After some Googling it became apparent that I wasn’t the only one with this issue. Most suggestions were to either remove a tiny SMT capacitor from the board to permanently disable the auto-reset function, or to suppress the behaviour by disabling DTR (in Windows) or HUPCL (in *nix). That sounded better, so I tried it out. The commands required were:

nhup sleep 999 < /dev/cu.usbserial-A7004WqM &
stty -f /dev/cu.usbserial-A7004WqM -hupcl

Now, I’m no command-line/serial expert, so I only have the slightest understanding about what goes on when those two commands are run. What I do know is that it solves the problem so long as the sleep process is still running. It’s hardly an ideal solution (in my opinion). I suspect this might be a problem unique to OS X, as it seemed to work much better when I tried it in Debian.

Then! I found a forum post lurking at the bottom of a thread on the Arduino Forum. It suggests putting a 110 ohm resistor between the 5V and Reset pins, or a 47 ohm between the 3.3V and Reset pins. I had a 47 ohm resistor handy so I whacking it in there and lo! No more automatic resets. Brilliant. The post does go on to say that using the reset button with the 47 ohm resistor is place may be risky, so I’ll have to try and remember to remove it if I ever need to press it.

So now the PHP to Arduino link is useable. Here’s an example of some PHP code to send a character to the Arduino:

1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
    //Include the PHP Serial class
    include "php_serial.class.php";
    //Define the serial port to use (in Windows something like 'COM1')
    define('SERIALPORT','/dev/cu.usbserial-A7004WqM');
    //The character to send
    $c = 0;
 
    $serial = new phpSerial; 
    $serial->deviceSet(SERIALPORT);
    $serial->deviceOpen();	
    $serial->sendMessage(chr($c));
?>

… and an example of the Arduino code to interpret this and do something:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int incomingByte = 0;
 
void setup()
{
    Serial.begin(9600); //Start serial connection, 9600 baud
}
 
void loop()
{
    if(Serial.available() > 0){
        incomingByte = Serial.read();
        if(incomingByte = 0){
            analogWrite(9, 128); //Pin 9 to 50% if 0 received
        }
        else if(incomingByte = 1){
            analogWrite(9, 255); //Pin 9 to 100% if 1 received
        }
    }
}

This works brilliantly. With only slightly more complex code (thanks to a post on Principia Labs for a great explanation on effective serial commands), and a bit of AJAXy goodness, I have something like this:

Now all I have to do if think of a use for it…

Posted in Hardware | Tagged , , | 25 Comments

How the Daily Mail is really made…

Entry for B3ta’s image challenge. Click the image for the bigger PNG version.

I assure you that any similarity between this and the Slurm Queen is entirely coincidental.

Posted in Images | Tagged , , | Leave a comment

Welcome

Welcome to MyDarkMaterials.co.uk. This will mainly be a dump for stuff I have made.

Posted in Site News | Leave a comment