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

Issue with resolving AnalogInput


  • Please log in to reply
7 replies to this topic

#1 Don King

Don King

    Advanced Member

  • Members
  • PipPipPip
  • 30 posts
  • LocationLawrence, KS

Posted 29 August 2012 - 11:48 PM

I hope this is the right place to post this. Please let me know otherwise.

I am a .NET Developer but a newbie to micro-controllers and electronics. I have been going through the samples and reading through two books, one of which is Getting Started with the Internet of Things. I am sure that others here are familiar with this. The code below has an issue that I cannot seem to get resolved. When I search the forum I see it mentioned but it seems to be pre release of .NETMF 4.2. The issue is marked below with a comment. I cannot get the 'AnalogInput' class to resolve except through the Microsoft.SPOT.Hardware namespace at which time it wants a type of Cpu.AnalogChannel as an argument. I have tried 'Cpu.AnalogChannel.ANALOG_1' as the argument for this code but it does not work. I am somewhat lost.

I have connected a potentiometer to the Analog In (Pins 0, 1 and 2) but when I run the application the voltage always reads out as 0.00 so either I don't have it hooked up correctly or my code is wrong. I am guessing the latter.

I have seen previous postings where it is mentioned that you should use 'SecretLabs.NETMF.Hardware.AnalogInput' but I am not seeing that class exist. I do notice however that if I use:

var voltagePort = new Microsoft.SPOT.Hardware.AnalogInput(Cpu.AnalogChannel.ANALOG_0);

and then try to declare:

var lowPort = new OutputPort(Pins.GPIO_PIN_A0, false);

I get an error as if the first declaration took the resource on the board and is having a conflict. That makes me think that my code is actually correct and I don't know what I am doing with the potentiometer (that is highly likely).

Below is my current code taken from the book with my mods:

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

public class VoltageReader
{
    public static void Main()
    {
        const double maxVoltage = 3.3;
        const int maxAdcValue = 1023;

        //var voltagePort = new AnalogInput(Pins.GPIO_PIN_A1); //THIS HAS AN ISSUE RESOLVING
        var voltagePort = new Microsoft.SPOT.Hardware.AnalogInput(Cpu.AnalogChannel.ANALOG_1); //REPLACED LINE WITH THIS
        var lowPort = new OutputPort(Pins.GPIO_PIN_A0, false);
        var highPort = new OutputPort(Pins.GPIO_PIN_A2, true);

        while (true)
        {
            int rawValue = voltagePort.Read();
            double value = (rawValue * maxVoltage) / maxAdcValue;
            Debug.Print(rawValue + "  " + value.ToString("f"));
            Thread.Sleep(3000);                     // 3 seconds
        }
    }
}
Any help is appreciate to point me in the right direction.

Thanks!

Don

Edited by Chris Walker, 30 August 2012 - 01:27 AM.
added [code] tags


#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 30 August 2012 - 01:29 AM

Hi Don, Did you upgrade your Netduino Plus to .NET Micro Framework 4.2? If so, then add SecretLabs.NETMF.Hardware.AnalogInput.dll as a reference to your project. If not, then you'll want to change the target framework for your application to .NET MF 4.1 in your project properties. Does this resolve the issue for you? We're here to help. Chris

#3 Don King

Don King

    Advanced Member

  • Members
  • PipPipPip
  • 30 posts
  • LocationLawrence, KS

Posted 30 August 2012 - 01:43 AM

Hi Don,

Did you upgrade your Netduino Plus to .NET Micro Framework 4.2?

If so, then add SecretLabs.NETMF.Hardware.AnalogInput.dll as a reference to your project.

If not, then you'll want to change the target framework for your application to .NET MF 4.1 in your project properties.

Does this resolve the issue for you? We're here to help.

Chris


That did it! I am at .NETMF 4.2. I added the missing reference and now it works with fully qualfied reference.

var voltagePort = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A1);

Thanks much for your help!

Don

#4 Nym

Nym

    Member

  • Members
  • PipPip
  • 20 posts

Posted 08 February 2013 - 09:49 PM

Chris I'm a little bit confuse here, if I'm using Netduino but upgraded board to framework 4.2, I should be using the declaration as:

 

AnalogInput solarSensor = new AnalogInput(Cpu.AnalogChannel.ANALOG_2) // From Microsoft.SPOT.Hardware

 

or

 

[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]var [/color]solarSensor[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]= new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A1); // From Secret lab[/color]

 

[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]Which one is the correct version for reading through Analog Input and Why?[/color]

 

[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]Thanks in advance[/color]



#5 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 08 February 2013 - 10:52 PM

its not Cpu.AnalogChannel.ANALOG_2 - its AnalogChannels.Yourpin

- netduino has a definition for that. in: sl.hardware.yournetduino



#6 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 09 February 2013 - 01:47 AM

Hi Nym, The legacy SecretLabs.NETMF.Hardware.AnalogInput class uses the new Microsoft.SPOT.Hardware.AnalogInput class behind the scenes. So you're good to go with either. I would recommend using the new one because it offers a floating point result that's easy to use into calculations. Also, NooM is correct: you will want to use AnalogChannels.ANALOG_PIN_A1, rather than Cpu.AnalogChannel.ANALOG_2. They're technically identical on Netduino Plus 2--but using "AnalogChannels." will help provide cross-board compatibility. Chris

#7 laurentiss

laurentiss

    New Member

  • Members
  • Pip
  • 8 posts
  • LocationGrenoble France

Posted 12 February 2013 - 11:50 AM

I have the same problem...

The application was OK on NetduinoPlus 1, but crashes with NetDuinoPlus2.

I use Framework 4.2.2, I tried what you describe.  Could you please give us 2 or 3 lines of C# sample code ?

Without AnalogInput, everything is OK, like Input and output Ports.

 

THANKS



#8 Michael E

Michael E

    New Member

  • Members
  • Pip
  • 8 posts
  • LocationCanada

Posted 06 June 2013 - 10:40 PM

I just had this problem and thanks to everyone here I solved it by adding [color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]SecretLabs.NETMF.Hardware.AnalogInput.dll to my references but found using the fully qualified namespace each time I wanted to use SecretLabs AnalogInput I added the following to the using section[/color]

using AnalogInput = SecretLabs.NETMF.Hardware.AnalogInput;

this way I can use AnalogInput like so:

AnalogInput pot = new AnalogInput(Pins.GPIO_PIN_A0);

Without the compiler errors and warnings.

 

Hope this helps anyone reading this thread.


I have not failed. I've just found 10,000 ways that won't work.
? Thomas A. Edison





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.