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

Analog input problem

Netduino Plus 2

  • Please log in to reply
7 replies to this topic

#1 caEstrada

caEstrada

    Advanced Member

  • Members
  • PipPipPip
  • 84 posts

Posted 18 June 2014 - 03:52 PM

Hi there,

 

I just bought some Netduino Plus 2, firmware 4.2, works well with VS2010.

 

Question:  what is wrong with this

 

AnalogInput input = new AnalogInput(AnalogChannels.ANALOG_PIN_A0)

 

I am trying to read a voltage in the range 0-3.3VDC at A0...

 

The VS2010 compiler says:

 

Error    2    The best overloaded method match for 'SecretLabs.NETMF.Hardware.AnalogInput.AnalogInput(Microsoft.SPOT.Hardware.Cpu.Pin)' has some invalid arguments    C:\Users\caestradalaptop\Documents\Visual Studio 2010\Projects\ceCSharpNetduinoPlus2\ceCSharpNetduinoPlus2\Program.cs    23    21    ceCSharpNetduinoPlus2

 

Also, it is supposed I can jump the pin 3V3 to A0 and see 4095 counts, right?
 

 

Suggestions?  Thanks in advance!

 

 

 

 



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 21 June 2014 - 09:29 PM

Hi caEstrada,

If you're using the SecretLabs.NETMF.Hardware.AnalogInput class, you'll want to pass in Pins.GPIO_PIN_A0.

If you're using the replacement Microsoft.SPOT.Hardware.AnalogInput class, you'll want to use the AnalogChannel as you have done.

Try adding "Microsoft.SPOT.Hardware." in front of "AnalogInput" in your constructor. Does that help?

And yes...if you connect 3V3 to A0 and call ReadRaw() you should get ~4095.

Chris

#3 PhilP

PhilP

    New Member

  • Members
  • Pip
  • 5 posts
  • LocationIndianapolis

Posted 21 July 2015 - 03:04 PM

Follow on question:

 

Using the .Netduino 3 Plus Wifi, have a 10k pot connected to +5, Gnd and the wiper connected to Analog pin 0.

 

Creating the object, the first statement below using AnalogInput works fine.  It shows three overloads, if I use the second line instead, the program compiles without issue, but when executing, the program fails with an System.Argument exception.

 

static AnalogInput my_Pot = new AnalogInput(AnalogChannels.ANALOG_PIN_A0);  // works just fine

static AnalogInput my_Pot = new AnalogInput(AnalogChannels.ANALOG_PIN_A0, 0.195, 0, 8);  // compiles OK, will not run.
 
Any thoughts? 
 
Thanks


#4 scardinale

scardinale

    Member

  • Members
  • PipPip
  • 27 posts
  • LocationNew York, USA

Posted 22 July 2015 - 01:16 AM

public AnalogInput(
	Cpu.AnalogChannel channel,
	double scale,
	double offset,
	int precisionInBits
)

More than likely, you are setting the precision bits to a value that is not supported by the hardware.



#5 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 22 July 2015 - 01:33 AM

Hi PhilP,

As scardinale surmised...if you specify the precisionInBits, it should match the ADC. The ADCs on Netduino 3 Wi-Fi are higher resolution (12-bit), so swap in 12 instead of 8 and you should be good to go.

You can always do a ReadRaw and then bit-shift 4 bits (>> 4) if you want to get rid of some resolution.

Does that get you moving in the right direction?

Chris

#6 PhilP

PhilP

    New Member

  • Members
  • Pip
  • 5 posts
  • LocationIndianapolis

Posted 22 July 2015 - 01:58 AM

Excellent. Thank you very much.

#7 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 22 July 2015 - 06:28 AM

I think the analog channel should have a maximum of 3.3V and you have stated you are connecting to 5V.

 

Regards,

Mark


To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#8 PhilP

PhilP

    New Member

  • Members
  • Pip
  • 5 posts
  • LocationIndianapolis

Posted 22 July 2015 - 10:23 AM

Mark:

Good catch.  Thanks for the heads up.  I moved the input lead and changed the 8 to 12 and life is good!

 

Phil







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.