Hi, I just came across another question for the analog reading in FEZ Cerbuino Bee. In NETMF4.1, we can just use the AnalogIn class which requires the assembly:
But I installed the NETMF 4.2 and could not find those assemblies any more. I wonder how canI read the analog signal with Cerbuino Bee? The only class I found is the AnalogInput defined in Microsoft.SPOT.Hardware, but I don’t know the mapping between Cpu.AnalogChannel with Cerbuino on board pins.
Prior to NETMF 4.2, Analog and PWM were added to the firmware as an added feature by the hardware vendor. Microsoft has subsequently added these two features to Micro Framework 4.2+. So to answer you question, Microsoft.SPOT.Hardware is the correct AnalogIn assembly to use and it is similar to how the GHI version worked.
With the upcoming firmware, Cerbuino will have the Arduino-styled headers enumerated for easier access to digital pins, Analog, and PWM plus Gadgeteer functionality will be available as well.
Just a quick curiosity: how to use AnalogInput class with Cerbuino Bee.
I tried to use: AnalogInput testAI = new AnalogInput (Cpu.AnalogChannel channel); and tried to cast the Cerbuino pin A0 (which is PB1/ADC12_IN9) to Cpu.AnalogChannel without any luck. Is there a way find which pin of Cerbuino Bee maps to the AnalogInput class channel?
For the mean time here is the order of channels to pin for the Cerberus/Cerbuino:
// A6,A2,A3,C0,C1,A4,C2,C3,A5,B0,B1
Channel 0 is A6 to Channel 10 is B1.
For the Cerbuino Pin-out Library the Arduino-styled Header will have the A0 - A5 already type casted to the correct channel. As for the Analog on the Gadgeteer sockets, you would either use Gadgeteer code or you will have to manually set the analog channel to the proper channel based on the pin out on the wiki and to what was listed here.
Need help, from reviewing this topic I’m trying to write a simple Hello World application on a Cerbuino Bee that reads the value from a non-gadgeteer analog sensor such as a light sensor, temperature sensor, etc. connected to e.g. A2. My simple program below throws an exception when I instantiate AnalogInput testAI. I’m using the channel order noted earlier in this topic.
A first chance exception of type ‘System.InvalidOperationException’ occurred in Microsoft.SPOT.Hardware.dll
A first chance exception of type ‘System.InvalidOperationException’ occurred in Microsoft.SPOT.Hardware.dll
An unhandled exception of type ‘System.InvalidOperationException’ occurred in Microsoft.SPOT.Hardware.dll
I am actually using a Gadgeteer button connected to socket 3, and then I’m using some of my Arduino Electronic Brick sensors connected to the A0-A5 connection headers. I desire a simple program that illustrates how to read the raw values from the A0-A5 and also how to write to the digital outputs D0-D9. The earlier reply that recommended that I cast did get me past my exceptions e.g.- AnalogInput testAI = new AnalogInput( (Cpu.AnalogChannel) Cpu.AnalogChannel.ANALOG_1); However, when I read the value of the analog input the result never changes even if e.g. the temperature changes. Thanks to everyone for the help so far!
If you are using the Arduino-Style AnalogIn headers, the A1 pin does not necessarily correspond to AnalogIn Channel 1. The channels are relative to how the pins were laid out. It is possible that you are reading one of the other analog pins that have nothing on them.
Under GHI.OSHW.Hardware, there is an enumeration for the proper channel for the Arduino-Styled headers. Here is an example:
AnalogInput testAI = new AnalogInput(FEZCerbuino.Pin.AnalogIn.A1);
Just add a reference to GHI.OSHW.Hardware and use the using and you can open up the other headers for Cerbuino. Type casting with this method should not be necessary as the enumerations are already typed to Analog channel type.