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 using AnalogInput


  • Please log in to reply
9 replies to this topic

#1 FVN.Net

FVN.Net

    Member

  • Members
  • PipPip
  • 15 posts
  • LocationCentral Belgium, EU

Posted 19 September 2012 - 07:52 PM

Hello to all

For the first time I try to use an analog input on my N+ with latest firmware.

I tried the obvious:

Dim potMeter As New AnalogInput(Pins.GPIO_PIN_A0)
but this gave me:
Option Strict On disallows implicit conversions from 'Microsoft.SPOT.Hardware.Cpu.Pin' to 'Microsoft.SPOT.Hardware.Cpu.AnalogChannel'.

This link told me to use this line of VB code:
Dim potMeter As New Microsoft.SPOT.Hardware.AnalogInput(Cpu.AnalogChannel.ANALOG_0)
or
Dim potMeter As New SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A0)
results in this error:
An unhandled exception of type 'System.ArgumentException' occurred in Microsoft.SPOT.Hardware.dll

So I can't even run my code, it breaks when initialising the analog input.
What am I doing wrong? What am I overlooking? All help appreciated. Thanks already.

#2 Kem

Kem

    Member

  • Members
  • PipPip
  • 17 posts

Posted 19 September 2012 - 09:30 PM

Hi there,

When using the AnalogInput from Microsoft.Spot.Hardware you have to use a Cpu.AnalogChannel, not a Cpu.Pin.

So to map to the Analog Pins of your Netduino you use SecretLabs.NETMF.Hardware.NetduinoPlus.AnalogChannels.ANALOG_PIN_A0.

Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware.NetduinoPlus

Dim potMeter As New AnalogInput(AnalogChannels.ANALOG_PIN_A0)

I just typed the code in here, so forgive me if I made typos :unsure: .

Regards,

Kem

#3 FVN.Net

FVN.Net

    Member

  • Members
  • PipPip
  • 15 posts
  • LocationCentral Belgium, EU

Posted 20 September 2012 - 10:20 AM

Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware.NetduinoPlus

Dim potMeter As New AnalogInput(AnalogChannels.ANALOG_PIN_A0)


Thanks Kem, but I still get an error when trying to execute the code. The code breaks on that line.

- Franki

#4 Kem

Kem

    Member

  • Members
  • PipPip
  • 17 posts

Posted 20 September 2012 - 11:50 AM

Hi Franki,

Make sure you have added references to Microsoft.Spot.Hardware and SecretLabs.NETMF.Hardware.NetduinoPlus.

This code works just fine for me:

Option Explicit On
Option Strict On

Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware.NetduinoPlus


Namespace VBMicroTest

    Public Module Module1

        Sub Main()
            Dim potMeter As New AnalogInput(AnalogChannels.ANALOG_PIN_A0)

            Debug.Print("Value: " + potMeter.Read().ToString())
        End Sub

    End Module

End Namespace

Regards,

Kem

#5 FVN.Net

FVN.Net

    Member

  • Members
  • PipPip
  • 15 posts
  • LocationCentral Belgium, EU

Posted 20 September 2012 - 04:31 PM

Too bad Kem, still the same problem:

Imports Microsoft.SPOT
Imports Microsoft.SPOT.IO
Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware
Imports SecretLabs.NETMF.Hardware.NetduinoPlus
Imports System.IO

Module Module1
    Sub Main()
        Dim potMeter As New Microsoft.SPOT.Hardware.AnalogInput(AnalogChannels.ANALOG_PIN_A0)
        For i As Integer = 1 To 50
            Debug.Print("Value: " & potMeter.Read().ToString())
        Next
    End Sub
End Module

results in: "A first chance exception of type 'System.ArgumentException' occurred in Microsoft.SPOT.Hardware.dll"

If I change the line of code to
Dim potMeter As New AnalogInput(AnalogChannels.ANALOG_PIN_A0)
I get:
" 'AnalogInput' is ambiguous, imported from the namespaces or types 'SecretLabs.NETMF.Hardware, Microsoft.SPOT.Hardware'. "

The project references show version 4.2.0.1 only for SecretLabs.NETMF.Hardware.NetduinoPlus and SecretLabs.NETMF.Hardware.AnalogInput, yet 4.2.0.0 for ALL other DLLs including SecretLabs.NETMF.Hardware.

I have no clue how to get this simple thing going...
- Franki

#6 Kem

Kem

    Member

  • Members
  • PipPip
  • 17 posts

Posted 20 September 2012 - 05:25 PM

Ah, please remove the reference to SecretLabs.NETMF.Hardware.AnalogInput that one is for backwards compatibility and conflicts with the Microsoft.SPOT.Hardware.AnalogInput. Kem

#7 FVN.Net

FVN.Net

    Member

  • Members
  • PipPip
  • 15 posts
  • LocationCentral Belgium, EU

Posted 20 September 2012 - 06:05 PM

Dear Kem, I really appreciate your time and effort, but all your hints don't work for me (so far).
I opened a totally new solution from scratch. Even one single line of code causes the program to break:

Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware
Imports SecretLabs.NETMF.Hardware.NetduinoPlus

Module Module1
    Sub Main()
        ' write your code here
        Dim potMeter As New AnalogInput(AnalogChannels.ANALOG_PIN_A1)
    End Sub
End Module

An attached PNG shows my references.
I just don't get it, it's always 'An unhandled exception of type 'System.ArgumentException' occurred in Microsoft.SPOT.Hardware.dll'and the execution breaks.

I wrote a button-lights-led program that works so it's really the AnalogInput part that bothers me.

- Franki

Attached Files



#8 Kem

Kem

    Member

  • Members
  • PipPip
  • 17 posts

Posted 20 September 2012 - 07:10 PM

Hi Franki,

believe me, I'm trying my best to help you :). I'll try to explain in detail how it should work.

There are two AnalogIn classes, one of Microsoft (Microsoft.SPOT.Hardware.AnalogInput) and one of SecretLabs (SecretLabs.NETMF.Hardware.AnalogInput). In the last code you gave, you import both of these namespaces, you now can not use AnalogIn without specifying it's full name. Otherwise the compiler does not know which class to use (ambiguous).

I am using the one supplied by Microsoft, for this you only need references to the following:

Microsoft.SPOT.Hardware (4.2.0.0)
Microsoft.SPOT.Native (4.2.0.0)
mscrorlib (4.2.0.0)
SecretLabs.NETMF.Hardware.NetduinoPlus ((4.2.0.1)

I made a small program with nothing more than the code as shown below. Just to make sure that there are no conflicts in imports, I used the full names of the classes:

AanalogIn > Microsoft.SPOT.Hardware.AnalogInput
ANALOG_PIN_A0 > SecretLabs.NETMF.Hardware.NetduinoPlus.AnalogChannels.ANALOG_PIN_A0

The AnalogIn class contains the functionality of sampling an analog input. But Microsoft does not know anything about the Netduino Plus. Therefor SecretLabs made a nice little class to map the Netduino's PINs to the ones expected by the AnalogIn class.

The code:

Option Explicit On
Option Strict On

Imports Microsoft.SPOT

Namespace MFConsoleApplication1
    Public Module Module1
        Sub Main()
            Dim potMeter As New Microsoft.SPOT.Hardware.AnalogInput(SecretLabs.NETMF.Hardware.NetduinoPlus.AnalogChannels.ANALOG_PIN_A0)
            For i As Integer = 1 To 50
                Debug.Print("Value: " & potMeter.Read().ToString())
            Next
        End Sub
    End Module
End Namespace

A few lines of the debug output:

Value: 0.0019550342130987292
Value: 0.015640273704789834
Value: 0.016617790811339198
Value: 0.00097751710654936461
Value: 0.0019550342130987292
Value: 0.01466275659824047
Value: 0.016617790811339198


O one last thing I can think of, do you have firmware 4.2 on your Netduino? The one's I just bought arrived with firmware 4.1 on it.

Hope this helps!

Regards,

Kem

OK, scratch that about the firmware, you've said that already in your first post :)

Edited by Kem, 20 September 2012 - 07:13 PM.


#9 FVN.Net

FVN.Net

    Member

  • Members
  • PipPip
  • 15 posts
  • LocationCentral Belgium, EU

Posted 20 September 2012 - 08:30 PM

Kem, PROBLEM SOLVED!

I just installed 'Version: 4.2.0 Update 1 (version 4.2.0.1)' of the firmware, I was still running 'NetduinoPlus_4.2.0.0_RC5' which I believed to be the most recent but it turned out Chris W published an update note yesterday. My bad! :huh:

My led is now blinking to the value of the potmeter. Finally!

Is there an online document or resource where I can get an overview of the most used classes for I/O (RS-232, I2C, SPI, PWM etc)? I'd love to learn more without having to ask too many questions, like I try to solve my Win Forms programming problems.

Thanks again for all your help!
- Franki

#10 mohammad

mohammad

    Advanced Member

  • Members
  • PipPipPip
  • 79 posts

Posted 09 May 2013 - 12:23 AM

Hi FVN.Net,

 

I exactly have the same problem. Could you solve the problem? I followed this post and tried everything Kem said (Thanks Kem), but all failed.

I really appreciate if you help me solve it.

 

Thanks,

Mohammad






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.