Tuesday, July 12, 2011

How to annoy your wife with a Netduino...

So, I stopped by a Radio Shack tonight to pick up some parts and decided to buy the Netduino some toys.

Amongst some other pieces, I picked up a 12 VDC Piezoelectric Buzzer (RS# 273-0059).  You can find cheaper ones online - just make sure that the low-end of the voltage range for yours is around 3 volts (http://www.netduino.com/netduino/specs.htm).

You can drive this pretty easily by simply plugging this buzzer in between the ground pin (GND) and one of the digital I/O ports (I used 13 - it's right next to the ground pin).  Somewhat annoyingly, it will immediately begin buzzing when you power-up the Netduino - this does not endear you to your sleeping wife.  :)

The plan was to make the last project into something useful.  As you may know - the FCC requires that amatuer radio operators identify periodically during operation (Sec 97.119 - http://www.w5yi.org/page.php?id=124).  With a couple quick modifications - you can make your Netduino provide your ID whenever you press the button.  This might actually be useful. I don't operate on CW often, but you can ID with CW wherever CW is authorized - So, everywhere but 60 meter right (not an issue for me)?

You can do this with a couple tiny modifications from the previous project:

First, change your OutputPort from:
// setup our output port (on-board LED)
static OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);


// setup our output port (piezo buzzer (RS # 273-0059) between D13 and ground)
static OutputPort piezo = new OutputPort(Pins.GPIO_PIN_D13, false);

Then change your write operations from:


Then switch the MESSAGE constant to your call sign.   Hit the "Start debug" button and then press your button and you should get your call sign in CW over the buzzer at about 14 wpm (based on the UNIT constant being left at 100).

(I also ran across this free eBook on the .NET Micro Framework tonight - I haven't read through it yet - but it looks interesting - check it out:  Beginner's Guide to C# and .NET Micro Framework)

Sunday, July 10, 2011

Review: "Programming HTML5 Applications" by Zachary Kessin; O'Reilly Media

I recently joined the O'Reilly Blogger Review program and the first book I selected to review was "Programming HTML5 Applications" by Zachary Kessin.

I enjoyed this book and learned a few interesting things along the way.  But I would tend to describe myself more as a JavaScript intermediate "user" more than a skilled JavaScript "programmer".  If you are an intermediate JavaScript user - this book will help you rise to the next level.  If you are already a skilled JavaScript programmer, I think you may find that there is not sufficient topical (HTML5) information in this book to justify your purchase.

Zachary Kessin has been involved with web development since the early 90's.  His experience as a working programmer shows clearly as he shares the lessons born from these experiences - this book doesn't read like a man page for JavaScript.  It reads like a talk from an experienced programmer sharing the tips of the trade - not only in terms of how - but also why you do things.  Overall this is good - but sometimes it seems like he slips into a shorthand way of describing things that takes a couple readings to decipher.

At 132 pages cover to cover, this is a short book, which isn't necessarily a bad thing.  You could probably make it shorter by skipping chapter one and ten - which really don't add much value to the experience in my opinion.  Chapter one is kind of a rehash of the history of the web with some focus on the evolution of development paradigms. In chapter ten, Zachary tries to look into his crystal ball and see the Internet of 2017.  Neither chapter is particularly relevant to the topic of programming HTML5 applications.  If you are already a skilled JavaScript programmer, you can probably similarly skip past chapters two through five without missing anything about HTML5 (although I found these chapters very useful - as they helped fill several gaps in my knowledge of JavaScript).

A better title for this book might be, "Modern JavaScript and HTML5."  Beginning in chapter two, the author takes the reader on a tour of "advanced" (my word) JavaScript methods, JQuery and ExtJS before discussing tools and methods for testing JavaScript.  I was aware of many of these topics at various levels previously, but the author does a good job of explaining them at a high level and why you would use them.  These chapters aren't really tutorials, but you get enough information to start exploring each area - which is probably how most of us learn JavaScript anyway.

From chapter six the book turns to HTML5 coverage beginning with a discussion about the LocalStorage APIs.  It goes on to offline applications, web workers and web sockets. It starts off as mostly similar content to what you would see in http://diveintohtml5.org/ or similar sites, but where it shines is that the author ties these features to real-world examples and back to the topics he previously discussed (like ExtJS and JQuery).  Throughout most of the book, the examples reinforce the text pretty well, although they could be commented better in several cases.

I think the main problem I have with this book is what I mentioned earlier - the title of the book doesn't seem to mesh with the content as well as you might hope.  For a book titled "Programming HTML5 Applications", my expectations were totally different than the (pretty good) content that was in this book.  I think I expected that the book might take that familiar path of developing a non-trivial "HTML5 Application" teaching how to use the HTML5 APIs as it goes.  I would have liked that better.

So...  Would I recommend this book?  Probably not.  It was interesting.  I learned a few things (much from chapters two and three).  It was a good start.  I wouldn't mind looking at it again when it is finished - I might change my mind (a great effort on finishing chapters eight and nine would be a good start).  But the problem right now is that there is already so much of the sort of HTML5 information that this book provides - in a very similar format ("this is what is new - here's a snippit") - available for free at a number of great HTML5 sites (like "Dive into HTML5" as mentioned before.)

Note: This was my first "Early Release" book I've looked at.  Apparently, "Early Release" indicates that the book was released directly from the author without the benefit of a review by an editor.  I found the large number of typos, misspellings, unfinished sections, etc. in the text to be quite distracting. I've tried to look past this.  I think that early access is a great idea especially for fast moving domains like web development.  But if this sort of thing bugs you - you might want to wait for the normal release.

Disclosure: I was provided with a free PDF copy of this book by O'Reilly as a part of their "Blogger Review Program" program.  (http://www.oreillynet.com/oreilly/bloggers/home.csp)

Saturday, July 9, 2011

My First Netduino App

So, as I mentioned earlier, we ordered a Netduino awhile back.  (We got ours via Amazon.)  This arrived earlier this week and I finally got some time to play with it during lunch today.

We had played with the MSP430 a little bit and messed around with an Arduino previously.  The Netduino is quite similar to the Arduino - but easier.  The combination of the Visual Studio, the .NET micro framework and the Netduino SDK (All linked to here) really works well so far.

After completing the obligatory "blink the LED" tutorial and reading the event handler example from the Netduino site I decided that a "Hello World" app was needed.  Obviously, this had to be in Morse code.  :)

So I whipped one up pretty quickly (this dev environment makes it REALLY fast - maybe 20 mins tops - mostly finding the proper timing for a dit and a dah (http://en.wikipedia.org/wiki/Morse_code)).  After work, I decided to clean it up a bit (it was a hideous sequential list of calls to dit and dah functions and sleeps).  At this time I ran across this implementation: http://www.hanselman.com/blog/TheNETMicroFrameworkHardwareForSoftwarePeople.aspx which seemed a lot more like what I was looking for.

So, mixing it all up - this is what I came up with. (Some portions © Copyright 2011, Scott Hanselman under Creative Commons Licensing http://creativecommons.org/licenses/by-nc-sa/3.0/)

using System;
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace NetduinoApplication1
    public class Program
        const String MESSAGE = "Hello World";
        const int UNIT = 100;            // controls speed
        const int SHORTMARK = 1 * UNIT;  // dit
        const int LONGMARK = 3 * UNIT;   // dah
        const int IEGAP = 1 * UNIT;      // gap between elements (dit and dah)
        const int SHORTGAP = 3 * UNIT;   // gap between chars
        const int LONGGAP = 7 * UNIT;    // gap between words
        // setup our output port (on-board LED)
        static OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);

        private static Char[] Letters = new Char[] 
                'a', 'b', 'c', 'd', 'e',
                'f', 'g','h','i', 'j', 
                'k', 'l', 'm', 'n', 'o', 
                'p','q', 'r', 's', 't', 
                'u','v', 'w', 'x','y',
                'z','0', '1', '2', '3', 
                '4', '5', '6', '7', '8',
                '9', ' '

        private static String[] MorseCode = new String[] 
                ".-", "-...", "-.-.","-..", ".", 
                "..-.", "--.", "....","..", ".---", 
                "-.-", ".-..","--", "-.", "---", 
                ".--.","--.-", ".-.", "...", "-", 
                "..-","...-", ".--", "-..-","-.--", 
                "--..","-----", ".----", "..---","...--", 
                "....-", ".....", "-....", "--...", "---..", 
                "----.", " "

        public static void Main()
            // setup our interrupt port (on-board button)
            // InterruptEdgeLow = Interrupt on button press only (not button up)
            InterruptPort button = new InterruptPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);

            // assign our interrupt handler
            button.OnInterrupt += new NativeEventHandler(button_OnInterrupt);
            // go to sleep until the interrupt wakes us (saves power)

        // the interrupt handler 
        static void button_OnInterrupt(uint data1, uint data2, DateTime time)
            foreach (char letter in MESSAGE.ToLower())
                string morse = ConvertTextToMorse(letter);
        public static String ConvertTextToMorse(char letter)
            int index = -1;
            index = Array.IndexOf(Letters, letter);
            if (index != -1)
                return MorseCode[index];
            return string.Empty;
        public static void TransmitMorse(string morse)
            foreach (char c in morse)
                if (c == ' ')
                    if (c == '-')

Also thanks to the "CodingFreak" blog for the very nice instructions on adding syntax highlighting to Blogger!