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

Problem with Analog Input


  • Please log in to reply
5 replies to this topic

#1 Acumen

Acumen

    New Member

  • Members
  • Pip
  • 7 posts

Posted 18 August 2010 - 03:51 AM

Just got my netduino, trying to figure this thing out.

I get the following output by simply jumping any analog input to ground:

Test: 127
Test: 15
Test: 1023
Test: 1023
Test: 255
Test: 1023
Test: 0
Test: 127
Test: 255
Test: 1023
Test: 127
Test: 0
Test: 0
Test: 255
Test: 63
Test: 0
Test: 255
Test: 1023
Test: 63
Test: 127
Test: 63
Test: 255
Test: 0
Test: 255
Test: 127
Test: 7
Test: 63

namespace Netduino_Test_1
{
    public class Program
    {
        public static void Main()
        {
            // write your code here

            AnalogInput apin0 = new AnalogInput(Pins.GPIO_PIN_A0);

            bool buttonstate = false;
            int test = 0;
            while (true)
            {
                Thread.Sleep(250);
                test = apin0.Read();
                Debug.Print("Test: " + test);
            }

        }

    }
}


#2 RuggedCircuits

RuggedCircuits

    Member

  • Members
  • PipPip
  • 17 posts

Posted 18 August 2010 - 03:58 AM

The Netduino does not have a default analog voltage reference (AREF). This pin is floating and there is no internal voltage reference. Try connecting a wire from the 3.3V pin to the AREF pin and try again.
Rugged Circuits LLC / <http://ruggedcircuits.com>

#3 Acumen

Acumen

    New Member

  • Members
  • Pip
  • 7 posts

Posted 18 August 2010 - 04:25 AM

Ah there we go. Thank you.

Fun little variable speed blinking program to test the analog input.

Potentiometer hooked up to 3V, Ground and A0.
3V hooked up to Aref.

namespace Netduino_Test_1
{
    public class Program
    {
        public static void Main()
        {
            AnalogInput apin0 = new AnalogInput(Pins.GPIO_PIN_A0);
            OutputPort led = new OutputPort(Pins.ONBOARD_LED, true);
            int test = 0;
            bool ledstate = true;

            while (true)
            {
                ledstate = !ledstate;

                led.Write(ledstate);

                test = apin0.Read();
                Debug.Print("Test: " + test); 

                Thread.Sleep(test/5);
            }

        }

    }
}


#4 SkippyFiRe

SkippyFiRe

    Member

  • Members
  • PipPip
  • 14 posts
  • LocationMA, USA

Posted 28 September 2010 - 02:34 AM

I tried the code above, but the analog pin A0 always read 1023. I also tried to hook up a photoresistor via the instructions in this tutorial, but it still read the same 1023 all the time: http://www.ladyada.n...ensors/cds.html (It is meant for the Arduino, but the hardware is more or less the same and from the looks of the code, that should be roughly the same too.) My wife helped me verify that everything looked good on the hardware side. The voltage was changing because of the photoresistor, and the photoresistor by itself even changed resistance with the multimeter. But the Analog Pins always read 1023!!! Is there something I'm missing? I saw somewhere that the analog pins can do digital out too... do I need to set what the pin is supposed to be doing? Or is it something else? Thanks in advance, SkippyFiRe.
- SkippyFiRe

#5 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 28 September 2010 - 02:41 AM

Is there something I'm missing? I saw somewhere that the analog pins can do digital out too... do I need to set what the pin is supposed to be doing? Or is it something else?


SkippyFiRe...are you also hooking up your 3.3V header to the AREF header as well?

You should have 3.3V and GND connected to your sensor, 3.3V connected to the AREF header, and your sensor's "analog output" connected to pin A0.

Chris

#6 SkippyFiRe

SkippyFiRe

    Member

  • Members
  • PipPip
  • 14 posts
  • LocationMA, USA

Posted 29 September 2010 - 11:54 AM

Thanks Chris! This worked beautifully. I guess this this another thing you just have to know! I now have an LED's brightness controlled by the amount of ambient light in the room. Awesome, I love it!
- SkippyFiRe




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.