Intro

In modern digital electronics, we often deal with finite states of HIGH or LOW, which represent digital 1/0, or On/Off, respectively. However, there are many sensors or other integrations that communicate not in binary, but in a range of voltages. For instance, a TMP35 analog temp sensor might output 0V when it’s reading an ambient temperature of 0ºC, 1.6V @ 50ºC, and 3.3V @ 100ºC.

Analog ports are specifically design for this scenario, and are able to operate throughout a specified range of voltages, in both an input (reading) and output (writing) capacity.

On the Meadow F7 Micro, Analog signals are written or read with a 12-bit resolution, which means that they can have 4,096 steps of resolution.

Meadow has the capabilities to both read and write analog signals, but presently only the input/read functionality is exposed via API.

Analog Input

Analog input is converted to a digital value via the onboard Analog to Digital Converter (ADC), which is accessed via an AnalogInputPort, and created from an IIODevice:

IAnalogInputPort analogIn = Device.CreateAnalogInputPort(Device.Pins.A02);

From there, the voltage can be read via the Read() method:

float voltage = analogIn.Read();

NOTE: Only analog pins A0 through A3 are currently configured. A4 and A5 will not currently work.

Events and IObservable API

As with other input APIs, the Analog input APIs support both events and the IObservable pattern, for advanced notification filtering. For more information, see the Events and IObservable guide.

Input Voltage Tolerance

It’s important to note that unlike the digital inputs (which are 5V tolerant), the analog inputs on the F7 Micro are only 3.3V tolerant, meaning any input signals above 3.3V may damage the chip. If you expect input signals to exceed 3.3V, there are two ways to protect the input.

If your sensor regularly operates at a higher voltage range, for instance, if it’s a 5V sensor, a two resistor voltage divider should be used to “divide” the voltage down from 5V to 3.3V.

For occasional voltage spikes that can be ignored, the input should be protected with a Zener diode and a resistor as illustrated in this tutorial.

Analog Output

Analog output can be generated via the Digital to Analog Converter (DAC) on the Meadow device. This feature is not currently exposed, and these docs will be updated when we ship it.

These docs are open source. If you find an issue, please file a bug, or send us a pull request. And if you want to contribute, we'd love that too!