Archive for the 'apple' Category

Quick test with Xbee alternative: Ciseco XRF module

This is a quick post to explain how to get a pair of Arduinos talking to each other wirelessly, using XRF wireless modules from Ciseco. They actually work straight out of the box, but if like me you like to have some instructions to get you going then hopefully you’ll find this post useful.

I’ve recently started learning/playing/experimenting with Arduino - an open-source microcontroller. Reading around, I saw lots of people mentioning Xbee wireless modules, which enable your Arduinos to talk wirelessly to each other (or to your computer) which sounded fun. However, the Xbee modules I’ve seen generally tend to operate at 2.4 GHz (along with every other wireless device in my home and the houses around me like cordless telephones and wi-fi), so I wasn’t really keen to add the the radio pollution in that band. They’re also moderately expensive (starting price circa £20 each with a range of 100m or so, and don’t forget you need a pair). But then I came across the XRF wireless module from Ciseco.

For about £10, you get a wireless module that’s pin-for-pin compatible with Xbee (Series 1), works over a range of different frequencies (868.3MHz by default, but also 315MHz, 433.5MHz, 868MHz, 903MHz and 915MHz), and has a standard range of approximately 300m (although ranges of over 3 Km are claimed). At this point I should make it clear that I’m a complete beginner at this stuff, but I was curious so emailed Ciseco with a few of my newbie questions. Their responses were quick and made everything sound simple, so, loving a bargain and challenge, I decided to order a pair and have a tinker.

Shopping List

The shopping list was pretty minimal. I already had an Arduino Uno and an Arduino Ethernet, so as well as ordering 2 x XRF modules, I also ordered 2 x Ciseco Xbee shields. These sit between the Arduino and the XRF, and were about £17 each. So although these are about the same price as alternatives, they have some nice features like an onboard 3v3 regulator, automatic disabling of the TX/RX lines when uploading a new sketch to the arduino (means you don’t have to unplug the XRF/Xbee when replacing the sketch), and space to solder on additional components (sensors, things that go blink etc….).

A simple test

I was assured that using the XRF was easy, and that when using the Xbee shield it was simply a matter of:

  1. Plugging the three PCBs together (Xbee shield into the Arduino, and the XRF into the Xbee shield),
  2. Enabling the XRF module by holding pin 8 high, and
  3. Reading/Writing between the two Arduinos using standard Serial.read()/Serial.write() commands.

I admit that it sounded much easier than I was expecting, so, with a little disbelief, I dropped the following code onto my arduinos. First up, a “Beacon”. This just sends the letter “H” (for Hello) every few moments, and listens for the letter “K” (for OK) in response. (Actually it doesn’t care if the letter K is in response to anything - it just listens for the K regardless.) If a letter K is received then the status LED on pin 13 of the Arduino Uno it lit for a moment, and because this LED is difficult to see (with two PCBs stacked on top of the Uno) I added in a piezo buzzer too — wiring it straight on to pin 7.

You can grab the PDE file for this sketch here: XRFTestBeacon.pde. This should compile to 3566 bytes. Note that it doesn’t do much on its own; you need to grab the second file below.

/* XRF Arduino Test Sketch - Beacon
 *
 * Full details of this example: http://bit.ly/sPPN8a
 *
 * Simple sketch to check the XRF radio modules are working.
 * Broadcasts the letter "H" (Hello) every 5 seconds.
 *
 * I'm using 2 x XRF modules and 2 x Xbee sheilds from Ciseco, and an
 * Arduino Uno and Arduino Ethernet. The default XRF baud rate in 9600.
 *
 * This sketch (1 of 2) is running on the Arduino Uno, which has a
 * built in LED on pin 13. A piezo beeper was connected to pin 7 for
 * audiable acknowledgment of activity.
 *
 *  Created 4 Dec 2011
 *  by Mark Sweeting - www.sweeting.org/mark
 */

int LEDPin = 13; // built in to the Uno PCB
int XbeeEnable = 8; // powers up the XRF when using the Xbee shield
int BuzzerPin = 7;
int BuzzerTone = 6000;
unsigned long lastBeaconTime = 0;
unsigned long nowTime = 0;
unsigned long LEDTime = 0;
int beaconInterval = 2000;
int LEDPeriod = 300;

void setup()
{
  pinMode(LEDPin, OUTPUT);
  pinMode(XbeeEnable, OUTPUT);

  // Turn XRF on
  digitalWrite(XbeeEnable, HIGH);

  Serial.begin(9600);
}

void loop()
{
  // Get the current time since power-up
  nowTime = millis();

  // Send the letter 'H' ("Hello") on the serial line every few
  // seconds
  if((nowTime - lastBeaconTime) > beaconInterval)
  {
    Serial.print("H");
    lastBeaconTime = nowTime;
  }

  // If we receive the letter 'K' (for "OK"), then turn the LED on
  // for a moment and beep the buzzer
  if(Serial.available() > 0)
  {
    if(Serial.read() == 'K')
    {
      LEDTime = nowTime;
    }
  }

  if(LEDTime)
  {
    digitalWrite(LEDPin, HIGH);
    tone(BuzzerPin, BuzzerTone);

    // Turn LED off after a short period
    if((nowTime - LEDTime) > LEDPeriod)
    {
      LEDTime = 0;
      digitalWrite(LEDPin, LOW);
      noTone(BuzzerPin);
    }
  }
}

The beacon “relay” code is even simpler: it just listens out for the letter “H” and sends a letter “O” in response. It was running on an Arduino Ethernet, and this doesn’t have a status LED on pin 13 so there was nothing for me to blink without wiring things in. For the purpose of the demo there was no need.

You can grab the PDE file for this second sketch here: XRFTestBeaconRelay.pde. This should compile to 2234 bytes.

/* XRF Arduino Test Sketch - Beacon Client Relay
 *
 * Full details of this example: http://bit.ly/sPPN8a
 *
 * Simple sketch to test a pair of XRF modules are working. Listens
 * for the letter "H" (Hello) on the serial line, and sends the letter
 * "K" (OK) in response.
 *
 * I'm using 2 x XRF modules and 2 x Xbee sheilds from Ciseco, and an
 * Arduino Uno and Arduino Ethernet. The default XRF baud rate in 9600.
 *
 * This sketch (2 of 2) is running on the Arduino Ethernet which
 * doesn't have a built in LED, so there's nothing for us to blink by
 * way of acknowledgement.
 *
 *  Created 4 Dec 2011
 *  by Mark Sweeting - www.sweeting.org/mark
 */

int XbeeEnable = 8;

void setup()
{
  pinMode(XbeeEnable, OUTPUT); 

  // Turn XRF on
  digitalWrite(XbeeEnable, HIGH);
  Serial.begin(9600);
}

void loop()
{
  // listen out for the letter "H", and send a "K" if we get one.
  if(Serial.available() > 0)
  {
    if(Serial.read() == 'H')
    {
      Serial.print('K');
    }
  }
}

So once I’d plugged everything together and the sketches were loaded onto the Arduinos, I powered them up, waited, and bingo! The beeper started to beep, meaning the letter “H” was being received by the second module, which was sending the letter “K” back in response. So it really was as simple as the folk at Ciseco said it would be!

I’m sure I’ll be posting more about the XRF modules in time as they’re pretty canny devices. In the meantime, it’s worth checking out the Openmicros forum (run by Ciseco, and includes a good support forum) as they’re very quick at responding to queries.

Change the default address bar search in Firefox on Mac OS X

Long title for a short post! Even since I moved to Mac (a month or so ago now…) I’ve been a little annoyed that the default Google site for searches from the address bar was google.com. I decided to poke around and I think I’ve come up with a fix. Not sure if there is a better way to do this, but it seems to be working for me so far. I’m running Firefox 2.0.0.15 (yes, I know I should probably be using Firefox 3…) on Mac OS X 10.5.4. Here’s what I did:

  1. In the Firefox address bar, type about:config
  2. Then, in the Filter box at the top type keyword
  3. This should show up a Preference Name called keyword.url. Right-click on this and select Modify
  4. Update the value to reflect the search engine of your choice. In my case I’ve changed it to http://www.google.co.uk/search?ie=UTF-8&oe=UTF-8&sourceid=navclient&gfns=1&q= to point me at Google UK.

That should be it. Now when I type some words into my address bar, firefox will search for those terms in google.co.uk if I’ve not entered a valid URL. I hope this helps someone!

You may also want to look at the keyword search feature built into Firefox bookmarks, also available through the new del.icio.us bookmarks too. This allows you to type things like google iphone 3g to search Google for the term ‘iphone 3g’, or flickr unboxing to search Flickr for photos of people unpacking their new gadgets.

Mac OS X Tip: Setting PATH environment variables

I’m still getting to grips with this OS X malarkey, and my latest challenge was how to set the PATH environment variables.

I started out wanting to add some aliases for the mysql and mysqladmin commands as I’ve just decided to have a bit of a play with django. On linux I used to edit my .bashrc file to do this, but the version of bash on Mac OS X (10.5.2) doesn’t seem to support this. Hunting around I realised that I should just add the path to these commands to my PATH environment variable, but again: not quite so simple.

I want these commands to be available to everyone, so it turns out you have to edit a file called paths in /etc:

sudo vi /etc/paths

And that was it. Easy when you know how! Oh, and remember to run vi as root using the sudo command….

Switching to Mac: the challenge continues…

I recently got myself an Apple Mac so that I could find out what all the fuss is about. In many respects it doesn’t matter what sort of a computer you use these days, so long as you have a web browser… However I’m still finding it a bit of a challenge to switch over. The most recent challenge has been finding the hash (#) key on the ‘English (UK)’ keyboard.

As you can see I’ve now got it sussed, but it took a bit of messing around. The keyboard is on a Mac Book Pro, and to get a hash you need to press Alt-3 (or ‘Option’ as I think they call it, and the key with the pound (£) symbol on it). Those funny Americans…

I’ve been having all sorts of problems getting my networked attached storage working too. I have two of these devices: and old LaCie Ethernet disk mini and an Infrant ReadyNAS NV+. The ReadyNAS works fine if I set it up as a Windows share (ironic, I know…), but it just wont work at all if I set it up as an AFP share and enable ‘bonjour’. However, the LaCie device (and I always had the impression that Lacie were more of a mac shop than a windows shop) just won’t work at all. I can try it as a windows share or an AFP share with bonjour, and neither setting will work. It’s very frustrating!

The next hurdle has been screen calibration. I’ve been trying to get the laptop screen and my 19″ LaCie 319 set up the same so that I can run both displays at the same time and have images on either look the same. I set both to the same colour temperature, gave them the same luminance and gamma setting and ran some calibration software that came with my monitor and the Blue Eye Pro colorimeter. No matter what I do they just won’t look the same. The curious thing is if I measure the response of either screen (using the colorimeter) they both report to be the same! Very perplexing!

At the same time I’m playing with Adobe Lightroom, and although I think it’s pretty good software, neither the laptop screen or my LaCie is big enough to make it ‘nice’ to use. I really need to close the laptop lid and use an external display, but have you seen the price of a LaCie 324 Monitor with hood?! They don’t come cheap!

So what other issues am I having?

Well there is mouse that goes exactly where I want it to on my Windows computer, but seems to have a mind of it’s own on the Mac.

And then there is the terminal/shell that doesn’t automatically copy selected text to the clipboard and paste on a right-click.

Talking of shells, the backspace key seems to want to do a forward delete instead in some circumstances. I’ve not worked out the pattern yet, but it’s a very strange thing indeed. And trying all the combinations of Ctrl-Backspace, Alt-Backspace and Cmd-Backspace don’t seem to help this time around. Again, a small annoyance on it’s own, but taken along with all the others it’s getting to be a major irritation!

Finally we mustn’t forget the lack of support for automatic window focus (where the cursor focus follows the mouse). This is a real pain indeed! Most linux window managers that I’ve used over the last 10 years (in fact all that I’ve ever used) have done this without a problem, and you can even do this on Windows, so why on earth doesn’t OS X support it?!

So despite being praised for it’s usability, I’m still having some issues using my Mac.

On the positive side, I discovered is that Safari (which I previously couldn’t stand) supports embedded colour profiles in images. This means that when I look at my photos on flickr, they look exactly how I meant them to look (assuming the viewing monitor has been calibrated). I don’t know if Safari does this on Windows, but it makes my flickr experience much nicer. So much so in fact that I now won’t use firefox to surf flickr! So that’s a good thing.

But I’m nearly there. I’m trying to reduce my clutter so if I can decommission my old NAS and sort out the display problems then I should be able to get rid of some old and bulky hardware and free up some well needed space!

So enough rambling. In conclusion maybe I need to think about installing Ubuntu linux on this laptop instead…. at least things would be more predictable… wouldn’t they? I’m dreading the thought of actually becoming a fan of Windows (XP, not Vista), so perhaps if I avoid installing Linux I’ll never know if it’s better or worse and I can live in the vague hope that it simply must be better, and one day if I ever need it I can switch over… That day must never come.

Right, I only started this post so I had somewhere to check back to when I needed reminding how to get the hash symbol…. so that’ll be Alt-3 then. Remember?