A steaming hot .NET Gadgeteer project, the steampunk weather station

Today's Hardware Friday post is a .Net Gadgeteer project that given the recent weather in the States, I thought weirdly appropriate.

Prototyping a connected object using the .NET Gadgeteer: the example of a steampunk meteo station

For years I’ve had this very old voltmeter I wanted to do something with: I liked the beautiful wooden case, the leather strap, but honestly, I had better tools for my day to day electronics experiments. I found a purpose for it when I started experimenting with the .NET Gadgeteer kit, and one of my first prototype of connected object: a simple meteo station that would measure temperature, humidity and pressure and upload data to a feed in Cosm, formerly known as Pachube, which is a connected objects web platform used to publish and consume realtime data. I had two goals with this project: have fun with the .NET Gadgeteer kits, and experiment on a complete connected object prototyping cycle (I’m not going to talk about industrialization or mass production here).

Here’s the plan:

  1. Discovering the .NET Gadgeteer tooling, and interfacing with sensors
  2. Connecting to Cosm (Pachube)
  3. Creating the steampunk GUI
  4. Making the meteo station user-configurable using a small webserver
  5. Prototyping the finished design using 3D modeling tools

While this article reads fine on the web, it's also available as a Word Document here. 

The article delves into each of the above areas, providing a number of code snips and related resources. Frist the hardware is covered.

Discovering the .NET Gadgeteer tooling, and interfacing with sensors

The .NET Gadgeteer is a rapid prototyping environment for connected objects. Kits are manufactured by Microsoft partners, like GHI Electronics (http://www.ghielectronics.com), Seed Studio (http://www.seeedstudio.com/depot/), or the Mountaineer Group (http://www.mountaineer.org/). The core libraries (based on the .NET Micro Framework: (http://www.netmf.com)) are maintained by Microsoft and the community, while the hardware specific drivers and updaters are maintained by the different partner.

Therefore, there are 3 different packages to install on top of Visual Studio 2010 (any version, Express will do) to install the .NET Gadgeteer tools: the .NET Micro Framework base, the Gadgeteer Core, and the hardware specific SDK. In our case, we are going to use a FEZ Spider Kit from GHI Electronics as well as a couple of sensors and a Wifi module.

image

Then each code section;

Connecting to Cosm

Before connecting to Cosm, we need to connect to a network. GHI Electronics offer different modules, we’ll talk about the Wifi Module, and the Ethernet (J11D) module .When purchasing anyone of them, pay attention that there are different references depending on the motherboard you’re using. Read the docs!

The Ethernet module is the easier to program: here’s the code to connect to a network using DHCP:

ethernet.NetworkSettings.EnableDhcp();
 

The static equivalent:

ethernet.NetworkSettings.EnableStaticIP("192.168.0.10", "255.255.255.0", "192.168.0.1");string[] dnsServers = { "192.168.0.1", "192.168.0.2" };ethernet.NetworkSettings.EnableStaticDns(dnsServers); 

There are a couple of events you can subscribe to be notified about Network changes:

ethernet.NetworkDown += new GTM.Module.NetworkModule.NetworkEventHandler(ethernet_NetworkDown);ethernet.NetworkUp += new GTM.Module.NetworkModule.NetworkEventHandler(ethernet_NetworkUp);
 

The Wifi module is also very straightforward to configure: you are going to use the same code, only you need to join a network first:

WiFi_RS21.WiFiNetworkInfo wifiInfo = wifi.Search("<SSID>");wifi.Join(wifiInfo, "<KEY>");
 

The second step is to set the system time. Since there’s no “backup” battery that saves the clock time, one has to set it everytime the system is powered. This is done with a small NTP library called MicroNTP extracted from the Micro Framework Toolkit: http://mftoolkit.codeplex.com/

DateTime UtcTime = NtpClient.GetNetworkTime("0.fr.pool.ntp.org");Microsoft.SPOT.Hardware.Utility.SetLocalTime(UtcTime + new TimeSpan(TimeSpan.TicksPerHour * 2));
 

The NTP server returns the Coordinated Universal Time (UTC) therefore I add the timezone difference (+2H, hardcoded here for readability reasons, it would have to be a system parameter, we’ll see later how to create a settings system.

Creating the Steampunk GUI : reading and displaying images from the SD Card, and charting data.

There are two ways to create a user interface using the .NET Micro Framework. Either using the very small subset of WPF, or, a bit like a game, create a display loop and use graphical elements and fonts, just like a game. In my case, I really want my interface to have a steampunk feeling so I’m going to use a lot of images. Since it will be sealed in a box, I have no need for touch interactions, so I’m going to go for the game-like approach. I’ll have a timer that will regularly draw all images, in the right order and at the right place, depending on the various data I have. The only “non-image” data that I’m going to display is a graph, and for that all I need is a SetPixel() method. It’s very easy.

Building a webserver and configuration interface within the meteo station

There’s a sample project for .NET Micro Framework that works great, but the .NET gadgeteer makes it even simpler: there’s a WebServer class already included, with basic routing functionalities. We’re going to use it. We will store the HTML files on the SD Card, as well as a configuration file.

Starting a WebServer is as simple as one line of code:

WebServer.StartLocalServer(ethernet.NetworkSettings.IPAddress, 80);

To configure routing (i.e. associate code execution with specific URLs), use the WebEvent class:

WebEvent webevt = WebServer.SetupWebEvent("Settings.htm");webevt.WebEventReceived += new WebEvent.ReceivedWebEventHandler(webevt_WebEventReceived);

Once the webevent is configured, calling “http://ip:port/Settings.htm” will automatically trigger the execution of the handler associated with the string “Settings.htm”. What we need to do in the handler, is therefore to return, as an HTTP response, the content of the Settings.htm file.

Conclusion

In this article, we’ve gone through the process of prototyping every function of a connected object, from the sensors, to the network, and configuration. Hopefully you now understand:

  • How to use the .NET Gadgeteer tooling
  • How to connect sensors, and get data from them
  • How to work with different kind of files on the SD Card
  • How to build a simple user interface
  • How to post them on the network
  • How to interface with Cosm
  • How to buld a webserver in your object
  • How to build a configuration mechanism

We also made use of a few toolkits (mftoolkit, HttpUtility, Pachube DAL, etc) that will hopefully help you, and concluded on the possibility to use CAD tools to physically design the object around the 3D models of the gadgeteer components. Now it’s your turn to build something!

In the end, there's a cool little steampunk weather station...

image

Tags:

Follow the Discussion

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.