One of the main new features of version 4.2 of the. NET Micro Framework is the support for the analog inputs with the introduction of class AnalogInput (namespace Microsoft.SPOT.Hardware). Until this version, each producer board that carried out the porting of the framework on it, introduced in its SDK a custom class for the management of these inputs. In particular, also the SecretLabs, producer of Netduino, provides the class AnalogInput (in the namespace SecretLabs.NETMF.Hardware) with version 4.1 and that presents some difference than is currently introduced into the new version. Thanks to this innovation, the developer can work with the same class of more different board without having to adapt from time to time to the specific implementation by the manufacturer thereof.
See below what the main difference between the AnalogInput the Netduino with the. Net Micro Framework 4.1 and the corresponding class only with version 4.2 of the framework itself.
In the first place the constructor, which in the case of Netduino 4.1 provides as input the input pin (enum Cpu.Pin) while in. Net MF 4.2 provides the enum Cpu.AnalogChannel.
As for the read operation of the input variable (however a voltage value), in the case of Netduino 4.1 is expected the Read() method that returns an integer value resulting from the conversion performed by the ADC (Analog-Digital Converter) . To obtain the corresponding voltage value, it is necessary to execute code in its calculations taking into account the resolution of the ADC (10 bits, values from 0 to 1023) and the reference voltage (typically 3.3 V). In the case of. Net MF 4.2, the Read () method returns a value between 0 and 1 which when multiplied by the reference voltage, it provides directly the value of voltage on pin bed. If you want to get the integer value, the result of the conversion, you must use the method ReadRaw(). Furthermore, were introduced the following two properties:
I report two examples of application of both classes ..
Netduino con .Net Micro Framework 4.1
1: AnalogInput input = new AnalogInput(Pins.GPIO_PIN_A0)
3: // ritorna un valore tra 0 e 1023 (ADC a 10 bit)
4: int value = input.Read();
6: // bisogna calcolare il valore corrispondente della tensione
7: double volt = value * 3.3 / 1023;
.Net Micro Framework 4.2
1: AnalogInput input = new AnalogInput(AnalogChannels.ANALOG_PIN_A0)
4: int rawValue = input.ReadRaw();
6: // ritorna un valore tra 0 ed 1 che va moltiplicato per
7: // la ARef per ottenere il valore in Volt della tensione
8: double volt = input.Read() * 3.3;
Thank you for posting this. I couldn't find documentation on how Read and ReadRaw function anywhere, so this is awesome and exactly what I needed to know.
View this page in another language: