Scott Hanselman

Exclusive Sneak Peek: The AGENT Smart Watch Emulator and managed .NET code on my wrist!

June 18, '13 Comments [30] Posted in Micro Framework | Tools
Sponsored By

The AGENT Smart Watch

I'm totally geeked out about Smart Watches. I always have been, from the original Microsoft SPOT watch (from 10 years ago!) to the Pebble, and now the AGENT Smart Watch from Secret Labs. Secret Labs are the folks that brought us the Netduino open source electronics platform that uses the .NET Micro Framework. It's pretty awesome that you can write C# and run it in 64k or in 64gigs, from the wrist to the cloud.

Upcoming Conference: If you're in or around Chicago in July 2013, consider joining Chris Walker from SecretLabs and I at the MonkeySpace conference! We'll be speaking about developing for embedded systems and the AGENT Watch with C#. What are the power considerations? How low-level is this kind of coding? Can one kind of app cause battery drain while another keeps the watch going for a week? What about notifications and bluetooth? We'll cover all this and lots more, join us.

The AGENT Smart Watch will talk to your phoneThe AGENT Smart Watch was trying to raise $100k to build a watch and as of the time of this writing they are within spitting distance of a MILLION dollars! There's just hours to go to get in on this cool Kickstarter. (Remember, Kickstarter is an investment, not a store.)

Not only is this a .NET Microframework Device, but we can start writing apps now using the AGENT Watch Emulator. From their Kickstarter site:

Traditional smartwatches run apps in an unrestricted environment.  AGENT's OS includes a managed runtime, optimized for our low-power architecture.  It is called the .NET Micro Framework and it makes watch apps trustable.

This feature-rich managed runtime also offers developers modern features they crave: event-based programming; multi-threading; garbage collection; lambda expressions; exception handling; automatic power management; and much more.

You can install VS2012 and the .NET Micro Framework 4.3 and write an app for your wrist! I alluded to this a little in my Xamarin talk "How C# Saved My Marriage." You can write .NET apps for embedded systems, a watch, tablets, desktops, web sites, large cloud systems and more.

Full disclosure: I have no financial stake or business relationship with SecretLabs, but we are friends and I'm a fan. I helped Chris with some copy writing on the Kickstarter page, its text and reviewing the video as a favor. I have received no money from SecretLabs and I backed the Kickstarter with my own money.

imageI got a preview of the AGENT Smart Watch emulator, and some code from Kickstarter backer Esben Bast who created a binary clock face. I loaded up VS2012 and the binary clock emulator. This initial code is just about 100 lines. You can see the references in Solution Explorer here. SPOT means "Smart Personal Object Technlogy."

The fact that there is an emulator is huge. No worries about breaking a watch or even having a watch! The Agent Watch SDK puts a reference to the AGENT Emulator in my registry, so it shows up directly in Visual Studio:

image

Then I can debug my watch app without a watch, just as if I were writing a Phone App or Web Site. It's a first class experience inside of VS. This makes me feel particularly empowered as a .NET developer because it means I already know how to write apps for this watch and I've never even seen it before..

The code is pretty straightforward, if appropriately low-level. This IS a small device we're talking about!

You've got total control over the screen and what can be displayed. You could create any watch face that you could imagine (that would fit on the screen) because you have a Bitmap to draw to.

The .NET Micro Framework has no fonts loaded by default, but I can include them as resources. There's some "tinyfnt" files in C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Fonts or I could download or make some myself. Even better I can use the TinyFontTool from Miloush.

I can load a font from a resource like this:

font = Resources.GetFont(Resources.FontResources.small);

and then later in my UpdateTime() method, Draw the time on my binary clock screen.

_bitmap.DrawText(DateTime.Now.ToString("HH:mm:ss"), font, Color.White, 45, 15);

Run my emulator again and I have the time printed as well!

Now my AGENT Smart Watch has the time printed above the Binary Clock

The only real "microframework-ism" in the code is that the watch face doesn't want to use a lot of power, so you should "go to sleep." It's the same as if you were writing a console app. If your main() function ends, then your app will end! But, since this is a watch face, we want it to run all the time, so, we start a 1 second timer, then sleep the main() forever. Everything interesting happens as an event on a background thread. (The watch can control the lifetime and tombstone or kill the watch face if you're doing other things.)

public static void Main()
{
_bitmap = new Bitmap(Bitmap.MaxWidth, Bitmap.MaxHeight);
_font = Resources.GetFont(Resources.FontResources.small);

// display the time immediately
UpdateTime(null);

// set up timer to refresh time every minute
DateTime currentTime = DateTime.Now;
TimeSpan dueTime = new TimeSpan(0); // beginning of next minute
TimeSpan period = new TimeSpan(0, 0, 0, 1, 0); // update time every minute
_updateClockTimer = new Timer(UpdateTime, null, dueTime, period); // start our minute timer

_button = new InterruptPort(HardwareProvider.HwProvider.GetButtonPins(Button.VK_SELECT),
false,
Port.ResistorMode.PullDown,
Port.InterruptMode.InterruptEdgeBoth);
_button.OnInterrupt += _button_OnInterrupt;
// go to sleep; time updates will happen automatically every minute
Thread.Sleep(Timeout.Infinite);
}

That last part is interesting. You've got two event handlers here, the one to UpdateTime every second and then one to watch for the Button getting pressed. You want the watch app to be event-driven...it needs to do as little as possible NOTHING until it's time to do something. This InterruptPort is watching for the the middle button (the VK_SELECT button). ResisterMode.PullDown means the button will show "1" or true when it's pressed. InterruptEdgeBoth means I get events when the button is pressed AND when it goes up.

Go make Watch Apps!

Here's another cool watch face from Dylan Mazurek next to the Big Digits example:

PixelFace example Watch for AGENT Smart Watch BigDigits example Watch for AGENT Smart Watch

And finally, here's an animated concept for a World Time face that Steve Bulgin made for Pete Brown as well as another Steve concept below:

The next step will be more than watch faces, it will be watch utilities and apps. Maybe an app for my FitBit, or an app to manage Blood Sugar? Perhaps a Nest app to control my thermostat?

The AGENT Watch Emulator emulator will be available to download this Thursday at www.agentwatches.com. You can get ready by installing the .NET Micro Framework today.

Steve Bulgin watch face for the AGENT smart watchWatch apps can be written in C# using Microsoft Visual Studio 2012 (including the free Express edition). Deploy your apps over Bluetooth and debug them interactively.

Download Visual Studio Express 2012
Download .NET Micro Framework SDK v4.3

Developers can also use AGENT as a secondary display, interacting with it remotely via Bluetooth from their Objective-C, C#, or Java smartphone app.

Even though the watch ships in December, I'm going to start writing apps now so I'm ready for the Watch App Store (coming soon)!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Hanselminutes Podcast 237 - Deeper into the Netduino with Chris Walker from Secret Labs

October 22, '10 Comments [3] Posted in Micro Framework | Open Source | Podcast
Sponsored By

imageScott chats with Chris from Secret Labs about the Netduino Open Source hardware platform. How does Netduino and Netduino Plus relate to the .NET Micro Framework and which parts of Open Source? What can I build with it and it how? What kinds of capabilities does this little piece of hardware have, and can it give even smaller?

Also, Chris and Secret Labs chose Hanselminutes to announce the new Netduino Mini! Listen to the show for all the cool tech details.

NOTE: If you want to download our complete archives as a feed - that's all 237 shows, subscribe to the Complete MP3 Feed here.

Also, please do take a moment and review the show on iTunes.

Subscribe: Subscribe to Hanselminutes Subscribe to my Podcast in iTunes

Download: MP3 Full Show

Do also remember the complete archives are always up and they have PDF Transcripts, a little known feature that show up a few weeks after each show.

Telerik is our sponsor for this show.

Building quality software is never easy. It requires skills and imagination. We cannot promise to improve your skills, but when it comes to User Interface and developer tools, we can provide the building blocks to take your application a step closer to your imagination. Explore the leading UI suites for ASP.NET AJAX,MVC,Silverlight,Windows Forms and WPF. Enjoy developer tools like .NET Reporting, ORM, Automated Testing Tools, Agile Project Management Tools, and Content Management Solution. And now you can increase your productivity with JustCode, Telerik’s new productivity tool for code analysis and refactoring. Visit www.telerik.com.

As I've said before this show comes to you with the audio expertise and stewardship of Carl Franklin. The name comes from Travis Illig, but the goal of the show is simple. Avoid wasting the listener's time. (and make the commute less boring)

Enjoy. Who knows what'll happen in the next show?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Hanselminutes Podcast 232 - .NET Micro Framework with Colin Miller

October 1, '10 Comments [3] Posted in Micro Framework | Open Source | Podcast
Sponsored By

image Scott talks to Colin Miller about the .NET Micro Framework. It's a "tiny CLR" that runs in as little as 64k! He explains how it started with the SPOT Watch (remember that) and how it's grown to an Open Source project under the Apache 2.0 license with a broad ecosystem and dozens of hardware boards available from partners.

Check out my other posts an videos on the .NET Micro Framework, as well as related Arduino posts.

NOTE: If you want to download our complete archives as a feed - that's all 232 shows, subscribe to the Complete MP3 Feed here.

Also, please do take a moment and review the show on iTunes.

Subscribe: Subscribe to Hanselminutes Subscribe to my Podcast in iTunes

Download: MP3 Full Show

Links from the Show

Do also remember the complete archives are always up and they have PDF Transcripts, a little known feature that show up a few weeks after each show.

Telerik is our sponsor for this show.

Building quality software is never easy. It requires skills and imagination. We cannot promise to improve your skills, but when it comes to User Interface and developer tools, we can provide the building blocks to take your application a step closer to your imagination. Explore the leading UI suites for ASP.NET AJAX,MVC,Silverlight,Windows Formsand WPF. Enjoy developer tools like .NET reporting,ORM,Automated Testing Tools, TFS, and Content Management Solution. And now you can increase your productivity with JustCode, Telerik’s new productivity tool for code analysis and refactoring. Visitwww.telerik.com.

As I've said before this show comes to you with the audio expertise and stewardship of Carl Franklin. The name comes from Travis Illig, but the goal of the show is simple. Avoid wasting the listener's time. (and make the commute less boring)

Enjoy. Who knows what'll happen in the next show?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

The .NET Micro Framework - Hardware for Software People

September 7, '10 Comments [24] Posted in Hardware | Micro Framework | Open Source
Sponsored By

imageI'm definitely a software person. I took EE in school and made an LED class, then a small computer like everyone else, and I know my volts and my amps for the most part, but that's about it. The limits of my skills are somewhere around adding an LED and some resistors to leech power off a USB adapter (which I recently did while working on the Hanselcade retro arcade build).

I look at hardware guys like Clint Rutkas in awe. I mean, seriously, who builds a T-shirt cannon from scratch for fun? Amazing.

Clint sent me a "Netduino" board today. It's similar to an Arduino board, except it uses the .NET Micro Framework. Micro you say? That's techie-speak for "tiny ass framework." I spoke to Colin Miller about this earlier in the year on video at Channel 9.

Remember my SPOT watch from 2004? That's Smart Personal Objects Technology, which is marketing-speak for "tiny ass framework." That watch is six years old (and still running nicely, sitting on my desk, in fact) and ran .NET.

Fast forward to today and I find myself plugging in this Netduino board to my computer and following Pete's Hello World Tutorial and I'm looking at this namespace.

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

It's back!

Ok, putting it all together in context. The Netduino is a board that's mostly Arduino compatible and has a published schematic (PDF here) so you could make one yourself, if you wanted. The .NET Micro Framework (or TinyCLR as some folks have called it) is literally that - it's a tiny CLR that runs .NET byte code. You can write C# and it'll run on tiny CPUs with tiny amounts of memory (like 64k or something similarly smallish.) It's been with us all this time, and there is an enthusiastic community built around it.

The .NET Micro Framework 4.1 source is available, it's Open Source under the Apache 2.0 License. (Ya, the new Microsoft is freaking me out also. There's a lot of source that's quietly making its way out under increasingly liberal licenses.) There's lots of great details at Pete's blog.

Here's what a Netduino looks like:

Netduino Overhead Photo

I'm going to think of some hardware ideas that I can build with this. I also have a more capable and fancy Tahoe II with a touch-screen, accelerometer, buttons and more. If you're looking to prototype something quick, or even build a complete system with an off-the-shelf board, do check it out! Here's what a Tahoe II looks like. Remember, all these boards use C# and .NET. It's amazing writing something for hardware using a language and framework I already know how to use. It literally gets me 80% of the way there from a learning curve perspective.

TahoeII Large Development Board

There's also the GHI Electronics EMX Development system, so there's a lot of choices.GHI-00129 Large Development Board

With each of these boards (and others) you just need to get the Micro Framework 4.1, then the SDK for that specific board. It integrates into Visual Studio 2010. If you want to change the product, they are taking proposals in the .NETMF Forums.

Directly from Pete's blog:

Getting Started

What you'll need:

  • Netduino (Scott: or some other .NET Micro Framework board)
  • USB Cable (early Netduino units come with the USB cable) (Scott: Usually a micro- or mini-USB)
  • Visual Studio 2010 and the .NET Micro Framework 4.1 SDK  (you can use C# Express 2010 if you don't have Visual Studio)
  • Netduino SDK in 32 bit or 64 bit, depending on your host OS.
  • Optional: shields and starter kits to do cool things with netduino. Existing Arduino shields are compatible. A shield is just an add-on card that fits the pins on the board.

The SDK installs a device driver for talking to the Netduino. Make sure you select the one with the appropriate bitness, and that you install it before connecting the Netduino to the PC. I installed the VS2010 bits before the SDK, but it shouldn't matter.

Once you plug in the Netduino, using the USB cable, you should see the device driver get installed, and the power LED on the board light up.

Hello World with Morse Code

Now I just have the Netduino for now, so I haven't got any attachments. If I was a hardware guy, I'm sure I'd go try to take apart a toaster or remote control and declare something like "this toaster just needs a one OHM resister on pin-out 5A so I can invert the voltage and it'll toast bread over Bluetooth" but I have no idea what that means. All I can do with the Netduino out of the box to flash its LED, as Pete points out:

public static void Main() 
{
OutputPort onboardLed = new OutputPort(Pins.ONBOARD_LED, false);

while (true)
{
onboardLed.Write(true);
Thread.Sleep(500);

onboardLed.Write(false);
Thread.Sleep(500);
}
}

Let's make it fancier. How about outputting string using Morse Code? Wikipedia says a dot is 100ms long and a dash is 300ms. How hard can it be?

I could go to StackOverflow as they had a contest to see who could make the SMALLEST implementation that would take a string and output Morse Code. They have an extremely optimized (for lines of code) solution. But it's extremely silly. Certainly no more silly than me making an LED blink Morse Code as well, but I'd like to be able to actually read my code. ;)

So, here's a naive 10 minutes solution using this guys' two arrays because I'm too lazy to type up the Morse myself. I could have use a Hashtable also, but two parallel arrays was fine too. The .NET Micro Framework, being micro, doesn't have everything the full framework has. However, being open source, it has taken contributions and version 4.1 includes a Hashtable implementation.

I can even debug directly connected to the board!

netduino debugging

Here's my sad little program (it was very easy!)

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

namespace NetduinoApplication1
{
public class Program
{
public static void Main()
{
OutputPort onboardLed = new OutputPort(Pins.ONBOARD_LED, false);

while (true)
{
onboardLed.Write(false);

foreach (char c in " hello scott hanselman ")
{
string morse = ConvertTextToMorse(c);
Debug.Print(c + " = " + morse);
TransmitDotOrDash(onboardLed, morse);
}

}
}

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 String ConvertTextToMorse(char c)
{
int index = -1;
index = Array.IndexOf(Letters, c);
if (index != -1)
return MorseCode[index];
return string.Empty;
}


public static void TransmitDotOrDash(OutputPort port, string dotordash)
{
foreach (char c in dotordash)
{
TransmitDotOrDash(port, c);
}
Thread.Sleep(300); //gap between letters
}

public static void TransmitDotOrDash(OutputPort port, char dotordash)
{
if (dotordash == ' ')
{
port.Write(false);
Thread.Sleep(700); //gap between words
}
else //it's something
{
port.Write(true);
if (dotordash == '.')
Thread.Sleep(100); //dot
else
Thread.Sleep(300); //dash
port.Write(false);
}
}
}
}

Here's the debug output as I flash "hello scott hanselman" from the board.

Debug Output from the Netduino Board

All it all, it really couldn't be much easier. Next I'll try to get the Tahoe II working and maybe make a game for the boys. Perhaps hook up a speaker and a proximity sensor and see if they can sneak up on it.

Related Links

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb
Page 1 of 1 in the Micro Framework category

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.