Unhanedled Exeptions! while trying to read a very simple analog input

Hi all,

I am beginner with my board, FEZ Cerbuino Bee, Firmware 4.2, VS2010, (QEF2) 4.2

The code is exactly from the tutorial for analog input:

Unfortunatily I had these exception:
An unhandled exception of type ‘System.Exception’ occurred in Microsoft.SPOT.Hardware.dll
An unhandled exception of type ‘System.ArgumentException’ occurred in Microsoft.SPOT.Hardware.dll

I’ve tried to modify the following:
from to
using GHI.Premium.Hardware; => using GHI.OSHW.Hardware;

but the same exceptions are still there!

Any idea great FEZers :S

@ PetaByte - What pins are you connecting it to?

@ Justin Hi dear, no pins are connected to anything till now.

Thnx for your quick reply :slight_smile:

both ways - Gadgeteer socket or Headers…

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;

namespace AnlaogTest
    public partial class Program
        private Gadgeteer.Interfaces.AnalogInput _magicalPressureSensor; //Gadgeteer
        private GT.Socket _magicalPressureSensoreSocket;
        private GT.Timer _timer;
        private double _magicalPressureSensorValue;
        private double _magicalPressureSensorValue2;

        private Microsoft.SPOT.Hardware.AnalogInput inputPin; //netmf
        void ProgramStarted()
            inputPin = new AnalogInput(GHI.OSHW.Hardware.FEZCerbuino.Pin.AnalogIn.A0);

            _magicalPressureSensoreSocket = GT.Socket.GetSocket(9, true, null, null);
            _magicalPressureSensor = new GT.Interfaces.AnalogInput(_magicalPressureSensoreSocket, GT.Socket.Pin.Five, null);
            _timer = new GT.Timer(1000);
            _timer.Tick += new GT.Timer.TickEventHandler(TimerTick);

        void TimerTick(GT.Timer timer)
            _magicalPressureSensorValue = _magicalPressureSensor.ReadVoltage();
            _magicalPressureSensorValue2 = inputPin.Read();

1 Like

The code seems nice and simple, but with a simple error :S

Thnx again dear Justin

All Errors are saying:
The type or namespace name ‘Gadgeteer’ could not be found (are you missing a using directive or an assembly reference?)

@ PetaByte - Have you created a Gadgeteer project or plain NetMF?

Either create a Gadgeteer project or add a preference to the Gadgeteer.dll

oops just looked at the image - if your using a bee just create a Gadgeteer project

I was following the tutorials which were using NetMF Consoles, and I will be happy if I find tutorials for Gadgeteer projects

I’ll try your code with a Gadgeteer project now :slight_smile:

Well, since I am not familiar with Gadgeteer Apps, I got this Errs :frowning:

I solved the first one by modifying it to be from:
Mainboard = new GHIElectronics.Gadgeteer.FEZCerbuinoBee();
Mainboard = new GHIElectronics.Gadgeteer.FEZCerberus();
but the second one is still there!!

It seems that Gadgeteer is a cool GUI tool, but actually I need the simplest analog reading.

I also was trying to modify my code (NetMF Console) by replacing my initialization:
new AnalogInput((Cpu.AnalogChannel)Cpu.AnalogChannel.ANALOG_7, 3.3,0.0,10);
with yours:
new AnalogInput(GHI.OSHW.Hardware.FEZCerbuino.Pin.AnalogIn.A0);

and there was no errors but the same exceptions appeared!!

I can’t believe that I spent all this time just to read analog input

Thnx Justin for your support, I appreciate this…

@ PetaByte - Are you using a Cerberus or Cerbuino?

Your code looks fine. There is a class in OSHW libs that enumerates the cerbuino pins IIRC. I am in a phone now so not easy to check.

oops, it seems that I was refreshing the first page waiting for the replies while they are here :stuck_out_tongue:

@ Justin yea dear it’s Cerbuino

@ Gus it looks fine yea but I don’t have any idea why I have these exceptions :frowning:

Thnx guys hope to solve this soon together

Hi PetaByte,

You need to add a reference to


(you’ve got a reference to FEZCerberus - subtle, but diffferent)

Then you need to make sure Program.cs contains a ProgramStarted() method (one was created automatically for you when you greated the new Gadgeteer application)
That could look like this:

void ProgramStarted()
  Debug.Print("Program Started");

  var analogInput = new Microsoft.SPOT.Hardware.AnalogInput(Cpu.AnalogChannel.ANALOG_0, 12);
  var analogValue = analogInput.Read();

  Debug.Print("Analog Input value was " + analogValue);

Also worth noting the obvious that while it’s fine to put your own code into Program.Generated.cs for quick and dirty testing it will be overwritten when the file is regenerated (any time you make changes to the Program.gadgeteer.diagram canvas

oops, I don’t have:

and all what I have is:

Thnx Byron :slight_smile:

It seems that we are almost there…

@ PetaByte - It still looks like your are using a console app - it will be easier to get going creating a new Gadgeteer app

1 Like

Hi dear Justin,

I have no problems working with whatever (MF console, Gadgeteer), but as I told you I had another Err while running your code in Gadgeteer project :frowning:

but the problem with Gadgeteer was that I didn’t find:

Remove the GHIElectronics.Gadgeteer,FEZCerberus reference and add GHIElectronics.Gadgeteer.FEZCerbuinoBee() reference

1 Like

Exactly that was the problem, I don’t have:
and all what I have is:

Anyway, I left the current PC and I installed VS2010 on my laptop again (and MF QEF2 and GHI NET MF 4.2 as well), and I found it there somehow!! :slight_smile:

image #1:
What I had in PC (Don’t care about it for know)

image #2:
what I got in the Laptop!!
‘GadgeteerApp1.Program’ does not contain a definition for ‘ProgramStarted’ and no extension method ‘ProgramStarted’ accepting a first argument of type ‘GadgeteerApp1.Program’ could be found (are you missing a using directive or an assembly reference?) c:\users\salman\documents\visual studio 2010\Projects\GadgeteerApp1\Program.generated.cs 27 21 GadgeteerApp1

Any idea gents :slight_smile: