Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Introduction to the Make Controller Kit in C#

Difficulty: Easy

Time Required: 1-3 hours

Cost: $150

Software: Visual Studio Express Editions

Hardware: Make Controller Kit

The Make Controller Kit was developed by MakingThings in collaboration with Make Magazine to provide an open hardware platform that encourages experimentation, learning, and - most importantly - the creation of fun, interesting, and practical projects. We aim to provide the easiest possible way for creative people from all backgrounds to get involved making interactive devices in the physical world. The firmware and software tools used with the Make Controller Kit are open source, and the schematics and hardware information are freely available as well.


The Make Controller Kit

Project Possibilities

The flexibility of the Make Controller Kit enables a wide range of possible projects:

  • Control up to 4 DC motors to create a robotic platform.

  • Connect to your LAN or other web service to enable networked and distributed projects. Control your garage door opener, or jointly monitor carbon dioxide levels with other users across town or across the state.

  • Use up to 8 analog inputs to log data on your PC, or provide custom control mechanisms for your programs.

    • Track the temperature in your house over several weeks.

    • Monitor the amount of electricity your appliances use.

    • Use a motion detector to alert your desktop applications to the presence of a person.

  • Control animations or other feedback devices with 4 standard servo controllers.

Structure/Architecture of the Make Controller Kit

The Make Controller Kit consists of two parts – the Controller Board and the Application Board. The Controller Board includes the microcontroller itself – the SAM7X256 from Atmel – and brings the majority of its signal lines out to standard 0.1” spaced headers. The Controller Board physically plugs into the Application Board, which includes the hardware necessary to connect to real devices – motors, sensors, and lights, among others. Alternatively, the Controller Board can be plugged into a circuit of your own design. Because the Controller Board is common to both, everybody benefits from and contributes to the same software tools.


The Make Controller Board

By default, the Make Controller Kit can connect as an interface to a PC either via Ethernet or USB – then you create desktop applications that talk to the Controller to read sensor data, or to control motors or lights. The board itself can also be reprogrammed to run standalone from the PC – firmware is written in C, and can be easily uploaded via USB.

.NET and the Make Controller Kit

The .NET C# library for the Make Controller Kit is designed to make it as simple as possible for developers to integrate the Make Controller Kit into their desktop applications, offering the transparency that makes open source software so rewarding to work with. You can communicate with the Make Controller Kit from your applications over either an Ethernet or USB connection, or both. The library is supplied both in source form and built, as MakeControllerOsc.dll

Communication

Messages to and from the board conform to the OSC (Open Sound Control) protocol. OSC is an open, transport-independent standard supported by an increasing number of environments and devices.

OSC messages are represented by the class OscMessage, and consist of two elements:

  1. An address string for the device on the board you're dealing with.

  2. A list of value(s) being sent to or from that device. The list of values is optional.

From the perspective of OSC addresses, the Make Controller Kit is organized into a hierarchy of two or three layers:

  • subsystems – classes of device, such as analog inputs, servo controllers, and digital outputs.

  • devices – the index of a specific device within a subsystem. If there is only one device in a subsystem, the device is not included in the OSC address.

  • properties – different devices have different properties, such as the value of an analog input, the position of a servo motor, or the state of an LED.

OSC messages always begin with a slash, and use a slash to delimit each element in the address, so an example OSC address string would look like:

/subsystem/device/property
 

The second part of an OscMessage is a list of values to be sent to the specified address. The OSC types that are used by the Make Controller Kit for these values are integers, floats, and strings. The values in this list are simply separated by spaces, and the list can be arbitrarily long. Most devices on the Make Controller Kit expect only one value. For example, to set the position of servo 1, you might send a message which in string form might look like:

 /servo/1/position  512
 

This addressing scheme allows interactions with the board's various subsystems and properties, and most importantly, accommodates the possibility of future or custom devices on the board that have not yet been implemented or imagined. If somebody creates, for example, a GPS extension to the board, communicating with that device from this library is the same as for any other. More details about OSC can be found at www.opensoundcontrol.org.

Sending Data

As previously mentioned, the Make Controller Kit can communicate over both Ethernet and USB. Messages are sent as packets, both over USB and UDP, and corresponding structures are used – UsbPacket and UdpPacket. Once you've created a packet, you can simply call its Send() method, with the OscMessage you'd like to send. There are helper methods to create an OscMessage from a string, or you can pass in the OscMessage itself.

For example, you might set up your UsbSend() routine to look something like:

public  void usbSend(string text)
{
  OscMessage  oscM = Osc.StringToOscMessage(text);
  // oscUsb is  an Osc object, connected to a UsbPacket object
  oscUsb.Send(oscM);
}

If your data is already in the form of an OscMessage, you can call oscUsb.Send() directly.

Reading Data

The Make Controller Kit must be polled in order to read data from it. To do this, send an OscMessage with the address of the device you'd like to read, but omit the list of values. When the board receives an OscMessage with no value, it interprets that as a read request, and sends back an OscMessage with the current value at the appropriate address.

The .NET Make Controller Kit library conveniently provides handlers that will call back a given function when an OscMessage with a given address string is received. Your implementation could look something like:

// Set the handler in the constructor for a particular address
MyConstructor()
{
  udpPacket  = new  UdpPacket();
  oscUdp  = new  Osc(udpPacket);
  // A thread  is started when the Osc object is created to read 
  // incoming  messages.
  oscUdp.SetAddressHandler("/analogin/0/value",  Ain0Message);
}
//  The method you specified as the handler will be called back when a 
//  message with a matching address string comes back from the board.
public  void AIn0Message(OscMessage oscMessage)
{
  // write the  message to a console, for example
  mct.WriteLine("AIn0  > " + Osc.OscMessageToString(oscMessage));
}

You could alternatively set a handler for all incoming messages by calling the SetAllMessageHandler() method in your setup, instead of SetAddressHandler().

System Commands

In addition to reading and writing to the IO devices on the board, you can also programmatically read/write parameters of your Make Controller Kit's configuration. For instance, you can check its serial number (good for uniquely identifying it), read and/or change its IP address, or tell it to shut down.

Quick Code Examples

We've put together a few simple code examples to demonstrate a few of the board's capabilities, and to give developers a place to start in creating their own applications.

  1. CPU Monitor – a servo motor moves an indicator to show how busy your machine is. The application uses the System.Diagnostics PerformanceCounter class to monitor CPU usage.


The onscreen UI


The complete physical system

Every 250ms the counter is examined and if the CPU usage is different from last time a new value is sent to the servo. The servo is set to move relatively slowly so the signal is smoothed out a little.


The servo motor


The dial being turned by the servo motor

Desktop Timer – a distance measuring sensor points out from the monitor on your computer and, if it finds you in front of it begins counting how long you're at your desk. If you go away, the work timer stops and the away counter begins.

The Distance Measuring Sensor provides a varying voltage depending on how close a target is in front of it. This voltage is converted into a number by the Make Controller Kit whenever the desktop polls the board for it. When the value exceeds a certain amount, the computer decides someone's at the desk and the Working counter is incremented. If the signal is above that amount for longer than 5 seconds, the Away counter is incremented instead.

MCTest - a .NET application similar to mchelper that allows users to send OSC messages to the Make Controller Kit over USB and Ethernet from a command line. Great for testing and debugging the board, and familiarizing yourself with the OSC protocol that it runs.

Application Deployment

To run your application, you'll need to do a few things:

  • Confirm that your Make Controller Kit is running appropriate firmware – the default firmware, called Heavy, is fine.

  • Make sure the application has access to the MakeControllerOsc.dll assembly, by placing it either in the same directory as the application, or in a shared location.

Summary

The Make Controller Kit is provides a friendly, open, and extensible environment for creating interactive devices, exhibits, and installations. Users are continually creating new applications and examples that can be easily shared with others. Because the Make Controller Kit is accessible and rewarding for users all the way from elementary school students to professional engineers, there is a vibrant community working with and advancing this platform. We look forward to seeing what you create with it.

Links

MakingThings home - www.makingthings.com/makecontrollerkit

Make forums - http://forums.makezine.com/?CategoryID=5

Getting Started With the Make Controller Kit and .NET C# - http://www.makingthings.com/makecontrollerkit/guides/dotnet.html

Make Controller Kit .NET C# Reference - http://www.makingthings.com/makecontrollerkit/software/doc/dotnet/html/

Tags:

Follow the Discussion

  • David FowlerDavid Fowler

    Great article! I have been playing around with the Make Controller Kit and am a C# guy so this will come in handy.

    I have some information about the Kit at my site and I hope to interface an graphic LCD to the unit.

    I was planning to build an OSC module for the GLCD so that it could be controled remotly. The lack of a bunch of GPIO is my first major issue with the Kit. I may use another uC to control the display and then use the extra serial on the Kit to talk to the display module.

    I have been controlling the GLCD from C# using a parallel port class I created. The source is at my site as well. Not the GLCD driver, the parallel port code.

    http://www.uchobby.com

  • ......

    pagine piuttosto informative, piacevoli =)

  •  VB.NET Support - Electronic Circuits Projects Diagrams Free VB.NET Support - Electronic Circuits Projects Diagrams Free

    PingBack from http://www.electro-tech-online.com/micro-controllers/89400-vb-net-support.html#post700525

Remove this comment

Remove this thread

close

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.