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

AnalogInput


  • Please log in to reply
14 replies to this topic

#1 Toon

Toon

    New Member

  • Members
  • Pip
  • 7 posts

Posted 14 February 2013 - 05:06 AM

Has anyone recieved an error from trying an AnalogInput command in visual studio 2010 express?

Here is my code, its from an example from the book I purchased.

 

using System.Threading; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware.Netduino; namespace POT_LED {   public class Program   {       public static void Main()   {       OutputPort led = new OutputPort(Pins.GPIO_PIN_D0, false);   AnalogInput pot = new AnalogInput(Pins.GPIO_PIN_A0);   int potValue = 0;   while (true)   {   // read the value of the potentiometer   potValue = pot.Read();   // blink the led based on the potentiometer's value (0-1023ms)   led.Write(true);   Thread.Sleep(potValue);   led.Write(false);   Thread.Sleep(potValue);   }     }   } }  

thanks in advance for any help.



#2 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 14 February 2013 - 08:35 AM

Hi!

 

I beleive that it should work - do you get an exception?

 

1. If so,

1a) what error message do you see?

 1b) what line causes it?

2. if not,

2a) what kind of error is it?

2b) have you measured actual voltage on A0 using a multimeter?

 2c) what value do you see?



#3 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 14 February 2013 - 08:59 AM

i wonder whats the analoginput class your using is.

 

the microsoft one want AnalogChannels.yourpin and not Pins.yourpin.

secretlabs one, i _think_ (never used it) wants it the way you have it.



#4 Toon

Toon

    New Member

  • Members
  • Pip
  • 7 posts

Posted 15 February 2013 - 04:43 AM

Error  1  The best overloaded method match for 'Microsoft.SPOT.Hardware.AnalogInput.AnalogInput(Microsoft.SPOT.Hardware.Cpu.AnalogChannel)' has some invalid arguments  C:Users*****documentsvisual studio 2010ProjectsPOT_LEDPOT_LEDProgram.cs  16  31  POT_LED Error  2  Argument 1: cannot convert from 'Microsoft.SPOT.Hardware.Cpu.Pin' to 'Microsoft.SPOT.Hardware.Cpu.AnalogChannel'  C:Users*****documentsvisual studio 2010ProjectsPOT_LEDPOT_LEDProgram.cs  16  47  POT_LED Error  3  'Microsoft.SPOT.Hardware.AnalogInput' does not contain a definition for 'SetRange' and no extension method 'SetRange' accepting a first argument of type 'Microsoft.SPOT.Hardware.AnalogInput' could be found (are you missing a using directive or an assembly reference?)  C:Users*****documentsvisual studio 2010ProjectsPOT_LEDPOT_LEDProgram.cs  17  17  POT_LED

 

Those are the error messages I recieve, I was using the example in the Getting Started with Netduino.  Are there any better books that you could recommend?  



#5 Toon

Toon

    New Member

  • Members
  • Pip
  • 7 posts

Posted 15 February 2013 - 04:44 AM

Thank you for responding. :)



#6 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 15 February 2013 - 05:59 AM

Could you try replacing this line

AnalogInput pot = new AnalogInput(Pins.GPIO_PIN_A0);

 

with thse two lines instead:

 

var pot = new ADC(Pins.GPIO_PIN_A0);pot.RangeSet(0, 1023);

Does that help?



#7 Toon

Toon

    New Member

  • Members
  • Pip
  • 7 posts

Posted 15 February 2013 - 06:25 AM

Error  1  The type or namespace name 'ADC' could not be found (are you missing a using directive or an assembly reference?)  C:Users*****documentsvisual studio 2010ProjectsPOT_LEDPOT_LEDProgram.cs  16  27  POT_LED

 

That showed up when i input that code.

 

 



#8 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 15 February 2013 - 06:29 AM

hmpf.. i thought what i said was clear..

 

use that:

 

AnalogInput pot = new AnalogInput(AnalogChannels.GPIO_PIN_A0);



#9 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 15 February 2013 - 08:53 AM

Error  1  The type or namespace name 'ADC' could not be found (are you missing a using directive or an assembly reference?)  C:Users*****documentsvisual studio 2010ProjectsPOT_LEDPOT_LEDProgram.cs  16  27  POT_LED

 

That showed up when i input that code.

Weird, I was under the impression that the ADC class resides within the SecretLabs.NETMF.Hardware.Netduino namespace for which you have a using statement in your example code snippet. But realized now that it's actually part of Stefan's toolkit as it's in the Toolbox.NETMF.Hardware.Netduino namespace. Sorry about that.

 

I'm sure NooM's suggestion will work.



#10 Ghunter

Ghunter

    New Member

  • Members
  • Pip
  • 2 posts

Posted 27 February 2013 - 02:33 PM

I had same problem. I found I had to make following changes and it worked.

 

AnalogInput pot = new AnalogInput(AnalogChannels.GPIO_PIN_A0);

 

changed to: AnalogInput pot = new AnalogInput(AnalogChannels.ANALOG_PIN_A1);

 

I figured it out by deleting end of code after AnalogChannels when I put the dot in, the menu gave me the selections.



#11 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 01 March 2013 - 12:19 AM

hanzibal--both the legacy SecretLabs and new NETMF AnalogInput classes are both named "AnalogInput". Toon and Ghunter--if you add the "SecretLabs.NETMF.Hardware.AnalogInput.dll" assembly as a reference to your project, you can use the code samples in the book as-is. Just type "SecretLabs.NETMF.Hardware.AnalogInput" when you create your object instead of just "AnalogInput". Visual Studio needs the full namespace since there are two options :) Welcome to the Netduino community, Chris

#12 DavidAsensio

DavidAsensio

    New Member

  • Members
  • Pip
  • 6 posts

Posted 01 March 2013 - 02:20 PM

I'm new using Netduino,

In the micro specifications the ADC range is 12 bits, but I'm not capable to read more than 10 bits using AnalogInput. 

Anyone can I to do to read the 12 bits?

 

Thanks!



#13 Ghunter

Ghunter

    New Member

  • Members
  • Pip
  • 2 posts

Posted 01 March 2013 - 02:58 PM

Thanks Chris. That solved my problem. I'll have to learn to be carefull about other references that might be missing. I have worked a little with the arduino but the netduino looks exciting with what it can do.

 

Bryan



#14 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 01 March 2013 - 03:26 PM

In the micro specifications the ADC range is 12 bits, but I'm not capable to read more than 10 bits using AnalogInput.

  Netduinos gen 1 have 10-bit ADC, the max raw value is 1023, Netduino/Plus 2 have 12-bit ADC, the max raw value is 4095. If you have Netduino/Plus 2 and you are using the sample code above that includes SetRange(0, 1023) call, you are reading 12-bit value, but scaling it to 1024 range. Delete that SetRange() call to get the full range...

 

Welcome to the community!



#15 DavidAsensio

DavidAsensio

    New Member

  • Members
  • Pip
  • 6 posts

Posted 01 March 2013 - 07:48 PM

  Netduinos gen 1 have 10-bit ADC, the max raw value is 1023, Netduino/Plus 2 have 12-bit ADC, the max raw value is 4095. If you have Netduino/Plus 2 and you are using the sample code above that includes SetRange(0, 1023) call, you are reading 12-bit value, but scaling it to 1024 range. Delete that SetRange() call to get the full range...

 

Welcome to the community!

Thanks CW2

But I'm not using the SetRange, please can you send me a little example?

Thanks a lot!






1 user(s) are reading this topic

0 members, 1 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.