Phidgets + Netduino = Yummy!

Rob Seder sent me a bunch of his old Phidget hardware last week.  It was like Christmas in February!  Since I was working with Netduino the last week, I wondered how easily Phidgets and Netduinos can interface.  In a word – very.  I took one of the sensor cables with one end Rob had already stripped and plugged the intact end into a Phidget force sensor.  I then took the stripped wires and put them into the respective ports on the Netduino (Red = 5V supply, Black = Ground, White = AnalogIn0).  The wiring looks like this:

Blog01

 

I then coded up a simple app like so:

private static void ReadForceSensor()
{   
    AnalogInput analogInput = new AnalogInput(Pins.GPIO_PIN_A0);
    analogInput.SetRange(0, 4095);

    OutputPort digitalOutput = new OutputPort(Pins.GPIO_PIN_D13, false);

    int inputValue = 0;
    while (true)
    {
        inputValue =  analogInput.Read();
        Debug.Print("Input = " + inputValue.ToString());
        if (inputValue > 10)
        {
            digitalOutput.Write(true);
        }
        else
        {
            digitalOutput.Write(false);
        }
        Thread.Sleep(250);
    }
}

Sure enough, the Netduino was reading the voltage coming in from the Phidget push button:

The thread '<No Name>' (0x2) has exited with code 0 (0x0).
Input = 0
Input = 0
Input = 0
Input = 0
Input = 12
Input = 2097
Input = 4095
Input = 4095
Input = 12
Input = 0
Input = 4
Input = 3350
Input = 4095
Input = 4095
Input = 4095
Input = 28
Input = 0
Input = 4
Input = 0
Input = 0
Input = 0
Input = 4
Input = 0

 

I then wanted to compare the values coming in.  Since, the integer value I set in the analogInput.SetRange determines the min and max value, I need to calibrate to the expected values of the Phidget.  I swapped out the pressure sensor for the Slider Sensor so I could hold each value. Turning to the documentation, the range for the Slider control is 0 to 1000 so I jammed those values into SetRange.

Blog02

 

When I attached the Slider to the 8/8/8 Phidget Interface Kit (PIK), the values match exactly.  For example, putting the slider to the far right gives a value of 0, far left 1000, middle 500, etc…

 

image

However, detaching the slider from the PIK and hooking it up to the Netduino, I get a different value:

inputValue = 565

inputValue = 662

inputValue = 688

inputValue = 701

inputValue = 703

inputValue = 692

inputValue = 701

inputValue = 703

inputValue = 685

Not only that, when there is no sensor attached, I am still getting readings:

inputValue = 271

inputValue = 387

inputValue = 430

inputValue = 462

inputValue = 478

inputValue = 481

inputValue = 478

inputValue = 462

inputValue = 456

Something is wrong here.  When I push the slider to far right, I get 0, as expected:

inputValue = 0

inputValue = 3

inputValue = 0

inputValue = 0

inputValue = 3

inputValue = 0

but it about 75% of the way to the left, I get:

inputValue = 955

inputValue = 961

inputValue = 938

inputValue = 961

inputValue = 945

inputValue = 917

inputValue = 961

Interestingly, no matter what value I put as the top bound on SetRange, I am still getting a max out by 3/4 of the way:

inputValue = 9589

inputValue = 9550

inputValue = 9540

inputValue = 9384

inputValue = 9569

inputValue = 9384

inputValue = 9540

When you read the Technical Information on the Slider Control, it talked about the SensorValue is (Vin * 200) when you build your own analog to digital converter. I need to know the voltage reference and input voltage range.  Humm, sounds like I have to finally read the documentation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: