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: Sometimes works, sometimes doesn't


  • Please log in to reply
3 replies to this topic

#1 mohammad

mohammad

    Advanced Member

  • Members
  • PipPipPip
  • 79 posts

Posted 08 May 2013 - 09:54 PM

Hi All,   I developed a code to get the temperature readings from TMP36 sensor. My Netduino was working properly. After 5 hours, I started debugging again, but it throwed exceptions (on the line voltagePort = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A1)):

A first chance exception of type 'System.ArgumentException' occurred in Microsoft.SPOT.Hardware.dllAn unhandled exception of type 'System.ArgumentException' occurred in Microsoft.SPOT.Hardware.dll

The code of mine is here:

using System;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.NetduinoPlus;namespace TMPSensor{    public class Sensor:Constants    {        //Microsoft.SPOT.Hardware.AnalogInput voltagePort;        SecretLabs.NETMF.Hardware.AnalogInput voltagePort;        OutputPort lowPort, highPort;        public Sensor()        {            //Temperature sensor           //voltagePort = new AnalogInput(AnalogChannels.ANALOG_PIN_A1);           voltagePort = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A1);           lowPort = new OutputPort(Pins.GPIO_PIN_A0, false);           highPort = new OutputPort(Pins.GPIO_PIN_A2, true);        }        public double read()        {            double rawValue = voltagePort.Read();            double value = (rawValue * maxVoltage) / maxAdcValue;            double result = (((value - 0.5) * 1000) / 10) - 4;            return result;        }    }}

The firmware of my Netduino Plus is 4.2.0.0 (RC5), and the SDK is MicroFrameworkSDK_NETMF42_QFE2. Any help or comment is highly appreciated.   Mohammad



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 08 May 2013 - 10:21 PM

Hi mohammad, My best guess is that your AnalogInput isn't being Disposed of properly--before being created again. If the ADC which backs the AnalogInput is already in use, you'd get an exception. I would recommend implementing IDisposable on your class. And then making sure that you call Sensor.Dispose() in your main application whenever you're done with that AnalogInput. Chris

#3 mohammad

mohammad

    Advanced Member

  • Members
  • PipPipPip
  • 79 posts

Posted 08 May 2013 - 10:29 PM

Hi Chris,

 

Thank you so much for your quick reply, but I didn't understand what I should dispose.

For your information, I deleted that project, and copied and created a new one. The new code worked properly once :) For the second time, it threw the exception. It seems it restores a file or attribute in the project folder.

 

Cheers,

Mohammad



#4 mohammad

mohammad

    Advanced Member

  • Members
  • PipPipPip
  • 79 posts

Posted 08 May 2013 - 10:34 PM

FYI. I copy and paste the code from my notebook to PC. The only diff between my notebook and PC is about the SDK version (I am not sure whether it matters). As long as the code hasn't been changed (e.g. type a character which needs a new software build), the code works properly. Whenever I change the code and build it again, the errors appear.






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.