Obedient Monkey

 
A couple years ago my family bought me a sock monkey for my birthday.
 
I wanted to start learning more about internet-enabled microcontrollers and Windows Phone apps, so I decided the sock monkey could be used as a notification device.
 
The Idea
There are no shortage of notification devices and techniques these days. Someone even put together a kit for a thermal printer notification system. While this is pretty cool, I wanted something a little more creepy.
 
If I put the internet-enabled microcontroller in the sock monkey, and hooked it up to a couple servo motors and LED's, I could use it to poll a web service and have it engage the physical components when the values change in the web service. Then, using a Windows Phone application, I can acknowledge or "reset" the value, so I'm ready for the next time an interesting event occurs.
  

 
 

This setup requires a few things:

  1. Internet-enabled microcontroller (Netduino Plus) (link to netduino plus)
  2. LEDs and/or servo motors(link to adafruit servo motor)
  3. Web Hosting that allows the publication of web services (GoDaddy)
  4. A computer to run a service to perform monitoring
  5. A phone to interact with the web service to reset values
  6. A sock monkey (not pictured)
 
Proofs of Concept
Servo Motors:
In my sketchduino project, I used stepper motors, which let you very easily give commands like "Move one step (1.8 degrees usually) clockwise". The servo motor seems to be more suited to commands like "Move to position X" and this is done with Pulse Width Modulation. The length of the pulse (usually between 1 and 2 ms) determines where along the servo's range of motion it needs to position itself. For more information that won't make you feel too stupid, click here.

I created a simple program for the Netduino that moves the servo motors to random positions every 500 ms. I attached a rod to the servo motor. In my case the range of motion on the servo is about 500 to 2500 microseconds (0.5 to 2.5 ms)
public static void Main()

{

Servo servo = new Servo(Pins.GPIO_PIN_D9);

while (true)

  {

   double d = new Random().NextDouble();

   servo.Degree = d * 180;

   Thread.Sleep(500);

  }

}



 
 
 
 
 
 
Windows Phone App
As far as mobile phone apps go, I have never developed anything beyond trivial "Hello World" applications, and I have been looking for a fun project that would let me to learn more about the Windows Phone platform.
I have heard that Windows Phone is a dream for developers to work with, but I was still pleasantly surprisied at how easy it was to create the windows phone app to hook up to my hosted web service.
 

 

 
The next logical step was to get the netduino also hooked up to the web service. I should point out that it's not a web service, per se. It's just a page that queries a database for the current values and spits out data in pipe-delimited name value pairs, in the format:
 
<name>:<value>[|<name>:<value>]...
 
This video shows how the Windows Phone App controls the centralized web service, which get picked up by a Netduino Plus, which is performing polls against the same service.
 

Netduino communicating with web service




Parsing logic below:

//(web request above here)

char[] chararray = new char[256];
byte[] buffer = new byte[256];

webStream.Read(buffer, 0, buffer.Length);
chararray = System.Text.Encoding.UTF8.GetChars(buffer);
foreach (char c in chararray)
{
 content = content + c;
}

foreach (string nvpair in content.Split("|".ToCharArray()))
{
 int count = 0;
 string activeNamePart = ""; 
 foreach (string val in nvpair.Split(":".ToCharArray())) 
 {
  if (count == 0) //name part 
  {
   activeNamePart = val;
   count = 1;
  } 
  else //value part 
  { 
   if ((activeNamePart == "1") && (val == "0")) 
   { led.Write(false); }
   else if ((activeNamePart == "1") && (val == "1"))
   { led.Write(true); }
  }
 }
}



Minor Surgery

After properly anesthetizing the patient and sterilizing the scissors, I cut open the back of the sock monkey and pulled out the sock monkey guts.

 
 
 
 
 
 
 
ą
OM1.png
(164k)
Joe Cochran,
Apr 25, 2012, 4:19 PM
Comments