# ESP32 - Complex Waveform Generator V2

#### Setting Up The App

<p class="callout info">ESP32 Complex Waveform Generator - Arrangement for WROOM-32 or WROVER-E (DevKit-C)</p>

##### <iframe allowfullscreen="allowfullscreen" height="451" src="https://www.youtube.com/embed/AxDYTR773SM" style="width: 804px; height: 451px;" width="804"></iframe>



#####   
PARTS Required

- 1 - ESP32 (WROOM-32 or WROVER-32) with 16 exposed pins
- 1 - ESP32 Breakout Board or equivalent pin header block
- 7 - Rotary Encoders (i.e. KY-040 Rotary Encoder Module CYT1062) 
    - TODO: add &gt;= 2 more for Elongation adjustments.
- 1 - +5VREG 1A Power Supply for ESP32 (i.e. ATX PowerSupply)

##### Installation Prerequisites

Install ESP Libraries in Arduino-IDE v2.0

```MarkDown
ArduinoJson
ESP32Encoder
```

##### Step 1. Open Esp32Full.ino and set Wifi Credentials  


```
// #### Change Me - Local Wifi Info ####
const char *SSID = "NETGEAR";
const char *PWD = "12345678";

```

##### Step 2. Configure free local LAN IP address  


Check your Router for more information

```
// #### CHANGE ME ####
// Set your Static IP address to a free IP in your local network
IPAddress local_IP(192, 168, 1, 8);
// Set your Gateway IP address
IPAddress gateway(192, 168, 1, 1);

IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(8, 8, 8, 8);   //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional
```

##### <span style="text-decoration: line-through;">Step 3. Configure ESP\_HOST in Javascript File</span>  


<span style="text-decoration: line-through;">Edit `./assets/espwavegen.js` and set the IP address used in Step 2 above.</span>

<p class="callout warning"><span style="text-decoration: line-through;">TODO: Make configurable in the web interface</span>  
</p>

<span style="text-decoration: line-through;">Save and close the file</span>

##### Step 3. Upload The code in `Esp32Full.ino`  


Paste the code into your Arduino-IDE and upload it to your ESP32

<p class="callout info">[Installing the ESP32 Board in Arduino IDE](https://randomnerdtutorials.com/installing-the-esp32-board-in-arduino-ide-windows-instructions/ "Installing the ESP32 Board in Arduino IDE")</p>

##### Step 4. Access the WebApp in your Web Browser  


Open Web Browser  
Open `index.html` in the `WebApp` directory below this file

- File -&gt; Open -&gt; Browse to WebApp/index.html -&gt; Open

Interface is now displayed!

#### Step 5: Enjoy!!

Please post pics and videos of your waves, and let others know how achievable this is!

[![Screenshot from 2022-12-31 13-23-07.png](https://stanslegacy.com/uploads/images/gallery/2022-12/scaled-1680-/uaaVo1B7ToYrI4Lr-screenshot-from-2022-12-31-13-23-07.png)](https://stanslegacy.com/uploads/images/gallery/2022-12/uaaVo1B7ToYrI4Lr-screenshot-from-2022-12-31-13-23-07.png)

#### Need Amplification?

<p class="callout success">See: [ESP32 - Complex Waveform Generator - Driver &amp; Amplification](https://stanslegacy.com/books/chris-bake/page/esp32-cwg-driver-amplification)</p>

#### [![Esp32-Encoder-Setup (5).png](https://stanslegacy.com/uploads/images/gallery/2022-12/scaled-1680-/qqNXcCwadrtae9wk-esp32-encoder-setup-5.png)](https://stanslegacy.com/uploads/images/gallery/2022-12/qqNXcCwadrtae9wk-esp32-encoder-setup-5.png)

####   


####   
Additional Troubleshooting / Customization

#####   
Optional: Configure alternate Output Pins  


- Output will be on Pins D2 and D4 by default

```C++
// #### Output Pins ####
int pinChannel1 = 2;
int pinChannel2 = 4;

```

##### Optional: Adjust Encoder Pins if needed  


```C++
int pulseCount_EncoderPIN1 = 14;
int pulseCount_EncoderPIN2 = 13;
int pulseWidth_EncoderPIN1 = 35;
int pulseWidth_EncoderPIN2 = 34;
int pulseSpace_EncoderPIN1 = 19;
int pulseSpace_EncoderPIN2 = 18;
int gate_freq_EncoderPIN1 = 22;
int gate_freq_EncoderPIN2 = 23;

int pulseWidthModifier_EncoderPIN1 = 27;
int pulseWidthModifier_EncoderPIN2 = 26;
int pulseSpaceModifier_EncoderPIN1 = 5;
int pulseSpaceModifier_EncoderPIN2 = 32;
int gateModifier_EncoderPIN1 = 25;
int gateModifier_EncoderPIN2 = 33;
```

#### ESP C+ Code

<p class="callout info">Git Repo: [https://bitbucket.org/cbake6807/esp32-complex-waveform-generator/src/master/](https://bitbucket.org/cbake6807/esp32-complex-waveform-generator/src/master/)</p>

##### Troubleshooting:

View the Console Log for errors in your browser while clicking the app's sliders buttons etc..

Look in the Network tab for red errors. 404 or other. Sometimes the ESP may drop or reject the connection on the first attempt. Just refresh the browser once or twice and it should resolve.

[![Screenshot from 2022-08-06 13-24-55.png](http://stanslegacy.com/uploads/images/gallery/2022-08/scaled-1680-/VUxhtVg24Ps11Wlw-screenshot-from-2022-08-06-13-24-55.png)](http://stanslegacy.com/uploads/images/gallery/2022-08/VUxhtVg24Ps11Wlw-screenshot-from-2022-08-06-13-24-55.png)

<p class="callout info">[https://www.browserstack.com/guide/inspect-element-in-chrome#:~:text=One%20of%20the%20easiest%20ways,%2C%20Sources%2C%20and%20other%20tools](https://www.browserstack.com/guide/inspect-element-in-chrome#:~:text=One%20of%20the%20easiest%20ways,%2C%20Sources%2C%20and%20other%20tools).</p>

Confirm the ESP is a connected host in your network and was given the IP you specified

<p class="callout info">[https://www.wikihow.com/See-Who-Is-Connected-to-Your-Wireless-Network](https://www.wikihow.com/See-Who-Is-Connected-to-Your-Wireless-Network)</p>

``

Code notes if internet connectivity isn't an option. Also, encoder wiring connections for this particular setup (Notepad++ document file type). [Chris Bake ESP32 notes.txt](https://stanslegacy.com/attachments/116)

Notepad++ download: [Notepad++](https://stanslegacy.com/attachments/117)