Don’t you hate it when you can’t the easy stuff to work.  Well if I wrote a real article base blog, I guess I would just hide my problems from you, but I write a blog as in: Web Log, and not an “article” based quality item like the  members of my cohort here at Microsoft.  Pretty sure they wish I would get to the point of writing real articles.  But you know what?  I am just too lazy.  Really.  It’s an accomplishment in the hillbilly in me.

Yep, spent the day trying to troubleshoot why a simple voltage divider using a variable resistor or Pot, to divide down the voltage being presented to the analog input on a Netduino.  This is a common circuit, in this case a resistor is used in the circuit, although you could use the pull up or pull down resistor in the Netduino to do the job.

Here is the code I used in the Netduino, with the latest version of the NetMF the AnalogInput Read method is a double and not an int, but that wasn’t the problem. Of course in .NETMF, the Convert can only be used for string to whatever you want converted, so you have to cast the value, again thanks to Bret Stateham he helped me out with that problem.  I also used that desperately cheap oscilloscope to good purpose as well, it showed me that the waveforms were there.  Just messed around with the wires for awhile and then it worked.  Darn it.  Well it works, and now I can move onto getting my sensor arrays tested using both Arduino and Netduino.  Next stop is the Galileo board using Windows 8 Embedded or something.  Here is the software, you can figure out the process for connecting up the voltage variation system using a variable resistor.

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

namespace Blinky2
{
    public class Program
    {
        public static void Main()
        {
            // write your code here
            OutputPort led = new OutputPort(Pins.GPIO_PIN_D0, false);
            AnalogInput pot = new AnalogInput(Cpu.AnalogChannel.ANALOG_0);
            int potValue = 0;

            while (true)
            {
                potValue = (int)pot.ReadRaw();
                led.Write(true);
                Thread.Sleep(potValue);
                led.Write(false);
                Thread.Sleep(potValue);
            }

        }
    }
}