|
1 | 1 | # Arduino_AdvancedAnalog library
|
2 | 2 |
|
3 |
| -The **Arduino_AdvancedAnalog** library is designed for high performance DAC/ADC applications on boards based on the STM32H747XI microcontroller: |
| 3 | +[](../LICENSE) |
| 4 | + |
| 5 | +The **Arduino_AdvancedAnalog** library is designed to offer high performance DAC/ADC applications on boards based on the STM32H747XI microcontroller: |
4 | 6 | - [Arduino GIGA R1 WiFi](https://store.arduino.cc/products/giga-r1-wifi)
|
5 | 7 | - [Arduino Portenta H7](https://store.arduino.cc/products/portenta-h7)
|
6 | 8 |
|
7 |
| -To use this library: |
| 9 | +## Features |
| 10 | + |
| 11 | +- ADC/DAC parameters fine tuning: resolution, channel number, queue number and size |
| 12 | +- ADC acquisition with DMA in double buffering mode |
| 13 | +- ADC Multichannel acquisition |
| 14 | +- DAC Multichannel writing |
| 15 | +- Storing ADC samples history in multiple queues |
| 16 | +## Guides |
| 17 | + |
| 18 | +To learn more about using the DAC & ADC on the GIGA R1 WiFi, check out the [GIGA Advanced DAC/ADC Guide](https://docs.arduino.cc/tutorials/giga-r1-wifi/giga-audio). |
| 19 | + |
| 20 | +This includes examples such as audio playback from USB storage, generate sine waves and more. |
| 21 | +## Usage |
| 22 | + |
| 23 | +### ADC |
| 24 | + |
| 25 | +To use this library for ADC applications, you must have a supported Arduino board and include the AdvancedAnalog library in your Arduino sketch. Here is a minimal example: |
| 26 | + |
| 27 | +```cpp |
| 28 | +#include <Arduino_AdvancedAnalog.h> |
| 29 | + |
| 30 | +AdvancedADC adc1(A0); |
| 31 | + |
| 32 | +void setup() { |
| 33 | + Serial.begin(9600); |
| 34 | + |
| 35 | + // Initialize ADC with: resolution, sample rate, number of samples per channel, queue depth |
| 36 | + if (!adc1.begin(AN_RESOLUTION_16, 16000, 32, 64)) { |
| 37 | + Serial.println("Failed to start ADC!"); |
| 38 | + while (1); |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +void loop() { |
| 43 | + // Check if an ADC measurement is ready |
| 44 | + if (adc1.available()) { |
| 45 | + // Get read buffer |
| 46 | + SampleBuffer buf = adc1.read(); |
| 47 | + |
| 48 | + // Print sample from read buffer |
| 49 | + Serial.println(buf[0]); |
| 50 | + |
| 51 | + // Release read buffer |
| 52 | + buf.release(); |
| 53 | + } |
| 54 | +} |
| 55 | +``` |
| 56 | +
|
| 57 | +#### ADC Multichannel (GIGA R1 WiFi) |
| 58 | +This library supports concurrent usage of up to **three** ADCs (_ADC1_, _ADC2_ and _ADC3_). |
| 59 | +Each ADC instance can handle up to **five** channels. |
| 60 | +
|
| 61 | +**Note:** It's important to be aware that certain pins cannot be used across multiple ADCs or cannot share the same ADC. |
| 62 | +
|
| 63 | +*Please ensure that you refer to tables below when configuring your project to avoid conflicts in pin assignments.* |
| 64 | +
|
| 65 | +Below is a table illustrating the pin mapping for each ADC in **Arduino Giga R1 WiFi**: |
| 66 | +
|
| 67 | +| Pin | ADC1 | ADC2 | ADC3 | |
| 68 | +|-------|-------|-------|-------| |
| 69 | +| A0 | X | X | | |
| 70 | +| A1 | X | X | | |
| 71 | +| A2 | X | X | | |
| 72 | +| A3 | X | X | | |
| 73 | +| A4 | X | X | | |
| 74 | +| A5 | X | X | X | |
| 75 | +| A6 | X | X | X | |
| 76 | +| A7 | X | | | |
| 77 | +| A8 | | | X | |
| 78 | +| A9 | | | X | |
| 79 | +| A10 | X | X | | |
| 80 | +| A11 | X | X | | |
| 81 | +
|
| 82 | +Here is a example for the Arduino GIGA R1 WiFi: |
| 83 | +
|
| 84 | +```cpp |
| 85 | +#include <Arduino_AdvancedAnalog.h> |
| 86 | +
|
| 87 | +AdvancedADC adc_a(A0, A1); |
| 88 | +/* Mapped to ADC1 */ |
| 89 | +
|
| 90 | +AdvancedADC adc_b(A2); |
| 91 | +/* Mapped to ADC2, because ADC1 is occupied by A0 and A1 */ |
8 | 92 |
|
| 93 | +void setup() { |
| 94 | +... |
9 | 95 | ```
|
| 96 | + |
| 97 | +#### ADC Multichannel (Portenta H7) |
| 98 | + |
| 99 | +Below is a table illustrating the pin mapping for each ADC in **Portenta H7**: |
| 100 | + |
| 101 | +| Pin | ADC1 | ADC2 | ADC3 | |
| 102 | +|-------|-------|-------|-------| |
| 103 | +| A0 | X | X | | |
| 104 | +| A1 | X | X | | |
| 105 | +| A2 | | | X | |
| 106 | +| A3 | | | X | |
| 107 | +| A4 | X | X | X | |
| 108 | +| A5 | X | X | | |
| 109 | +| A6 | X | X | | |
| 110 | +| A7 | X | X | | |
| 111 | + |
| 112 | +Here is an example for the Portenta H7: |
| 113 | + |
| 114 | +```cpp |
10 | 115 | #include <Arduino_AdvancedAnalog.h>
|
| 116 | + |
| 117 | +AdvancedADC adc_c(A2, A3, A4); |
| 118 | +/* Mapped to ADC3 */ |
| 119 | + |
| 120 | +AdvancedADC adc_d(A5); |
| 121 | +/* Mapped to ADC1 */ |
| 122 | + |
| 123 | +void setup() { |
| 124 | +... |
11 | 125 | ```
|
12 | 126 |
|
| 127 | +### DAC |
| 128 | +
|
| 129 | +To use this library for DAC application, you must have a supported Arduino board and include the AdvancedAnalog library in your Arduino sketch. Here is a minimal example for the Arduino GIGA R1 WiFi: |
| 130 | +
|
| 131 | +```cpp |
| 132 | +#include <Arduino_AdvancedAnalog.h> |
| 133 | +
|
| 134 | +AdvancedDAC dac1(A12); |
| 135 | +
|
| 136 | +void setup() { |
| 137 | + Serial.begin(9600); |
| 138 | +
|
| 139 | + // Initialize DAC with: resolution, sample rate, number of samples per channel, queue depth |
| 140 | + if (!dac1.begin(AN_RESOLUTION_12, 8000, 32, 64)) { |
| 141 | + Serial.println("Failed to start DAC!"); |
| 142 | + while (1); |
| 143 | + } |
| 144 | +} |
| 145 | +
|
| 146 | +void loop() { |
| 147 | + if (dac1.available()) { |
| 148 | +
|
| 149 | + // Get a free buffer for writing |
| 150 | + SampleBuffer buf = dac1.dequeue(); |
| 151 | +
|
| 152 | + // Write data to buffer (Even position: 0, Odd position: 0xFFF) |
| 153 | + for (int i=0; i<buf.size(); i++) { |
| 154 | + buf.data()[i] = (i % 2 == 0) ? 0: 0xFFF; |
| 155 | + } |
| 156 | +
|
| 157 | + // Write the buffer to DAC |
| 158 | + dac1.write(buf); |
| 159 | + } |
| 160 | +} |
| 161 | +``` |
| 162 | + |
| 163 | +## Examples |
| 164 | +- **[Advanced](../examples/Advanced):** This folder contains examples showing how to configure ADC/DAC to read/write data. |
| 165 | +- **[Beginner](../examples/Beginner):** This folder contains examples showing how to generate waveforms with DAC. |
| 166 | + |
| 167 | +## API |
| 168 | + |
| 169 | +The API documentation can be found [here](./api.md). |
| 170 | + |
| 171 | +## License |
| 172 | + |
| 173 | +This library is released under the [LGPLv2.1 license](../LICENSE). |
| 174 | + |
0 commit comments