RDM630 125KHz RFID reading with the Arduino Mega 2560 R3

This howto is for the RDM630 125Khz RFID module – UART board. Seeedstudio and Spec Sheet.

There are a few chunks of code on the internet that will get the RDM630 up and running on an Uno, but those don’t seem to work on the Mega. There are also a few examples of code that sort-of works, but not reliably, and does not check the checksum etc. I stated with these and then kept on hacking until I got it to work 100%.

RDM630ArduinoMega

So, firstly, a few things that you should know before we start:

  • Many of the code examples work fine with an Uno (using Software Serial) but I’m starting to learn that the Mega doesn’t like Software Serial. I’ve found a few instances of people saying (anecdotally) that Software Serial is “not supported” on the Mega, and even though it works, it’s buggy, and there are patches blah blah. Luckily we have 4 hardware serial ports, so lets use those.
  • You only need to use +5V, GND and one pin (TX) to connect the board to your Mega.
  • You will notice the delay(20); in my code. That gives the board time to bring up the serial connection before trying to read data for it. Without that you’ll get garbage 90% of the time.
  • There are various methods for reading. I’m using a hybrid of various approaches from the internets that uses Serial1.available() as a signal that a tag has been swiped and explicitly reads 14 bytes.
  • I am also explicitly closing and restarting the the Serial1 connection after reading a tag. I do this because the code was working until I left a tag in range for longer than about 5 seconds, at which point Serial1 would get confused and the counter would overrun. This approach does slow things down, but since you can still scan about 4 tags a second (way more than you’ll need to in real life) you’ll be fine.
  • This approach uses pointers, buffers and some confusing snprintf and sscanf functions to extract and convert the 14 bytes from the tag into the various bits and pieces (RFID Tags have checksums, and the unique number itself is stored in HEX). That stuff is hard to grok, but luckily you can chose to either make an effort to understand it or just use the code as-is.

Right. Wiring.

Look at the spec sheet. On pin-set one, pins 4 and 5 go to GND and +5V respectively, with  pin 1 going to Pin 19 on your Arduino Mega (RX for Serial1). That’s all.

Now the code:

uint8_t buffer[14];
uint8_t* buffer_at;
uint8_t* buffer_end = buffer + sizeof(buffer);

String checksum;
boolean tagfound = false;

void setup()
{
    Serial.begin(9600);
    Serial.println("Serial Ready");

    Serial1.begin(9600);
    Serial.println("RFID Ready");
}

void loop()
{
    if (Serial1.available()){
        delay(20);
        buffer_at = buffer;

        while ( buffer_at < buffer_end )
        {
            *buffer_at++ = Serial1.read();
        }
        tagfound = true;
        Serial1.end();
        Serial1.begin(9600);
    }

    if (tagfound){
        buffer_at = buffer;
        uint32_t result = 0;

        // Skip the preamble
        ++buffer_at;
        // Accumulate the checksum, starting with the first value
        uint8_t checksum = rfid_get_next();
        // We are looking for 4 more values
        int i = 4;
        while(i--)
        {
            // Grab the next value
            uint8_t value = rfid_get_next();
            // Add it into the result
            result <<= 8;
            result |= value;
            // Xor it into the checksum
            checksum ^= value;
        }
        // Pull out the checksum from the data
        uint8_t data_checksum = rfid_get_next();

        // Print the result
        Serial.print("Tag: ");
        Serial.print(result);
        if ( checksum == data_checksum )
            Serial.println(" OK");
        else
            Serial.println(" CHECKSUM FAILED");
        // We're done processing, so there is no current value

        tagfound = false;
    }

}

uint8_t rfid_get_next(void)
{
    // sscanf needs a 2-byte space to put the result but we
    // only need one byte.
    uint16_t hexresult;
    // Working space to assemble each byte
    static char byte_chars[3];
    // Pull out one byte from this position in the stream
    snprintf(byte_chars,3,"%c%c",buffer_at[0],buffer_at[1]);
    sscanf(byte_chars,"%x",&hexresult);
    buffer_at += 2;
    return static_cast<uint8_t>(hexresult);
}

Now connect it up, open your Serial Monitor and swipe a tag. You should see the tags being read, with their decimal value (often the number that’s printed on them) printed out.

My three tags look like so:

Serial Ready
RFID Ready
Reading: 695592 OK
Reading: 721129 OK
Reading: 1430936 OK

Credits:
I stole a large chunk of code from ManicBug’s blog post, and got a lot of help from the great people in #arduino on Freenode.  Thanks!

Advertisement

Seeed Studio GPRS Shield 1.4 and Arduino Mega 2560

Recently I battled to get the Seeed Studio GPRS Shield 1.4 and Arduino Mega 2560 to talk to each other. I eventually discovered that they are not actually compatible when stacked (without some ugly pin jumping, and even then, not really compatible because the Software Serial can’t seem to really handle 19200 baud rates).

So here’s how to treat it as a breakout board. (my notes in blue):Image

This only requires 5 connections. The blue labels represent the Arduino pins to connect to.

  1. 5v and GND – These should be pretty obvious.
  2. Pin 9 – This pin is used to turn the SIM900 on and off.
  3. Pin 18 and 19 – These are the HW serial pins

Finally note the position of the jumpers (HW Serial) and the position of the Power Switch (Internal).

Which, when connected up should look something like this:Image

Then finally you can load up the following sketch to get serial access to the GPRS modem via the Arduino’s serial monitor.

#include <SoftwareSerial.h> 
#define terminator 10 // DEC value for a LF(line feed) to skip while loop

/*
SETUP
 
 See https://arbitraryuser.com/2013/04/07/seeed-studio-gprs-shield-and-arduino-mega-2560/
 
 This code is partially "borrowed" from idS2001 at http://www.seeedstudio.com/forum/viewtopic.php?p=12939#p12939
 */

String IncDataSerial = "";

void setup()
{
  delay(1000);
  Serial.begin(19200);
  Serial1.begin(19200);

  // Automatically power up the SIM900.
  pinMode(9, OUTPUT);
  digitalWrite(9,LOW);
  delay(1000);
  digitalWrite(9,HIGH);
  delay(2500);
  digitalWrite(9,LOW);
  delay(3500);
  // End of SIM900 power up.
}

void loop()
{
  if (Serial1.available()>0)  // if date is comming from softwareserial port ==> data is comming from gprs shield
  {
    boolean getLF = false;
    while(Serial1.available()>0 && !getLF)  // reading data into string if activity is on port and getLF is false ==> no LF have been send
    {
      char buffer=Serial1.read();  // writing data into char
      IncDataSerial += buffer;
      if (buffer == terminator) {
        getLF = true;
      }
    }

    Serial.print(IncDataSerial);  // send string ( char array ) to hardware serial
    Serial.print("\r");   // send a CR because it is missing
    IncDataSerial = "";
  }
  if (Serial.available()>0) // if data is available on hardwareserial port ==> data is comming from PC or notebook
    Serial1.write(Serial.read());  // write it to the GPRS shield
}

In Serial Monitor (or similar app) you will then see it start to talk to you after the initial ~5 second startup delay.

RDY

+CFUN: 1

+CPIN: READY

Call Ready

AT
OK

AT+CSQ
+CSQ:18,0
OK

20 Pieces of Startup Advice I Should Have Posted A Long Time Ago

Disclaimer: I am not a successful tech entrepreneur, so you probably shouldn’t read this.

  1. Build what people need and build it in the quickest and easiest (read hackiest) way possible that is barely acceptable to them. There are a lot of very bad implementations out there making millions right now.
  2. Do not build what you want (or what you think people need/want). As a tech entrepreneur you are an anomaly. Most people don’t care about the things you care about. eg. “I want a way to sync my scrobbles to my own server in case LastFM gets taken down by the FBI.” – Only 5 people care about this.
  3. Build products around use cases, NOT use cases around products.
    If you can’t explain what your product does in 20 seconds then you don’t have a product, you have a big idea. Unless you have unlimited resources and funding you’re going to need to tame your idea. Find a specific implementation of your big idea in action that resonates with the masses and run with that. If building that specific instance of your idea doesn’t sound sexy enough, think about how sexy it is going to be when you go back to your old boss and ask for a job. Once you’re making a profit off your not-so-sexy idea you can start self-funding your big idea.
  4. Big ideas don’t get funding. Google was not a big idea, it was a vastly better search engine in a market flooded with search engines. It was a product. Angels and VCs need to be able to understand your idea and then be able to communicate your idea to other people who will also understand it and immediately see how it will make money.
  5. Don’t let VCs lead you down the garden path and never commit. They’re doing you a disservice. If they truly like your idea and believe in you they can do their due diligence in 2 weeks and have (some) money in your bank account in a month. Too often it seems that VCs who don’t really “get” an idea are too scared to tell the founders to go away, just in case their idea starts to make sense. (No one wants to be the record exec who told the Beatles to go away). But this can give youa false  impression of how good your idea is, because if a VC seems interested, then surely your idea is a good one, right?
  6. Don’t make friends with VCs. Friends don’t want to tell friends that they “don’t really get it“, or more specifically that they “get it, but don’t see how you will be able to sell enough of it“. This kind of feedback can too easily come off as a personal insult for anyone to ever say it… so they’ll lead you on in the hope that one day you’ll say something to convince them because they really want you to do well.
  7. Don’t get too personal or precious about your idea. You are a smart, attractive person with great hair and a wonderful personality, you don’t need your product to validate your worth. Getting too personal about your product leaves you unable to change anything because it’s like gazing into the eyes of your beautiful new born baby and wishing they had been born with with nicer ears. You need to be ready to dump that baby in the dumpster at a moments notice.
  8. It’s all about cash, sales and runways. Building the product is the easy bit. Any nerd with a laptop can build a product. Selling it is HARD. You need to realise up front that your “tech startup” is 90% on-the-street-corner-sales. If you think you’re immune to this you’re a fool. If you aren’t earning 50% of what you need to break even after 50% of your runway you are in trouble.
  9. If your runway is 100 meters long, you need to be selling your product at 25m. The next 75m is refine, sell, refine, sell, repeat.
  10. Make sure know how long your runway is from day 1. Count down in days, have it up on the wall in big print.
  11. If you can’t build a product that people would pay for in 25m, make it simpler. If you don’t think you can sell this new simplified product then charge less for it or try and find some more runway… But figure this all out before you start.
  12. If you think you have a longer runway because you will obviously get more funding, don’t quit your day job. Negotiate all your funding before you quit your job. You might need to develop an MVP to get this funding. Do that at night or on weekends.
  13. Selling isn’t sexy but don’t avoid it. Rather get your hands dirty from day one so that you get used to the smell. (You’ll also get better at not stinking up the room every time you try)
  14. You need to realise that there is a difference between what people are impressed by and what they will pay for. If you’re removing some significant pain or frustration from their life, they might not be impressed but they will pay for it. People pay for lots of very unsexy things all the time.
  15. Design and field-test products until something resonates. Mock something up in photoshop and then go and see if you can sell it. You need to get to the point where someone is willing to give you cash out of their wallet in order to go home and use your thing.
  16. Sell to people you don’t know and who don’t know you. If you’re going to be successful then 99.9999% of your market is going to be people who have never met you, so why would test your sales on people who know you? Firstly they’re biased (they want to help you and may even give you their hard earned money out of guilt/pity/just-to-be-nice) and secondly, you have insider knowledge– you know who to sell to and which of your friends to not even bother with. That’s not reality.
  17. If there is more than one of you in the startup, don’t assume roles like “sales guy” and “coder”. Send the coder out to sell (especially when you’re still faking it)… He/She might just surprise you, and, at the very least they’ll learn more about how the product fits in the real world.
  18. Get a simple office (or even a room in the back of someone else’s office). Be there every day from 9 until 5 (or 10 till 6, or 11 till 7 etc) from day 1. Stick things on the walls, decorate your corner… get a crappy coffee machine. There is something about a humble office that will bring out the best in you. Working from someone’s home, even if you all work together just doesn’t have the same effect.
  19. Don’t believe everything you read on the internet.
  20. Read The Personal MBA before you start. Even if you have an MBA.

How to install CyanogenMod 7 on an HTC Desire

Quick post because I wrote most of this out for a friend and figure it was internets worthy.

Firstly, why would you want to do this?

  1. CyanogenMod gives you Apps2SD functionality which means you can store apps on your SD card regardless of whether they support being moved to SD. The Desire has some or other issue with storage space and you’re forever running out.
  2. Android 2.3.3 is slick and should almost double your battery life.
  3. CyanogenMod has hundreds of tiny tweaks that make your phone better and faster.

Warning: This should be obvious but following the steps below will essentially factory reset your phone and you will lose all apps etc. Since your contacts are probably backed up with Google and all the apps are available via Market, you shouldn’t need to stress.

From start to finish this entire process should take less than an hour.

  1. Plug your phone into a computer and copy everything off your SD card. This is only necessary if you care about your photos and movies etc.
  2. Use unrevoked to root your phone. Don’t stress if it automatically reboots once or twice. It does that… no idea why.
  3. Install Clockwork ROM manager from the Market. (the free one is fine)
  4. From inside the Rom Manager, “Flash ClockworkMod Recovery”. Takes a minute and will give you a success message when done.
  5. From inside the Rom Manager, “Partition SD Card”. This partitions and formats your SD card to give you Apps2SD functionality and also a bit of swap memory. I used a 512mb Ext partition and a 32mb swap partition. (Your phone will reboot and do the partitioning in the recovery mode)
  6. From inside the ROM manager, use “Download ROM” to get the latest Stable CyanogenMod. It’ll ask if you want the Google apps as well, tick the box to say yes.
  7. Wait for it to finish downloading (might take a while since it’s about 90mb of downloads)
  8. When done it it will ask if you want Backup Existing ROM and Wipe Data and Cache. If this is your first CyanogenMod you’ll want to tick the last two (Data and Cache). Additionally you probably also want to backup your existing rom. (it backs it up to the SD Card)
  9. Your phone will reboot into recovery and start doing stuff. It’ll do the backup first (take about 10 minutes) and then it will install the new ROM (takes about 8 minutes) and then it will reboot.
  10. The first reboot is slow. Don’t stress.
  11. Boom, you have CyanogenMod 7 with Android 2.3.3 (at time of writing)

Who invented the lightbulb?

Lets get one thing straight. Thomas Alva Edison did not invent the lightbulb.

This story requires context:

  • In 600AD the greek writer Thales of Miletus started writing about Electricity. Mostly this was all about rubbing Amber together and noticing static charge
  • In 1760 French physicist Charles-Augustin Coulomb starts actually making sense of electricity.
  • In 1779 Alessandro Volta builds the first true battery.
  • In the late 1700s and early 1800s every scientist, tinkerer and hacker is playing with electricity.
  • 30 years later, in 1809, Humphry Davy builds the first true electric lamp. This is 38 years before Edison is even born.
  • 50 years later, in 1860, Sir Joseph Wilson Swan builds an electric light bulb and starts tinkering with carbon-filament incandescent electric bulbs (The same stuff Edison eventually used).
  • Ten years later in 1877, the American Charles Francis Brush manufactured carbon arcs and was lighting public parks and office blocks.
  • In 1879, three years after Brush already had electric light in office blocks, Thomas Alva Edison discovers that a carbon filament in an oxygen-free bulb was able to stay glowing for up to 40 hours.
  • Two years later some dude named Lewis Howard Latimer makes a better filament.
  • 20 years later another guy called Willis R. Whitney invents a process to stop the globe getting dimmer as it got older
  • Seven years later, in 1910, a guy called William David Coolidge invents a tungsten filament that lasts a lot longer than the carbon ones.
Thomas Alva Edison - Douchebag Extraordinaire

So all that Edison ever “invented” was that a vacuum increased the lifespan of the filament.

So, the next obvious question is, why does everyone think that Edison invented the light bulb? The answer to that question is an interesting one because it has more to do with propaganda than it does to do with invention.

A lightbulb is useless without electricity, Edison knew that… and, like any clever businessman, Edison knew that real inventors are generally very bad at making money out of their inventions because they’re always too busy working on version 2.

Edison realised that the only way to make real money was to get electricity into people’s houses so that you could sell them lightbulbs, and electricity… This was brilliant because it’s the “Give away the razor, sell the razorblades” plan except both lightbulbs and electricity are consumables… so its more like “Give away the connection and sell the lightbulbs and the electricity”. Edison also wasn’t the first person to figure this out, he was just really really good at marketing… Or really really bad at marketing, depending on how you feel about Elephants.

Topsy the Elephant

Another person who realised that Electricity was going to make a lot of money was a rich businessman called Westinghouse. Westinghouse had become friends with an eccentric Yugoslav scientist called Nikola Tesla who had been experimenting with electricity his whole life. When Tesla wasn’t busy building Tesla Coils or trying to harness the power of lightning (or trying to harness energy from outer space, I shit you not) he worked with Westinghouse to build electricity generators and plan electricity distribution systems. Tesla knew more about electricity than pretty much anyone else alive at that point and early on had realised that Alternating Current (AC) was far better at distributing electricity than Direct Current (DC). So Westinghouse and Tesla started generating and distributing power to the rich and famous.

Edison didn’t like this. Not only were Tesla and Westinghouse competitors, but they were also proposing a different, better, system (AC) that Edison knew would eventually win the battle. Edison had managed to market himself as the father of electricity — a magician and folk hero — and he was getting incredibly rich.

Nikola Tesla - True Genius

So Edison did what any self respecting douche-bag marketer would do… he started publicly torturing animals… and filming it. Thomas Alva Edison, the “inventor of the lightbulb” went out into the streets and publicly electrocuted, to death, animals in a bid to show the public that Alternating Current was far too dangerous to be in their homes. And yes, in case you’re wondering, that reference to elephants earlier is because Edison even electrocuted, to death, an adult elephant.

Of course AC isn’t really any more dangerous than DC and Edison knew that… While there are some issues with AC’s 50-60 Hertz frequency being closer to that of your heart, both AC and DC are equally able to kill elephants and small children.

Sadly the public was gullible and Tesla was devastated… He went from being an eccentric socialite magician to being that guy who wants to murder small children and animals. Westinghouse had thicker skin and managed to keep his chin up, but Tesla became a recluse and started working in isolation on increasingly crazier ideas like harnessing power from the stratosphere. Tesla believed that it would be possible to get this power so cheaply that it would become free. Whether Tesla was onto something or whether his eccentric genius mind had finally snapped will never be known… In 1943 he died, alone, drowning in debt, in a hotel room.

Thomas Edison was no doubt a very clever man, but he was also ethically a disgusting person who thought nothing of destroying others to elevate his own fame.

Quick and Simple Server SMTP

I have a number of servers that I look after in various places on the intertubes. I like to have things like MDADM (Linux software RAID manager) be able to mail me when the something goes wrong like a disk dies etc.

Some of these machines are in places without reliable SMTP servers for me to send mail through and I’ve tried running my own postfix and delivering the mail directly, but invariably I run into situations where the servers that I’m trying to deliver mail to don’t like DSL IPs… and not getting a mail about a dead disk is kinda a big issue.

I also don’t trust a lot of ISP’s SMTP, and some of my servers move around, so one day it’ll be behind a DSL IP and the next behind a Verizon IP (where it can’t talk to smtp.dslprovider.net etc).

My solution is quite simple, use google. (This guide is for Ubuntu but I’m sure you’ll figure it out with other distros)

  1. Create a gmail account for monitoring. I do this because I don’t want my gmail password floating around in plaintext on various machines.
  2. Install the ca-certificates package

    $ sudo aptitude install ca-certificates
    $ sudo update-ca-certificates

  3. Install msmtp

    $ sudo apt-get install msmtp

  4. Configure msmtp

    $ sudo vim /etc/msmtprc

    Set it to something like

    account gmail
    host smtp.gmail.com
    from myemailaddress@gmail.com
    auth on
    tls on
    tls_trust_file /etc/ssl/certs/ca-certificates.crt
    user notifyemailaddress@gmail.com
    password mys3cr3tp455w0rd
    port 587

    account default : gmail

  5. Create a sendmail simlink

    $ sudo ln -s /usr/bin/msmtp /usr/sbin/sendmail

  6. Run a test

    $ echo “This is a an awesome test email” | msmtp youremail@domain.com

  7. If you want mdadm to mail you when something goes wrong

    $ sudo vim /etc/mdadm/mdadm.conf

    and put your email address on the line that reads something like

    MAILADDR youremail@domain.com

  8. And then run a mdadm test by running

    $ sudo mdadm –monitor –scan –test –oneshot

  9. If everything is working according to plan you should receive an email. You can now rest assured that any future MDADM issues will get to you.

Android for noobs and Heroes!

Some of my non-technical friends mentioned that all this Android stuff sounds great but they don’t understand any of it. So here is a very brief introduction. Android is a (mostly) Open Source operating system initially developed by Google and subsequently taken over by the Open Handset Alliance (OHA). This means that instead of every phone manufacturer working on building their own operating systems in isolation, the members of the OHA all work together to make Android better, fixing bugs and writing new apps.

Just a little teaser... I've subsequently installed the Hero ROM... and it is beautiful.
My Magic running Hero with TouchFLO.

This does mean that a relatively unknown manufacturer like Huawei could build a phone to Android specifications, install Android on it and reap the rewards of work that HTC employees had done. Phone manufacturers can chose to keep applications to themselves, like HTC has done with the user interface app called TouchFlo that they released on their new Hero Android phone. However the Open Source license states that if HTC makes any changes to the core Android system (ie, fixing a bug or adding a new feature) those changes have to be shared with the rest of the the Android community.

While all the OHA members, (Google, Intel, Nvidia, HTC, LG, Motorolla, Samsung, Asus, Garmin, Huawei, Sony Ericsson, Toshiba, Acer and more)  work together to build a better phone operating system, there are also a bunch of independent nerds in their nerd rooms building cool apps and fixing bugs for free. (Some developers can charge for their apps)

This is great for the consumer because not only do you get a great operating system and great apps but you also get well priced phones because there is always pressure from the little known phone manufacturers in China etc bringing out a really cheap Android phone. This also means that phone manufacturers can focus on building good quality phones with great cameras etc instead of wasting time with the OS.

While Apple’s iPhone does have a more mature ecosystem, the speed at which Android is currently moving makes me think that their lead will only last for a few more months. Case in point is the ridiculous speed at which new ROMs (A ROM is basically a big file containing the entire operating system) are being released by the Android community. I don’t think I’d be exaggerating if I said there was a new ROM available ever second day.

Which brings me to the part that my nerd friends want to hear about. Running the HERO Rom on my Magic. To clear this up for the non-nerds, what I’m doing here is running an Operating System theoretically built for HTC’s newest phone, the Hero, on my HTC Magic. The fact that this is even possible is entirely due to the fact that these phones run Android. While it may have been possible to do it with other phones in the past, the process would have been exceedingly complicated and probably impossible.

The Process: It was easy, I put the update.zip on my phones’ SD card, booted into fastboot mode, fastbooted the recovery image and applied the update.zip. It took about 2 minutes in total.

The OS: There are a few new things:

  • New keyboard with longpress for things like numbers and symbols ($%#()!) etc. This is great.
  • New Social Networking integration. When you’re setting it up it asks for your twitter, facebook and flickr details. From then on uploading a picture to any of those is a one “click” process. The built in Twitter client, Peep, is pretty nice too.
  • TouchFLO is very pretty but it really needs to be equated to Vista… It is CPU intensive and therefore your battery life is decreased. I used Touch Flo for a few days and then turned it off, which essentially makes the phone look like the traditional Android interface and increase the battery life. TouchFLO does have some nice widgets that are not available once you disable TouchFLO.
  • There are some new non-TouchFLO widgets that come bundled with the image (A neater calendar widget is one) but I think these are probably all available on Android Martket.

Now that I’m back to running the standard Android UI, I do believe that the Hero ROM has increased my battery live compared to the stock image that the phone came with.

All in all I’m very happy with the Hero ROM and I certainly won’t be going back. 😉

j.

Rooting a Vodacom HTC Magic and upgrading the firmware in South Africa to get Android Market and more.

If you’re in South Africa and you own an HTC Magic Android phone you’ll soon realise that it’s missing Android Market, which to be honest, is pretty much what makes Android so damn amazing in the first place. In its place is the Leaf Open Market. Leaf are the South African HTC importers. Open Market is about as awesome as getting stabbed in the eye with a pencil, repeatedly. The application works okay, but the selection of applications is incredibly dismal.

Update 30/06/09: There are rumblings that Leaf is going to “release” Market in “two weeks”. Supposedly they’re going to be sending out instructions on how to ROM your phone or allowing you to take it into a vodacom store and getting it ROM’d there (most likely they’ll need to send it away). I have no idea how true these claims are. Maybe someone wants to phone Leaf and ask them?

Update 23/07/09: A really good resource for anyone looking to hack their Magic is the XDA-Developers Forum. Some kind souls have also recently added a Wiki specifically put together for hacking the Magic (Sapphire) which every one of you should read from start to finish.

Anyway, the primary reason I love Android is because it’s hackable. Commence hacking. Warning: Yes, this probably will void your warranty. Yes, it’s possible that the real Android Market will eventually be released in SA, but I’m not holding my breath.

Basically what we’re doing here is updating the phone’s firmware to the version HTC originally intended the Magic to ship with… There are stacks of other firmwares (called ROM’s in the ‘community’) floating around, I’m just pointing to one that definitely works. Using the wrong ROM can put your phone in a state where it refuses to boot… Never fear, see below ‘Recovering from a bricked Magic‘.

General Steps

I’m going to explain the general steps you go through first… This will help you understand what it is you’re about to do so that you aren’t just blindly following instructions.

  1. We get the Android SDK and Fastboot applications installed on our computer
  2. We copy the ROM we want to install onto the SD Card and rename it ‘update.zip’
  3. We boot the phone into FASTBOOT mode.
  4. Using the FASTBOOT program we temporarily upload and ‘install’ the daldroid-recovery.img ROM over USB. (This is a special boot loader app that lets us do cool stuff like made Nandroid backups and install that update.zip ROM from the SD Card.)
  5. The phone boots into the daldroid-recovery mode.
  6. We backup our original ROM to the SD Card using Nandoid, clear some settings and then install the new ROM.
  7. Congratulations, you have a rooted, real android phone 😉

Step by Step Instructions

Okay, now that you know the basic steps, here are the details.

  1. Enable USB debugging on the device in Settings->Applications->Development->”USB Debugging”
  2. Ensure you have the Android SDK downloaded, and the included USB driver installed correctly on your desktop.
  3. Download Fastboot. Since I use linux I just copied the ‘fastboot’ binary to the Android SDK’s tools directory and made it executable.
  4. Open up a terminal/dos prompt and “cd” to the tools directory in your Android SDK folder.
  5. Plug in your USB Cable.
  6. Run the following command:
    adb devices

    Linux users will need to run:

    sudo ./adb devices
  7. You should see your Android phone’s serial in the list. If you get an empty list, you need to sort out your USB driver.
  8. Download Daldroid’s Rooted (adb shell) Original HTC ROM for Magic and Daldroid’s Recovery Image
  9. Unzip the daldroid-recovery.zip file and put it in the Android SDK’s tools directory.
  10. Connect the phone with the USB cable and from the notifications bar, mount the SD card. Rename daldroid-htcmagic1-signed.zip to update.zip and copy it to the phone’s SD card.
  11. On your device, enter the bootloader FASTBOOT mode by turning off the phone and then, while it is off, pressing the volume down button while pressing the power button.
  12. You should get a screen with some androids on skateboards at the bottom…Give it a second to run whatever tests it runs.
  13. Pressing the back button will get you into FASTBOOT MODE and you should see the screen change to say ‘FASTBOOT USB’
  14. Type the following commands on your computer (not on the device):
    fastboot boot daldroid-recovery.img

    Again, Linux users will need to run:

    sudo ./fastboot boot daldroid-recovery.img
  15. This will upload (over usb) a mini recovery image and reboot your phone… It’ll take a few seconds and you’ll be prompted with the recovery interface.
  16. Select ‘Nandroid Backup 2.1’ from the menu. This will write a backup of your existing system to the SD card… useful in case something goes wrong.
  17. Select ‘Wipe Data/factory reset’. This erases settings etc that might not be compatible with the new firmware
  18. Select ‘Apply sdcard:update.zip’. This essentially installs the system image from the update.zip file.
  19. Select ‘reboot system now’.
  20. Wait a long time for the first initialization. Congratulations, you have a real, rooted, Android phone with Android Market and thousands of quality apps to install.

The really nice thing about the Daldroid image is that it comes with all the APN settings etc required for Vodacom so your HSDPA will work straight away.

Recovering from a ‘Bricked’ Magic

I promised earlier I would tell you how to recover from a ‘Bricked’ Android phone… I’ve put ‘bricked’ in quotes because a lot of people seem to be thinking they’ve bricked their phones when in reality it’s quite easy to recover.

  1. Check if you can get to into Fastboot Mode:
    1. Remove the battery.
    2. Wait 10 seconds (or more)
    3. While pressing the volume down button, pop the battery back in.
    4. If it doesn’t turn on by itself, keep pressing the volume down button and press the power button.
    5. You should get the Fastboot menu.
    6. If you don’t get into Fastboot mode, try a few more times and then panic. I don’t know how to help you. Try Google.
  2. You now need to copy the right update.zip (see step 8 above) onto your SD Card. There are two ways:
    1. Get a usb card reader or use another cell phone that will allow you to mount the SD Card over USB and just copy it.
    2. or, the slightly fancier way, while your phone is in Fastboot mode run the following command on your computer (first put the new update.zip in your Android SDK tools directory):
      adb push update.zip /sdcard/update.zip

      Again, Linux users will need to run:

      sudo ./adb push update.zip /sdcard/update.zip

      This uploads the file directly onto the SD Card via USB. It takes a minute or two so do be patient.

  3. Now you just need to follow steps 11 though 20 from the instructions above and you should be golden.

Updated (21 June 2009) – Putting the original Vodacom ROM back

If for some or other reason you want to go back to the old version of the Vodacom ROM, you can do so quite easily.

Nandroid writes a selection of files to the SD Card:

2.5M  boot.img
339K  cache.img
60M   data.img
256K  misc.img
265    nandroid.md5
5.0M  recovery.img
78M   system.img

You should really make a copy of them on your local machine just in case. Once you’ve got those files on your local machine you can restore your phone using fastboot like so:

  1. Copy the nandroid files (*.img) from your backup into your SDK Tools Directory.
  2. Boot your phone into Fastboot mode (Steps 11, 12, 13) from the Step by Step guide above.
  3. Run the following commands from your computer:
    fastboot erase system -w
    fastboot erase boot
    fastboot flash system system.img
    fastboot flash userdata data.img
    fastboot flash boot boot.img
    fastboot reboot
  4. Congratulations, you now have your old Vodacom phone back. :/

Hope this helps, feel free to ask questions.