Main Site Documentation

Cerbuino Bee PB1,PA5, PB0, PC3 as analog inputs?


#1

Can someone provide me with an example on how to do what’s stated in the subject line? I’m finding conflicting info in the forum about this so far. Using the latest SDK.

Thanks!


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

namespace GadgeteerApp28
{
    public partial class Program
    {
       void ProgramStarted()
        {
            Microsoft.SPOT.Hardware.AnalogInput a1 = new Microsoft.SPOT.Hardware.AnalogInput((Cpu.AnalogChannel) GHI.Hardware.FEZCerb.Pin.PA5);
        }
    }
}

#3

You will use the following code:


AnalogInput VARIABLE_NAME = new AnalogInput(CPU.AnalogChannel.ANALOG_X);

where X is the channel number. Because NETMF only enumerates the first 8 channels, you will need to typecast 8+.

Here is a link to the analog channels: http://www.ghielectronics.com/docs/46/cerb-family#403


#4

Thanks for the info guys but I get:

A first chance exception of type ‘System.ArgumentException’ occurred in Microsoft.SPOT.Hardware.dll
An unhandled exception of type ‘System.ArgumentException’ occurred in Microsoft.SPOT.Hardware.dll

at for this line during deployment:

AnalogInput ana1 = new AnalogInput((Cpu.AnalogChannel)GHI.Hardware.FEZCerb.Pin.PB1);

#5

The reason is because the NetMF implementation of AnalogIn uses channels and not the pin assignments. Typecasting the Cerb pins to a channel is the same as saying channel 17 in the case of the pin that you used. Look at my previous post to see the differences and go to the link because it will show you a list of the analog channel enumerations.


#6

Alrighty then. I guess I’m at a loss as to how to typecast something besides what I thought I showed I did.

Please provide me the correct code replacement for the following lines I cannot get to work:

AnalogInput ana1 = new AnalogInput((Cpu.AnalogChannel)GHI.Hardware.FEZCerb.Pin.PB1);

        AnalogInput ana2 = new AnalogInput((Cpu.AnalogChannel) GHI.Hardware.FEZCerb.Pin.PA5);

        AnalogInput ana3 = new AnalogInput((Cpu.AnalogChannel)GHI.Hardware.FEZCerb.Pin.PB0);

        AnalogInput ana4 = new AnalogInput((Cpu.AnalogChannel)GHI.Hardware.FEZCerb.Pin.PC3);

Thanks!


#7

OMG I figured it out! Can it really be this freakin easy? I suppose so!

My fix:

        AnalogInput ana1 = new AnalogInput((Cpu.AnalogChannel)10);

        AnalogInput ana2 = new AnalogInput((Cpu.AnalogChannel)8);

        AnalogInput ana3 = new AnalogInput((Cpu.AnalogChannel)9);

        AnalogInput ana4 = new AnalogInput(Cpu.AnalogChannel.ANALOG_7);


#8

That is why we call it FEZ. :wink: