User Tools

Site Tools


esp32

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
esp32 [2024/10/20 11:53] – [Install] brunoesp32 [2025/03/06 20:28] (current) bruno
Line 1: Line 1:
-==== Install ====+==== Préambule ====
  
-=== Préambule: Les vidéos de Tommy Desrochers ===+Les vidéos de Tommy Desrochers:
  
   * [[https://www.youtube.com/watch?v=zqwnYuOLvsE|ESP32 #1]]   * [[https://www.youtube.com/watch?v=zqwnYuOLvsE|ESP32 #1]]
Line 8: Line 8:
   * [[https://www.youtube.com/watch?v=DDMQbqPUliY|ESP32 #4]]   * [[https://www.youtube.com/watch?v=DDMQbqPUliY|ESP32 #4]]
   * [[https://www.youtube.com/watch?v=LkxCr_n3JOw|ESP32 #5]]   * [[https://www.youtube.com/watch?v=LkxCr_n3JOw|ESP32 #5]]
 +
 +==== Installation ====
  
 === Install config sous Linux === === Install config sous Linux ===
  
-Sous Debian 13, lors du 1er test, j'ai reçu ces deux messages d'erreur:+Sous Debian 12, lors du 1er test, j'ai reçu ces deux messages d'erreur:
  
   * Error Msg: ''ModuleNotFoundError: No module named 'serial'''   * Error Msg: ''ModuleNotFoundError: No module named 'serial'''
Line 36: Line 38:
   *  Menu File -> example -> ESP32 -> ChipID -> GetChipID   *  Menu File -> example -> ESP32 -> ChipID -> GetChipID
   * Upload: Menu Sketch -> Upload   * Upload: Menu Sketch -> Upload
-  * Error Msg: ''ModuleNotFoundError: No module named 'serial''' => ''# apt install python3-serial'' 
-  * Error msg: ''Failed uploading: no upload port provided'' => ''# /sbin/usermod -aG dialout <USER>'' + reboot 
   * Menu Tools -> Serial Monitor   * Menu Tools -> Serial Monitor
   * Change to 115200 Baud   * Change to 115200 Baud
Line 47: Line 47:
 </code> </code>
  
-  * [[https://gist.github.com/plembo/37e0d4c3cabaead6a150e61d6a8c3035]]+==== Serial Output ==== 
 + 
 +<code c> 
 +void setup() {  
 +  Serial.begin(115200); 
 +  while (!Serial) continue; 
 +  Serial.println("Ready."); 
 +}  
 +void loop() {  
 +
 +</code>
  
 ==== K2000 ==== ==== K2000 ====
 [26/09/2014] [26/09/2014]
 +
 +Suite illogique des pins GPIO
 +
 +GPIO-1 en OUTPUT -> conflit avec sortie serial
 <code c> <code c>
 #include <math.h> #include <math.h>
- 
 const float pi = 3.14159; const float pi = 3.14159;
- 
-// Suite illogique des pins GPIO 
-// /!\ GPIO-1 en OUTPUT -> conflit avec sortie Serial 
 const int ledPin[7] = {5,18,19,21,3,22,23};  const int ledPin[7] = {5,18,19,21,3,22,23}; 
    
-void setup() {  +void setup() {  
- +
-  Serial.begin(115200); +
-  while (!Serial) continue; +
-  Serial.println("Ready."); +
-  +
   for (int i=0; i<7; i++) {   for (int i=0; i<7; i++) {
     pinMode (ledPin[i], OUTPUT);     pinMode (ledPin[i], OUTPUT);
Line 72: Line 77:
    
 void loop() {  void loop() { 
- 
   for (float ang=-pi; ang<pi; ang=ang+(2*pi/700)) {   for (float ang=-pi; ang<pi; ang=ang+(2*pi/700)) {
     int led = (1+std::sin(ang))*7/2;     int led = (1+std::sin(ang))*7/2;
-    //Serial.print(led); 
     digitalWrite (ledPin[led], HIGH);     digitalWrite (ledPin[led], HIGH);
     delay(1);     delay(1);
     digitalWrite (ledPin[led], LOW);     digitalWrite (ledPin[led], LOW);
   }   }
-  //Serial.println(); 
-   
 } }
 </code> </code>
  
-==== Client Wifi ==== 
  
-<code c> 
- 
-#include <WiFi.h> 
- 
-void setup() { 
- 
-  Serial.begin(115200); 
-  while (!Serial) continue; 
- 
-  WiFi.begin("SSID", "P4sswOrd"); 
-  while (WiFi.status() != WL_CONNECTED) delay(500); 
-  Serial.print("IP address:"); 
-  Serial.println(WiFi.localIP()); 
- 
-} 
- 
-void loop() { 
- 
-  if (WiFi.status() == WL_CONNECTED) { 
-    Serial.println("Connected to Wifi."); 
-  } else { 
-    Serial.println("WiFi connection lost."); 
-  } 
-  delay(1000); 
-} 
-</code> 
- 
-==== Client HTTP ==== 
- 
-<code c> 
- 
-#include <WiFi.h> 
-#include <HTTPClient.h> 
- 
-void setup() { 
- 
-  Serial.begin(115200); 
-  while (!Serial) continue; 
- 
-  WiFi.begin("SSID", "P4ssw0rd"); 
- 
-  while (WiFi.status() != WL_CONNECTED) delay(500); 
- 
-  Serial.println("Connected to Wifi."); 
- 
-  HTTPClient http; 
- 
-  Serial.print("Get https://example.com... "); 
-  http.begin("https://example.com"); 
-  int httpCode = http.GET(); 
- 
-  if (httpCode == HTTP_CODE_OK) { 
- 
-    Serial.println(http.getString()); 
- 
-  } else { 
- 
-    Serial.printf("failed, error: %s\n", http.errorToString(httpCode).c_str()); 
- 
-  } 
- 
-  http.end(); 
-} 
- 
-void loop() { 
-} 
- 
-</code> 
- 
-==== Server HTTP === 
- 
-<code c> 
-#include <WiFi.h> 
-#include <WebServer.h> 
-//#include <ESPmDNS.h> 
- 
-const char *ssid = "Your SSID"; 
-const char *password = "P4sswOrd"; 
- 
-WebServer server(80); 
- 
-void handleRoot() { 
-  String html = "<!DOCTYPE html>"; 
-  html += "<html>\n"; 
-  html += "<head>\n"; 
-  html += "<title>Server ESP32</title>\n"; 
-  html += "</head>\n"; 
-  html += "<body>\n"; 
-  html += "<h1>Hello world</h1>\n"; 
-  html += "</body>\n"; 
-  html += "</html>"; 
-  server.send(200, "text/html", html); 
-} 
- 
-void setup(void) { 
- 
-  Serial.begin(115200); 
-  while (!Serial) continue; 
- 
-  WiFi.begin(ssid, password); 
-  while (WiFi.status() != WL_CONNECTED) delay(500); 
-  Serial.print("Connected to "); 
-  Serial.println(ssid); 
-  Serial.print("IP address: "); 
-  Serial.println(WiFi.localIP()); 
- 
-  //if (MDNS.begin("esp32")) { 
-  //  Serial.println("MDNS responder started"); 
-  //} 
- 
-  server.on("/", handleRoot); 
- 
-  server.onNotFound([]() { 
-    server.send(404, "text/plain", "Not Found"); 
-  }); 
- 
-  server.begin(); 
-  Serial.println("HTTP server started"); 
-} 
- 
-void loop(void) { 
- 
-  server.handleClient(); 
- 
-  delay(2);  //allow the cpu to switch to other tasks 
- 
-} 
-</code> 
- 
-==== Client REST API ==== 
- 
-<code c> 
- 
-#include <WiFi.h> 
-#include <HTTPClient.h> 
-#include <ArduinoJson.h> 
- 
-void setup() { 
- 
-  Serial.begin(115200); 
-  while (!Serial) delay(100); 
- 
-  WiFi.begin("SSID", "P4ssw0rd"); 
-  while (WiFi.status() != WL_CONNECTED) delay(500); 
-  Serial.println("Connected."); 
-} 
- 
-void loop() { 
- 
-  if (WiFi.status() == WL_CONNECTED) { 
- 
-    HTTPClient http; 
- 
-    // https://docs.kraken.com/api/docs/rest-api/get-ticker-information 
-    http.begin("https://api.kraken.com/0/public/Ticker?pair=XXBTZEUR"); 
- 
-    int httpCode = http.GET(); 
- 
-    if (httpCode == HTTP_CODE_OK) { 
-       
-      String response = http.getString(); 
- 
-      JsonDocument doc; 
-      DeserializationError error = deserializeJson(doc, response); 
-      if (error) { 
-        Serial.print(F("deserializeJson() failed: ")); 
-        Serial.println(error.f_str()); 
-      } else { 
-        Serial.print("BTC: "); 
-        Serial.println(doc["result"]["XXBTZEUR"]["c"][0].as<double>()); 
-      } 
- 
-    } else { 
-     
-      Serial.printf("failed, error: %i %s\n", httpCode, http.errorToString(httpCode).c_str()); 
-       
-    } 
-     
-    http.end(); 
-     
-  } else { 
-   
-    Serial.println("Network unreachable"); 
-     
-  } 
- 
-  delay(5000); 
-} 
- 
-</code> 
- 
-==== Thread ==== 
- 
-<code c> 
-#include <WiFi.h> 
-#include <WebServer.h> 
-#include <HTTPClient.h> 
-#include <ArduinoJson.h> 
-#include <Thread.h> 
- 
-const char *ssid = "....."; 
-const char *password = "....."; 
- 
-float btc; 
- 
-Thread myThread = Thread(); 
- 
-void getBtcFromKraken() { 
- 
-  HTTPClient http; 
-   
-  http.begin("https://api.kraken.com/0/public/Ticker?pair=XXBTZEUR"); 
- 
-  int httpCode = http.GET(); 
-   
-  if (httpCode == HTTP_CODE_OK) { 
-    String response = http.getString(); 
- 
-    JsonDocument doc; 
-    DeserializationError error = deserializeJson(doc, response); 
-    if (!error) { 
-      btc = doc["result"]["XXBTZEUR"]["c"][0].as<float>(); 
-      Serial.print("BTC: "); 
-      Serial.println(btc); 
-    } 
-     
-  } 
- 
-  http.end(); 
-} 
- 
- 
-WebServer server(80); 
- 
- 
- 
-void handleRoot() { 
-  String html = "BTC = " + String(btc); 
-  server.send(200, "text/plain", html); 
-} 
- 
-void setup(void) { 
-  Serial.begin(115200); 
- 
-  WiFi.begin(ssid, password); 
-  while (WiFi.status() != WL_CONNECTED) delay(500); 
- 
-  Serial.print("Connected to "); 
-  Serial.println(ssid); 
-  Serial.print("IP address: "); 
-  Serial.println(WiFi.localIP()); 
- 
-  //if (MDNS.begin("esp32")) { 
-  //  Serial.println("MDNS responder started"); 
-  //} 
- 
- 
-  myThread.onRun(getBtcFromKraken); 
-  myThread.setInterval(10000); 
-  myThread.run(); 
- 
-  server.on("/", handleRoot); 
- 
-  server.onNotFound([]() { 
-    server.send(404, "text/plain", "Not Found"); 
-  }); 
- 
-  server.begin(); 
-  Serial.println("HTTP server started"); 
-} 
- 
-void loop(void) { 
-  if (myThread.shouldRun()) myThread.run(); 
-  Serial.print("."); 
-  server.handleClient(); 
-  delay(500);  //allow the cpu to switch to other tasks 
-} 
- 
-</code> 
esp32.1729425185.txt.gz · Last modified: 2024/10/20 11:53 by bruno