├── README.md ├── blinking-LED ├── src │ └── main.cpp └── platformio.ini ├── minimal-web-server ├── platformio.ini └── src │ └── main.cpp ├── servo-on-WiFi ├── platformio.ini └── src │ └── main.cpp └── servo-controller ├── platformio.ini └── src └── main.cpp /README.md: -------------------------------------------------------------------------------- 1 | # ESP32 projects 2 | 3 | ## Resources 4 | 5 | - https://esp32io.com/ 6 | - https://makeabilitylab.github.io/physcomp/esp32/ 7 | - https://techexplorations.com/esp32/ 8 | - https://www.donskytech.com/category/esp32/ 9 | - https://icircuit.net/category/esp32 10 | - https://randomnerdtutorials.com/projects-esp32/ 11 | -------------------------------------------------------------------------------- /blinking-LED/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void setup() 4 | { 5 | // put your setup code here, to run once: 6 | pinMode(LED_BUILTIN, OUTPUT); 7 | Serial.begin(115200); 8 | } 9 | 10 | void loop() 11 | { 12 | // put your main code here, to run repeatedly: 13 | digitalWrite(LED_BUILTIN, HIGH); 14 | Serial.println("LED is ON"); 15 | delay(500); 16 | digitalWrite(LED_BUILTIN, LOW); 17 | Serial.println("LED is OFF"); 18 | delay(500); 19 | } -------------------------------------------------------------------------------- /blinking-LED/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env:esp32doit-devkit-v1] 12 | platform = espressif32 13 | board = esp32doit-devkit-v1 14 | framework = arduino 15 | monitor_speed = 115200 -------------------------------------------------------------------------------- /minimal-web-server/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env:esp32doit-devkit-v1] 12 | platform = espressif32 13 | board = esp32doit-devkit-v1 14 | framework = arduino 15 | monitor_speed = 115200 16 | -------------------------------------------------------------------------------- /servo-on-WiFi/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env:esp32doit-devkit-v1] 12 | platform = espressif32 13 | board = esp32doit-devkit-v1 14 | framework = arduino 15 | monitor_speed = 115200 16 | lib_deps = roboticsbrno/ServoESP32@^1.0.3 17 | -------------------------------------------------------------------------------- /servo-controller/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env:esp32doit-devkit-v1] 12 | platform = espressif32 13 | board = esp32doit-devkit-v1 14 | framework = arduino 15 | monitor_speed = 115200 16 | lib_deps = roboticsbrno/ServoESP32@^1.0.3 17 | -------------------------------------------------------------------------------- /servo-controller/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | Servo myservo; // create servo object to control a servo 5 | // twelve servo objects can be created on most boards 6 | 7 | int pos; // variable to store the servo position 8 | int delta_t = 10; // ms 9 | int pause_t = 2500; // ms 10 | 11 | void setup() { 12 | myservo.attach(13); // attaches the servo on pin 9 to the servo object 13 | } 14 | 15 | void loop() { 16 | for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees 17 | // in steps of 1 degree 18 | myservo.write(pos); // tell servo to go to position in variable 'pos' 19 | delay(delta_t); // waits 15 ms for the servo to reach the position 20 | } 21 | delay(pause_t); 22 | for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees 23 | myservo.write(pos); // tell servo to go to position in variable 'pos' 24 | delay(delta_t); // waits 15 ms for the servo to reach the position 25 | } 26 | delay(pause_t); 27 | } -------------------------------------------------------------------------------- /minimal-web-server/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ESP32 Web Server - STA Mode 3 | modified on 25 MAy 2019 4 | by Mohammadreza Akbari @ Electropeak 5 | https://electropeak.com/learn/create-a-web-server-w-esp32/ 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | // SSID & Password 12 | const char *ssid = "***"; // Enter your SSID here 13 | const char *password = "***"; // Enter your Password here 14 | 15 | WebServer server(80); // Object of WebServer(HTTP port, 80 is defult) 16 | 17 | // HTML & CSS contents which display on web server 18 | String HTML = "\ 19 | \ 20 | \ 21 |

My First Web Server with ESP32 - Station Mode 😊

\ 22 | \ 23 | "; 24 | 25 | // Handle root url (/) 26 | void handle_root() 27 | { 28 | server.send(200, "text/html", HTML); 29 | } 30 | 31 | void setup() 32 | { 33 | Serial.begin(115200); 34 | Serial.println("Try Connecting to "); 35 | Serial.println(ssid); 36 | 37 | // Connect to your wi-fi modem 38 | WiFi.begin(ssid, password); 39 | 40 | // Check wi-fi is connected to wi-fi network 41 | while (WiFi.status() != WL_CONNECTED) 42 | { 43 | delay(1000); 44 | Serial.print("."); 45 | } 46 | Serial.println(""); 47 | Serial.println("WiFi connected successfully"); 48 | Serial.print("Got IP: "); 49 | Serial.println(WiFi.localIP()); // Show ESP32 IP on serial 50 | 51 | server.on("/", handle_root); 52 | 53 | server.begin(); 54 | Serial.println("HTTP server started"); 55 | delay(100); 56 | } 57 | 58 | void loop() 59 | { 60 | server.handleClient(); 61 | } 62 | -------------------------------------------------------------------------------- /servo-on-WiFi/src/main.cpp: -------------------------------------------------------------------------------- 1 | /********* 2 | Rui Santos 3 | Complete project details at http://randomnerdtutorials.com 4 | *********/ 5 | 6 | #include 7 | #include 8 | 9 | Servo myservo; // create servo object to control a servo 10 | // twelve servo objects can be created on most boards 11 | 12 | // GPIO the servo is attached to 13 | static const int servoPin = 13; 14 | 15 | // Replace with your network credentials 16 | const char* ssid = "***"; 17 | const char* password = "***"; 18 | 19 | // Set web server port number to 80 20 | WiFiServer server(80); 21 | 22 | // Variable to store the HTTP request 23 | String header; 24 | 25 | // Decode HTTP GET value 26 | String valueString = String(5); 27 | int pos1 = 0; 28 | int pos2 = 0; 29 | 30 | // Current time 31 | unsigned long currentTime = millis(); 32 | // Previous time 33 | unsigned long previousTime = 0; 34 | // Define timeout time in milliseconds (example: 2000ms = 2s) 35 | const long timeoutTime = 2000; 36 | 37 | void setup() { 38 | Serial.begin(115200); 39 | 40 | myservo.attach(servoPin); // attaches the servo on the servoPin to the servo object 41 | 42 | // Connect to Wi-Fi network with SSID and password 43 | Serial.print("Connecting to "); 44 | Serial.println(ssid); 45 | WiFi.begin(ssid, password); 46 | while (WiFi.status() != WL_CONNECTED) { 47 | delay(500); 48 | Serial.print("."); 49 | } 50 | // Print local IP address and start web server 51 | Serial.println(""); 52 | Serial.println("WiFi connected."); 53 | Serial.println("IP address: "); 54 | Serial.println(WiFi.localIP()); 55 | server.begin(); 56 | } 57 | 58 | void loop(){ 59 | WiFiClient client = server.available(); // Listen for incoming clients 60 | 61 | if (client) { // If a new client connects, 62 | currentTime = millis(); 63 | previousTime = currentTime; 64 | Serial.println("New Client."); // print a message out in the serial port 65 | String currentLine = ""; // make a String to hold incoming data from the client 66 | while (client.connected() && currentTime - previousTime <= timeoutTime) { // loop while the client's connected 67 | currentTime = millis(); 68 | if (client.available()) { // if there's bytes to read from the client, 69 | char c = client.read(); // read a byte, then 70 | Serial.write(c); // print it out the serial monitor 71 | header += c; 72 | if (c == '\n') { // if the byte is a newline character 73 | // if the current line is blank, you got two newline characters in a row. 74 | // that's the end of the client HTTP request, so send a response: 75 | if (currentLine.length() == 0) { 76 | // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) 77 | // and a content-type so the client knows what's coming, then a blank line: 78 | client.println("HTTP/1.1 200 OK"); 79 | client.println("Content-type:text/html"); 80 | client.println("Connection: close"); 81 | client.println(); 82 | 83 | // Display the HTML web page 84 | client.println(""); 85 | client.println(""); 86 | client.println(""); 87 | // CSS to style the on/off buttons 88 | // Feel free to change the background-color and font-size attributes to fit your preferences 89 | client.println(""); 91 | client.println(""); 92 | 93 | // Web Page 94 | client.println("

ESP32 with Servo

"); 95 | client.println("

Position:

"); 96 | client.println(""); 97 | 98 | client.println(""); 103 | 104 | client.println(""); 105 | 106 | //GET /?value=180& HTTP/1.1 107 | if(header.indexOf("GET /?value=")>=0) { 108 | pos1 = header.indexOf('='); 109 | pos2 = header.indexOf('&'); 110 | valueString = header.substring(pos1+1, pos2); 111 | 112 | //Rotate the servo 113 | myservo.write(valueString.toInt()); 114 | Serial.println(valueString); 115 | } 116 | // The HTTP response ends with another blank line 117 | client.println(); 118 | // Break out of the while loop 119 | break; 120 | } else { // if you got a newline, then clear currentLine 121 | currentLine = ""; 122 | } 123 | } else if (c != '\r') { // if you got anything else but a carriage return character, 124 | currentLine += c; // add it to the end of the currentLine 125 | } 126 | } 127 | } 128 | // Clear the header variable 129 | header = ""; 130 | // Close the connection 131 | client.stop(); 132 | Serial.println("Client disconnected."); 133 | Serial.println(""); 134 | } 135 | } --------------------------------------------------------------------------------