Azure Sphere – ADC
This sample application demonstrates how to do analog-to-digital conversion in a high-level application.
The application samples and displays the output from a simple variable voltage source once per second. It uses the MT3620 analog-to-digital converter (ADC) to sample the voltage.
The sample uses the following Azure Sphere libraries.
|adc||Manages the analog-to-digital converters (ADCs).|
|eventloop||Invokes handlers for timer events.|
|log||Displays messages in the Device Output window during debugging.|
||Application manifest file, which describes the resources.|
||CMake configuration file, which Contains the project information and is required for all builds.|
||JSON file for configuring Visual Studio to use CMake with the correct command-line options.|
||JSON file that tells Visual Studio how to deploy and debug the application.|
||The license for this sample application.|
||Main C source code file.|
||This README file.|
||Folder containing the JSON files that configure Visual Studio Code for building, debugging, and deploying the application.|
||Folder containing the hardware definition files for various Azure Sphere boards.|
The sample requires the following hardware:
Note: By default, this sample targets MT3620 reference development board (RDB) hardware, such as the MT3620 development kit from Seeed Studio. To build the sample for different Azure Sphere hardware, change the Target Hardware Definition Directory in the CMakeLists.txt file. For detailed instructions, see the README file in the HardwareDefinitions folder.
Ensure that your Azure Sphere device is connected to your computer, and your computer is connected to the internet.
Even if you've performed this setup previously, ensure that you have Azure Sphere SDK version 21.04 or above. At the command prompt, run azsphere show-version to check. Upgrade the Azure Sphere SDK for Windows or Linux as needed.
Enable application development, if you have not already done so, by entering the following line at the command prompt:
azsphere device enable-development
Set up the ADC connections
- Connect MT3620 dev board pin H2.2 (GND) to an outer terminal of the potentiometer.
- Connect both pin 1 and pin 2 of jumper J1 to the other outer terminal of the potentiometer. This connects the MT3620 2.5 V output to the ADC VREF pin and to the potentiometer.
- Connect MT3620 dev board pin H2.11 (GPIO41 / ADC0) to the center terminal of the potentiometer.
Build and run the sample
To build and run this sample, follow the instructions in Build a sample application.
Test the sample
The ADC output is displayed in the output terminal or Device Output window during debugging. Adjust the potentiometer and observe that the displayed value changes, as shown in the following example output.
Show output from: Device Output The out sample value is 2.500 V The out sample value is 2.483 V The out sample value is 2.337 V The out sample value is 2.055 V
- For an overview of Azure Sphere, see What is Azure Sphere.
- To learn more about Azure Sphere application development, see Overview of Azure Sphere applications.
- To learn more about how to interact with an ADC peripheral by using the simplified Azure Sphere functions or the advanced Linux IOCTLs, see the ADC code snippets.
- For information about using ADCs, see Use ADCs in high-level applications.