1# Sigma Delta Modulation Example 2 3(See the README.md file in the upper level 'examples' directory for more information about examples.) 4 5This example uses the sigma-delta driver to generate modulated output on a GPIO. If you connect a LED to the output GPIO, you will see it slowly brightening and dimming. 6 7 8## How to use example 9 10### Hardware Required 11 12Besides the [ESP32 development board](https://www.espressif.com/en/products/hardware/development-boards) you need a LED and a resistor to limit the LED current. Connect them as below: 13 14``` 15 330R LED 16GPIO4 +----/\/\/\----+------|>|-----+ GND 17``` 18 19A resistor in range from 100 Ohm to 1 kOhm should usually be fine. You may use ESP32 development board by other vendors as well, provided they have at least one GPIO output pin exposed. 20 21By default the GPIO output is 4. To change it, edit the line with `GPIO_NUM_4` in `sigmadelta_init()` function inside `main/sigmadelta_test.c`. For example to use GPIO 25, modify the line to contain `GPIO_NUM_25` instead. 22 23 24### Configure the project 25 26``` 27idf.py menuconfig 28``` 29 30### Build and Flash 31 32Build the project and flash it to the board, then run monitor tool to view serial output: 33 34``` 35idf.py -p PORT flash monitor 36``` 37 38(To exit the serial monitor, type ``Ctrl-]``.) 39 40See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects. 41 42## Example Output 43 44Once the upload is complete and the board is reset, the program should start running. This is reported on the monitor as below: 45 46``` 47... 48I (275) cpu_start: Pro cpu start user code 49I (293) cpu_start: Starting scheduler on PRO CPU. 50I (0) cpu_start: Starting scheduler on APP CPU. 51``` 52 53Immediately after that the LED should start brightening and dimming. 54 55 56## Troubleshooting 57 58If you are using [ESP-WROVER-KIT](https://www.espressif.com/en/products/hardware/esp-wrover-kit/overview) then this board has an RGB LED already installed. GPIO4 is driving blue color of the LED. The brightening and dimming effect of the blue LED may not be distinctly visible because red and green LEDs are not actively driven by this example and will slightly lit. To resolve this issue you can switch both diodes off by adding the following code at the end of `sigmadelta_example_init()` function: 59 60```c 61esp_rom_gpio_pad_select_gpio(GPIO_NUM_0); 62gpio_set_direction(GPIO_NUM_0, GPIO_MODE_OUTPUT); 63gpio_set_level(GPIO_NUM_0, 0); 64 65esp_rom_gpio_pad_select_gpio(GPIO_NUM_2); 66gpio_set_direction(GPIO_NUM_2, GPIO_MODE_OUTPUT); 67gpio_set_level(GPIO_NUM_2, 0); 68``` 69