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

Getting Started with Netduino error in Chapter 5


Best Answer Chris Walker, 04 February 2013 - 06:51 PM

Hi Trevor, The new AnalogInput constructor has an overload with offset and scale properties. You can use those to set the scale. It uses the opposite method that our AnalogInput.SetRange method used...but it's not hard to get used to. Chris Go to the full post


  • Please log in to reply
4 replies to this topic

#1 typcs

typcs

    New Member

  • Members
  • Pip
  • 2 posts

Posted 04 February 2013 - 04:49 AM

Using the Net MF 4.2 and Netduino Plus 2 I'm having a problem with the pot experiment in the Getting Started book. The code line [color=rgb(43,145,175);]AnalogInput[/color] pot = [color=#0000FF;]new[/color] [color=rgb(43,145,175);]AnalogInput[/color]([color=rgb(43,145,175);]Pins[/color].GPIO_PIN_A0); gives me an error in VS2010 C# of invalid arguments. As a newbie not sure how to get around this. .
 



#2 MarkNic

MarkNic

    Member

  • Members
  • PipPip
  • 22 posts

Posted 04 February 2013 - 02:41 PM

With the newer frameworks for Netduino I believe they have changed the types for the digital and analog ports that don't match the book anymore.  In this case the AnalogInput parameters are looking for "AnalogChannel" values such as Cpu.AnalogChannel.ANALOG_0.  To see the list of possible values, delete the parameter portion of the call including the parens "(".  The type a open-paren, VS IntelliSense should show you a list of enumerated values that you can use.  Just match up the channel number with what it says in the book.

 

HTH



#3 Gutworks

Gutworks

    Advanced Member

  • Members
  • PipPipPip
  • 363 posts
  • LocationOttawa, Ontario

Posted 04 February 2013 - 04:31 PM

Hi typcs,

 

Welcome to the community! I loved the Getting Started with Netduino book, and it really gave me a good primer and helped me as someone who had little prior knowledge of microcontrollers and the C# language. Since the book's publication there have been several changes to the .Net Micro Framework, and as a result some of the sections in the book require slight modifications in order for the samples to work. The samples use the Secret Labs AnalogInput and PWM classes, and since the books release, Microsoft has added new PWM and AnalaoInput classes to NETMF 4.2. The good news is that the code will still work but you need to strictly define the classes namespace to avoid conflict with the MS classes.

 

To do so you will need to add the SecretLabs.NETMF.Hardware.AnalogInput assembly file to your project. To do this you simply:

  • Right click on "Reference" in the Solution Explorer within Visual Studio, generally located to the far right of your screen. 
  • Select "Add Reference"
  • In the .Net Applications tab find and add the SecretLabs.NETMF.Hardware.AnalogInput assembly file. 

Now in your code you need to make sure you fully define the namespace and class name like so:

SecretLabs.NETMF.Hardware.AnalogInput pot = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A0);

 

After doing this, your project should run perfectly. Once you have mastered the samples in the book you can try the Microsoft's AnalogInput and PWM classes, which you will see used often in more recent code samples. They have slightly different constructors, and accept different arguments when you create a new instance of them. There are a few examples found in our forums when you're ready to give it a shot. 

 

Happy hacking and if you have any other questions feel free to post them here in the forum. 

 

Cheers,

Steve



#4 typcs

typcs

    New Member

  • Members
  • Pip
  • 2 posts

Posted 04 February 2013 - 06:24 PM

Thanks to both of you for the help. I went ahead and used the new MF syntax as HTH proposed. I noticed also that AnalogInput.SetRange is no longer available (without, I suppose, using Steve's method of adding a new Reference). I experimented with .Scale and that worked for changing the speed of LED blinking. Is there an equivalent that works like .SetRange where you can determine the beginning and end?

Thanks again,

Trevor  



#5 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 04 February 2013 - 06:51 PM   Best Answer

Hi Trevor, The new AnalogInput constructor has an overload with offset and scale properties. You can use those to set the scale. It uses the opposite method that our AnalogInput.SetRange method used...but it's not hard to get used to. Chris




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.