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

New to this : Trouble with AnalogInput with Firmware v4.2.0.1


  • Please log in to reply
10 replies to this topic

#1 Jaime Florence

Jaime Florence

    New Member

  • Members
  • Pip
  • 3 posts

Posted 14 November 2012 - 02:55 AM

Hi,

Let me apologize in advance for what is probably a silly question or mistake on my part. I'm brand new at most of this and I'm a bit lost. I did try to do some searching on this forum in hopes of finding my own answers, but most of the topics are way beyond what I'm working on. I'm literally just trying to build the equivelant of "hello world" type stuff and already stuck.

I just recieved my Netduino and begam working through the Getting Started with NetDuino documentation. I noticed that the Netduino had an old Firmware so I went trhough the steps of flashing it and installing the newer SDKs. I built the first Blinky app with the Netduino and all was well.

I built the MakerShild and began making the Blinky app work with that (the LED and button). This worked well too.

Once I started trying to write the code to read the (analog) values from the potentiometer on the MakerShield I started getting debugger errors within MS Visual C# Express.

AnalogInput pot = new AnalogInput(Pins.GPIO_PIN_A0);
I get : "Error 1 The best overloaded method match for 'Microsoft.SPOT.Hardware.AnalogInput.AnalogInput(Microsoft.SPOT.Hardware.Cpu.AnalogChannel)' has some invalid arguments C:\Users\Jaime\documents\visual studio 2010\Projects\Blinky\Blinky\Program.cs 18 31 Blinky"


I noticed that there was a mention of "2. New core AnalogInput and PWM classes; backwards-compatible classes available via add-on assemblies". Does this mean that I need to include something more to be able to use the Pins.GPIO_PIN_A0 above?

I hacked around and was able to get the following to compile:
AnalogInput pot = new AnalogInput(AnalogChannels.ANALOG_PIN_A0)
but that doesn't seem to recieve any values from the potentiometer.

The source is attached.


Any tips would be greatly apreciated.

Thanks,

Jaime

Attached Files



#2 IronMarco

IronMarco

    New Member

  • Members
  • Pip
  • 4 posts

Posted 14 November 2012 - 12:58 PM

I have the same issue!!!

Hi,

Let me apologize in advance for what is probably a silly question or mistake on my part. I'm brand new at most of this and I'm a bit lost. I did try to do some searching on this forum in hopes of finding my own answers, but most of the topics are way beyond what I'm working on. I'm literally just trying to build the equivelant of "hello world" type stuff and already stuck.

I just recieved my Netduino and begam working through the Getting Started with NetDuino documentation. I noticed that the Netduino had an old Firmware so I went trhough the steps of flashing it and installing the newer SDKs. I built the first Blinky app with the Netduino and all was well.

I built the MakerShild and began making the Blinky app work with that (the LED and button). This worked well too.

Once I started trying to write the code to read the (analog) values from the potentiometer on the MakerShield I started getting debugger errors within MS Visual C# Express.

AnalogInput pot = new AnalogInput(Pins.GPIO_PIN_A0);
I get : "Error 1 The best overloaded method match for 'Microsoft.SPOT.Hardware.AnalogInput.AnalogInput(Microsoft.SPOT.Hardware.Cpu.AnalogChannel)' has some invalid arguments C:\Users\Jaime\documents\visual studio 2010\Projects\Blinky\Blinky\Program.cs 18 31 Blinky"


I noticed that there was a mention of "2. New core AnalogInput and PWM classes; backwards-compatible classes available via add-on assemblies". Does this mean that I need to include something more to be able to use the Pins.GPIO_PIN_A0 above?

I hacked around and was able to get the following to compile:
AnalogInput pot = new AnalogInput(AnalogChannels.ANALOG_PIN_A0)
but that doesn't seem to recieve any values from the potentiometer.

The source is attached.


Any tips would be greatly apreciated.

Thanks,

Jaime



#3 Baqs

Baqs

    New Member

  • Members
  • Pip
  • 5 posts

Posted 14 November 2012 - 02:08 PM

Hi Jaime. The problem could be in the method you are using to obtain the analog value. AnalogInputs have two methods to obtain the analog value: Read and RawRead. To use Read you must initialize the offset and scale properties in order to obtain a correct reading, this method returns a double by the way. Try replacing pot.Read() with pot.ReadRaw() which returns an unscaled int. That may solve the issue. Good luck!

#4 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 14 November 2012 - 02:31 PM

you should do pot.Read() * 3.3f to get the voltage you put in. also do Debug.Print("analog value: " + pot.Read * 3.3f); so you know wich value it is. also you are using microsofts analog input class, so you dont use the secretlabs one. rawread returns a value between 0 and 1024 iirc. your "hack around" is the only way. the defines are analogchannels, pwmchannels and normal pins. intellisense will also show you cpu.pins wich you cant use easly, cos they are routed different.

#5 Jaime Florence

Jaime Florence

    New Member

  • Members
  • Pip
  • 3 posts

Posted 14 November 2012 - 06:35 PM

Awesome. Thanks for the help! I'll try the RawRead and/or pot.Read() * 3.3f. Also I'll use Debug.Print to see what I'm getting. I'll post back and let you know how it goes. Thanks, Jaime

#6 Jaime Florence

Jaime Florence

    New Member

  • Members
  • Pip
  • 3 posts

Posted 15 November 2012 - 03:01 AM

Bingo.

NooM and Baqs, you were both right. I ended up using pot.ReadRaw() and AnalogChannels.ANALOG_PIN_A0.


Thanks again for the help! Now I can continue on, and I know more about AnalogChannels, debugging in C# and using MS VC#.



For anyone else that has this, here is the what I used to make the potentiometer on the MakerShield work with the little blinky app:

            OutputPort led = new OutputPort(Pins.GPIO_PIN_D0, false);
            AnalogInput pot = new AnalogInput(AnalogChannels.ANALOG_PIN_A0);

            int potValue = 0;

            while (true)
            {
                //read the value of the potentiometer
                potValue = (int)pot.ReadRaw();
                Debug.Print("ReadRaw analog value: " + pot.ReadRaw());

                // blink the LED based on the pot's value (0-1023ms)
                led.Write(true); // turn on the LED
                Thread.Sleep(potValue); // sleep based on the Pot
                led.Write(false); // turn off the LED
                Thread.Sleep(potValue); // sleep based on the Pot

            }
Sincerely,

Jaime

Edited by Chris Walker, 15 November 2012 - 03:11 AM.
added [code][/code] tags


#7 V64

V64

    Member

  • Members
  • PipPip
  • 20 posts

Posted 07 December 2012 - 05:12 PM

I am trying to use a TMP36 sensor - can anyone help me with the settings I should use for the AnalogInPut scaleFactor and Offset parameters? And what values (and units) the Read and ReadRaw methods return for the correct settings (of those parameters). Thank-you - I find the lack of any semantic explanations of this new Class a little frustrating!!!

#8 carb

carb

    Advanced Member

  • Members
  • PipPipPip
  • 352 posts
  • LocationCrystal River, Florida

Posted 07 December 2012 - 07:29 PM

I am trying to use a TMP36 sensor - can anyone help me with the settings I should use for the AnalogInPut scaleFactor and Offset parameters? And what values (and units) the Read and ReadRaw methods return for the correct settings (of those parameters).

Thank-you - I find the lack of any semantic explanations of this new Class a little frustrating!!!

V64,

Welcome to the forum.

The Read is the easiest to use, it gives you an output of 0.0 to 1.0 that you multiply times 3.3vdc.

The ReadRaw varies depending on the board, ie. the Netduino Go & Plus 2 have 12 bit ADC and read 0 to 4095. The other Netduinos are 10 bit and read 0 to 1023.

As far as the TMP36 this post may help Shieldbase and TMP-36

Also you can search the forum for TMP-36, there are a lot of examples.

Chuck

#9 V64

V64

    Member

  • Members
  • PipPip
  • 20 posts

Posted 07 December 2012 - 08:37 PM

V64,

Welcome to the forum.

The Read is the easiest to use, it gives you an output of 0.0 to 1.0 that you multiply times 3.3vdc.

The ReadRaw varies depending on the board, ie. the Netduino Go & Plus 2 have 12 bit ADC and read 0 to 4095. The other Netduinos are 10 bit and read 0 to 1023.

As far as the TMP36 this post may help Shieldbase and TMP-36

Also you can search the forum for TMP-36, there are a lot of examples.

Chuck


Chuck,

Thank-you for the above - I am using a Netduino.
I understand the bit about the Read and multiply by 3.3 to get the actual volts.
I then did temp = (volts-0.5) *100; And the result looks about right

But how do I get the -0.5 from the TMP-36 datasheet? And why the 100?

I have this problem with all the examples I have found - they give you some device specific magic numbers but I cant work out where they come from!

Also how do these numbers transform into the AnalogInput ScaleFactor and offset parameters?

David

#10 carb

carb

    Advanced Member

  • Members
  • PipPipPip
  • 352 posts
  • LocationCrystal River, Florida

Posted 07 December 2012 - 09:21 PM


I then did temp = (volts-0.5) *100; And the result looks about right

But how do I get the -0.5 from the TMP-36 datasheet? And why the 100?

I have this problem with all the examples I have found - they give you some device specific magic numbers but I cant work out where they come from!

Also how do these numbers transform into the AnalogInput ScaleFactor and offset parameters?

David


The formula is converting the voltage to degrees Centegrade. The TMP36 starts at -50 degrees, and changes .010 volts per degree (10 millivolts). So that when you have 0 volts = -50 degrees, 0.5 volt = 0 degrees and 1.5 volts = 100 degrees. (1000/10=100).

The scalefactor and offset I have not used, I Googled it AnalogInput Class and it appears to allow you to add an offset and a scale factor (could use for calibration) to the ReadRaw method. That is kinda pushing the limits of what I know of C#, if you need a better explaination you may want to try the Chat area, someone may be there that can help.

Chuck

#11 FourT2

FourT2

    Advanced Member

  • Members
  • PipPipPip
  • 63 posts
  • LocationSeattle, WA

Posted 01 August 2014 - 06:12 AM

Here is the code that works on my Netduino Plus 1 with MF 4.2 using TEMP-36

 

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
 
namespace TempMonitor
{
    public class Program
    {
        static AnalogInput tempSensor = new AnalogInput(Cpu.AnalogChannel.ANALOG_1);
        
        public static void Main()
        {            
            while (true)
            {
                double volts = (tempSensor.ReadRaw() / 1024f) * 3.3f;
                double tempC = (volts - 0.5) * 100;
                double tempF = tempC * 9 / 5 + 32;
 
                Debug.Print("Temp C: " + tempC.ToString() + " | Temp F: " + tempF.ToString());                
                Thread.Sleep(10000);
               
            }
        }
 
    }
}
 





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.