Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Reading Value from potentiometer

Netduino Plus 2 Visual Studio 2013 4.3.1.0 Potentiometer

  • Please log in to reply
1 reply to this topic

#1 Spammy786

Spammy786

    Member

  • Members
  • PipPip
  • 26 posts

Posted 13 November 2014 - 02:49 PM

Hi Guys

 

I am trying to read the values from my potentiometer. I got it working but the output is not really what I was expecting.

 

Firstly I dont understand the concept of the channels. 

Like for example, you physically connect something to PIN 0, but instead of choosing PIN 0, you have to select Cpu.AnalogChannel.ANALOG_0.

Is there any user friendly documentation on this, but anyways back to my problem.

 

I was using some snippnets from 1 of the posts I found in the netduino forums, basically the guy was just reading values from the potentiometer. I would like to do the same. heres the potentiometer I have

http://netram.co.za/...entiometer.html

 

But this guy was setting a range in his example. (pot.setrange(0,100)) I dont have those options. and I just want round numbers and not decimals. I just want to read values from 0-100 also in my example. Heres my code. I does output the values but it starts like 1 2 3 then back to 1 2 3 and then if you turn it slightly, it jumps all the way to 202. 

 

Only options I have for the AnalogInput is the following and what do they mean ? I have no clue.

Offset
Pin
Presicion (read only)
Read
ReadRaw
Scale
 

 

It basically needs to be refine and optimized. Any ideas

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 NetduinoPotTester
{
    public class Program
    {
        public static void Main()
        {
            AnalogInput pot = new AnalogInput(Cpu.AnalogChannel.ANALOG_0);
            while (true)
            {
                int potValue = 0;
                potValue = pot.ReadRaw();
                Debug.Print(potValue.ToString());
            }
        }

    }
}

Thanks guys.



#2 KiwiDev

KiwiDev

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts
  • LocationNew Zealand

Posted 19 November 2014 - 08:29 AM

Hi

 

How about this, it returns a value between 0 & 100.

 

PrecisionInBits = -1  maximum 

Offset = 0 so values will start from 0.0

Scale = 100 so result will be between 0.0 & 100.0

 

If you wanted say -50 to + 50 

Offset = -50

Scale = 100 

 

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

 

public class Program
{
   public static void Main()
   {
      AnalogInput rotaryAngleSensor = new AnalogInput(Cpu.AnalogChannel.ANALOG_0, 100, 0, -1);

      while (true)
      {

         Debug.Print("Angle " + rotaryAngleSensor.Read().ToString("F1"));

         Thread.Sleep(250);
      }
   }
}

 

Bryn

blog.devmobile.co.nz







Also tagged with one or more of these keywords: Netduino Plus 2, Visual Studio 2013, 4.3.1.0, Potentiometer

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.