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 hardware error


  • Please log in to reply
7 replies to this topic

#1 GDSever

GDSever

    Advanced Member

  • Members
  • PipPipPip
  • 81 posts
  • LocationNewark, DE

Posted 11 December 2010 - 01:18 AM

For some reason I am just having issues galore this week. In an effort to try to figure out why my I2C communications aren't working anymore, I went back to just about the simplest circuit I could think of - a LM34 analog temperature sensor to A4 and A5. When I try to instantiate an AnalogInput, it throws a hardware error at me that I can't seem to figure out. I then thought maybe I should try pins A0 and A1. Same problem. See the screenshot below. Any clues out there what might cause this? I haven't had this problem before, and some searches didn't turn up anything...

Attached Files



#2 bill.french

bill.french

    Advanced Member

  • Members
  • PipPipPip
  • 260 posts
  • LocationPrinceton, NJ

Posted 11 December 2010 - 01:58 AM

Can you post the rest of that code block? If you click break, does it give you a more explicit error?

#3 GDSever

GDSever

    Advanced Member

  • Members
  • PipPipPip
  • 81 posts
  • LocationNewark, DE

Posted 11 December 2010 - 02:03 AM

Can you post the rest of that code block? If you click break, does it give you a more explicit error?

Pretty much the screenshot has everything, but I've included all of Program.cs below... I'm not sure it's going to tell you much.

Attached Files



#4 bill.french

bill.french

    Advanced Member

  • Members
  • PipPipPip
  • 260 posts
  • LocationPrinceton, NJ

Posted 11 December 2010 - 02:11 AM

hmm, seems like the analogpin isn't getting released properly, would be my guess? Something to do with ReadLM34 being static?

Maybe try something like this:

instead of:
AnalogInput analogPin = new AnalogInput(inputPin);
try:

using(AnalogIntput analogPin = new AnalogInput(inputPin))
{
...your other code...
}

... but then again analog input might not be idisposable, so this might not help.

I'm about to jump onto my other computer and can try it out myself.

#5 bill.french

bill.french

    Advanced Member

  • Members
  • PipPipPip
  • 260 posts
  • LocationPrinceton, NJ

Posted 11 December 2010 - 03:52 AM

This worked for me -- note the .Dispose() towards the end; the "using" i suggested earlier might not work because of AnalogInput not being IDisposable

public static double ReadLM34(Cpu.Pin inputPin)
        {
            // Reads an LM34 analog temperature sensor several times and converts the 
            // Code example for potentiometer at:
            //  http://forums.netduino.com/index.php?/topic/638-basic-analog-input-circuit-and-program/

            int vRef = 3300;        // 3300 mV, or 3.3V
            int readingTot = 0;     // Summed total of the iterations
            int numReads = 10;      // Number of times to take a reading
            double tempF = 0.0;     //

            AnalogInput analogPin = new AnalogInput(inputPin);

            // Take a number of readings and average them together to get the final 
            //  temperature calculation

            for (int i = 0; i < numReads; i++)
            {
                readingTot += analogPin.Read();
            }
            tempF = (readingTot / numReads) / 1024 * vRef / 10;

            analogPin.Dispose();
            
            return tempF;
        }


#6 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 11 December 2010 - 04:10 AM

GDSever, Do you have any more details on the exception? Also--you are running on the Netduino and not in an emulator correct? Chris

#7 GDSever

GDSever

    Advanced Member

  • Members
  • PipPipPip
  • 81 posts
  • LocationNewark, DE

Posted 11 December 2010 - 11:51 AM

It was the missing .Dispose() that was causing the error. I should have stepped thru the code. I would have noticed the second iteration is when the error was being thrown, not the first. Same thing happened the first time I used the I2CDevice class a while back. Of course now I've got the problem that I suspected, and I'm not sure what to do. All of my AnalogInput readings are coming back as zero - regardless of what pins I try to measure them on. I added a SetRange(0, 1023) to the subroutine, made sure that Aref is connected to 3.3V... Is it possible the analog pin bank is "blown" or something? If that were the case, it'd also explain why my I2C communications stopped working as well... although not what the root cause was. Any recovery from a "blown" pin (or pins)?

Attached Files



#8 GDSever

GDSever

    Advanced Member

  • Members
  • PipPipPip
  • 81 posts
  • LocationNewark, DE

Posted 11 December 2010 - 12:00 PM

Never mind. I had a math error that was dividing an int into another int, resulting in zero. Amazing how sometimes you get into the thick of things and you can't see the forest thru the trees. Thanks for all your help. Now I can get back to figuring out why my I2C communications have all seemed to stop.




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.