Oomlout.co.uk – order received…

On Sunday night, I placed an order on the oomlout.co.uk site for a few bits I needed for a small project I’ve been working on.

I received the parcel on Tuesday morning and was very pleased with the fast delivery. When I opened it, I was really impressed with everything. First of all, all the components were in small resealable anti-static bags with a sticker with a description on them, which meant I could just put them in a box without worrying that I would forget where is what.

The second thing that really impressed me was that they actually included the description sheets for the multi-color LEDs and the force Sensitive Resistors I ordered. These sheets are also available on their website, but it was actually extremely handy to have them by my side, when I had the soldering iron on my other hand!

Last, but definitely not least, was the quality of the components!

I can fully recommend Oomlout.co.uk and I will be ordering again from them 🙂 .

Parsing files with Processing…

In the following basic example, I’m using Processing to parse a 2GB textfile.

The textfile I’m using (content.rdf.u8) is from the DMOZ.org project. You can download the compressed file here.

As mentioned earlier, the size of the textfile, content.rdf.u8, is approx 2GB. For a sample of the contents and structure of the file, follow this link. For a file of this size, it’s important to use BufferedReader. Read here for more on BufferedReader.

The following piece of code, reads the textfile and converts it to another textfile of the format: URL|Title|Description|Category:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.util.regex.*;
 
String fileName = dataPath("C:\\Users\\Arkadian\\Downloads\\content.rdf.u8") ;
String outputFile = dataPath("D:\\dmoz\\data.txt") ;
 
String sep = "|";
String outputLine = "";
String L = "";
String t = "";
 
PrintWriter output;
output = createWriter(outputFile);
 
try
{
  BufferedReader file = new BufferedReader (new FileReader (fileName)) ;
 
  while (file.ready()){ 
 
    L = file.readLine(); 
    //println(L); //for debuging only...
 
    String[] m1 = match(L, "<ExternalPage about=");
    String[] m2 = match(L, "<d:Title>");
    String[] m3 = match(L, "<d:Description>");
    String[] m4 = match(L, "<topic>");
    String[] m5 = match(L, "</ExternalPage>");
 
    // Start of an external page & URL
    if(m1 != null){
      t = L.replaceAll("<ExternalPage about=\"","");
      t = t.replaceAll("\">","");
      outputLine = t;
    }
 
    // Title
    if(m2 != null){
      t = L.replaceAll("  <d:Title>","");
      t = t.replaceAll("</d:Title>","");
      outputLine = outputLine + sep + t;
    }   
 
    // Description
    if(m3 != null){
      t = L.replaceAll("  <d:Description>","");
      t = t.replaceAll("</d:Description>","");
      outputLine = outputLine + sep + t;
    }   
 
    // Topic
    if(m4 != null){
      t = L.replaceAll("  <topic>","");
      t = t.replaceAll("</topic>","");
      outputLine = outputLine + sep + t;
    }    
 
    // End of External page
    if(m5 != null){
      println(outputLine);
      output.println(outputLine);
      output.flush();
    }    
  }
}
 
catch (Exception e){
  println ("Error" + e) ;
}
 
output.close();
exit();

Pretty simple, yet effective…

Arduino Programming Notebook on Lulu.com

Brian Evans has published a book on Arduino on Lulu.com, which is available either as a free pdf download or a real paperback for £3.72 + postage. Arduino Programming Notebook – Direct link

This is book (or “notebook” as Brian calls it, as it is only 36 pages long) is a very short introduction to Adruino. It covers all the basics and it’s really all you need in order to get started if you know another programming language.

Most of the information on this book is also available online on the arduino.cc website, but it’s always worth having a printout handy, in case you want to look something up pretty quickly.

About Amazon Web Services…

AWS (Amazon Web Services) has been around for a while, but I never thought I was the target audience for it, so I never really looked into that.

Last weekend, I had the following problem to solve: I’m working on a model, that realistically needs approx 1,000 “normal” PCs in order to run within an hour. This is a simulation running on Processing I’ve been working on.

Realistically, I won’t be able to persuade my boss to buy me a cluster of servers with the processing power of 1,000 machines for this.

Here is where AWS saves me. AWS allows you to rent any number of machines for any number of hours. Well, sort of… You don’t actually rent real machines, you get virtual machines, runnning on clusters I suppose. The beauty of this service is that you can select either a pre-defined image or build and use your own. There are many pre-defined images to select from, including Fedora, Ubuntu, Suse, Debian and of course all the Windows Servers.

You have full control of the firewall and you can attach IPs and storage (at a price) if you like on your loaded image.

I created an account and started playing around and I was actually pretty impressed with the service.

You are getting charged by the hour; if, for example, you are using a smallish linux server for 1 hour, you will pay $0.10 which is not actually that bad. In my case, if I need to use 1,000 machines for 1 hour, I’ll have to pay $100, which is pretty acceptable. There are other charges for storage and traffic, but again these are pretty low too.

Even if you don’t need 1,000 machines, it’s always great to be able to have a virtual linux machine ready to be used as a sandbox for just 10 cents an hour.

I think Google offers a similar service, but, Google’s service is more about running a program on their servers rather than a program on a virtual machine that you have full (root) control, like AWS

Link: Amazon Web Services

Processing, MySQL and RAM tables…

I’m currently working on a simulation model in Processing, which creates in every cycle, 350,000 lines of temporary data in chunks of 1,000 lines.

I decided to save the temporary data in a MySQL table, as this allows me to easily add an extra query at the end that summarises everything and saves the final results on a different table.

As the 350,000 lines need only to be stored temporarily, I’m using the Memory storage engine, instead of the default (MyISAM). The advantage of the Memory storage engine for temporary storage is that it saves the data on the RAM rather than the hard drive, is (or should be) faster and when you reboot the machine, the temp data is gone. The structure of the table is stored on the hard drive, so you can use the table again and again.

Here is a test sketch I wrote to get an estimate of how long it takes to create 350,000 records.

If you want to try this, you need to download and install the SQLibrary (http://bezier.de/processing/libs/sql/). You also need to install a mySQL database locally. If you don’t have one installed already, I suggest you go to apachefriends.org and download the latest version of XAMPP.

First, to create a simple table in RAM, run the following mysql snippet:

1
2
3
4
5
6
CREATE TABLE IF NOT EXISTS `arkadian_test` (
  `myID` int(11) NOT NULL AUTO_INCREMENT,
  `myRecord` int(15) NOT NULL,
  `myTimestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`myID`)
) ENGINE=MEMORY  DEFAULT CHARSET=latin1;

This is a simple table, that is stored in ram (ENGINE=MEMORY).

The following sketch creates 350,000 records in chunks of 1,000 records.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 
/* //////////////////////////////////////////////////////////////////////
Date: 1 Aug 2009
From: Arkadian.eu
Desc: A quick sketch that creates 350K records in MySQL
*///////////////////////////////////////////////////////////////////////
 
import de.bezier.data.sql.*;
MySQL mx;
 
public int maxRecords = 350000;
public int currentRecord = 0;
 
// adjust these for your configuration
public String user     = "root";
public String pass     = ""; //blank
public String database = "test";
public String dbhost = "localhost";
/////////////////////////////////////////////////////////////////////////
void setup() {
  size(100, 100);
  mx = new MySQL( this, dbhost, database, user, pass );
  while(mx.connect()==false){delay(1000);}
  mx.execute("TRUNCATE TABLE  `arkadian_test`"); 
}
/////////////////////////////////////////////////////////////////////////
void draw() {
 if(currentRecord<maxRecords){
    // let's check to see if the connection is still up
    while(mx.connect()==false){
      mx = new MySQL( this, "localhost", database, user, pass );
    }
 
    if ( mx.connect()==true ){  
 
      for(int i=0; i<1000; i++){
        currentRecord++;
        mx.execute("INSERT INTO arkadian_test(myRecord) VALUES ('" + currentRecord+ "')"); 
      }
 
    }
 
  }
 
  else{
    mx.close();
    exit();
  }
}
/////////////////////////////////////////////////////////////////////////

The above sketch takes about 45-50 seconds to run on my 2GHz Intel Core2 Duo laptop with 3GB RAM.

To see how long it takes on your machine, just look at the timestamps of the first and last record on your database.

For more information on MySQL tables on RAM, visit this site.

Sparkfun Alarm Clock

Sparkun are selling the following simple clock on their site: Link

ClockIT from Sparkfun
ClockIT from Sparkfun

This is a minimalistic clock that includes all the essential functions and is very similar to a product offered at Maplins in the UK that I have used before: Maplin link | My project which includes this module

There are two differences between the two clocks from Sparkfun and the Maplin. The first one is that the Sparkfun clock runs at 5V; the Maplin clock needs 9-18V (which then regulates down to 5 and generates quite a bit of useless heat in the process…). This for me, is a major design flaw! When I used it for this project, I had to power it from a USB port, which basically meant that I removed the voltage regulator and changed the wiring a bit to accommodate for the lower voltage.

The second difference is that the Sparkfun clock is based around the ATmega168 chip (i.e. the old Arduino chip). It would be nice if the code (provided by Sparkfun on their website) was in the Processing/Arduino language.

These are great modules to use for custom applications. Of course you can go down the I2C real clock module path and use something like this. The problem is that you add a whole new layer of complexity to your module. You need a way to display the time, controls to adjust the time, etc, etc… If you just need a basic alarm clock to flip a switch at a specific pre-defined time, just get one of these modules, replace the speaker with a transistor and you are sorted…

Anyway, enough about alarms 🙂