How to use the analog port in Socket3, Cerbuino Bee

Hi Gents,

I have Cerbuino Bee and I was reading an analog input successfully from (A0) using:

var analogInput = new Microsoft.SPOT.Hardware.AnalogInput(GHI.OSHW.Hardware.FEZCerbuino.Pin.AnalogIn.A0);

But when I want to use the analog input in Socket #3, so I changed it to:

var analogInput = new Microsoft.SPOT.Hardware.AnalogInput(GHI.OSHW.Hardware.FEZCerbuino.Pin.Gadgeteer.Socket3.Pin3);

it gives me some errors:
[em]Error 2 Argument 1: cannot convert from ‘Microsoft.SPOT.Hardware.Cpu.Pin’ to 'Microsoft.SPOT.Hardware.Cpu.AnalogChannel’
Error 1 The best overloaded method match for ‘Microsoft.SPOT.Hardware.AnalogInput.AnalogInput(Microsoft.SPOT.Hardware.Cpu.AnalogChannel)’
[/em]
I was trying to cast it using:
var analogInput = new Microsoft.SPOT.Hardware.AnalogInput((Microsoft.SPOT.Hardware.Cpu.AnalogChannel)GHI.OSHW.Hardware.FEZCerbuino.Pin.Gadgeteer.Socket3.Pin3);

The error gone, no errors now but it gives me run-time exception!!
[em]Exception performing Timer operation
A first chance exception of type ‘System.ArgumentException’ occurred in Microsoft.SPOT.Hardware.dll
[/em]
All what I need right now is to read an analog input from Socket #3, any idea?

Regards :slight_smile:

It appears that you have cast one enumeration to another. Since both are integer based, the conversion is allowed. While the conversion succeeded, this does not mean that the value casted is correct in it’s new form.

Keep using what works.

@ PetaByte

This particular enumeration GHI.OSHW.Hardware.FEZCerbuino.Pin.Gadgeteer.Socket3.Pin3 is the standard CPU.Pin enumeration. It does not translate to the actual analog channel that is on that pin. Check this page: http://www.ghielectronics.com/docs/45/fez-cerbuino-bee-developer#395 to see the pin that is being accessed to translate to the proper analog channel.