informatica:arduino:esp32
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| informatica:arduino:esp32 [2021/02/07 15:36] – created jose | informatica:arduino:esp32 [2022/10/24 22:12] (current) – jose | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ESP32 | + | ====== Ejemplos: ====== |
| + | **Estación Metereológica: | ||
| + | https:// | ||
| + | ====== Bateria bien montada ====== | ||
| + | https:// | ||
| + | |||
| + | ====== ESP32 ====== | ||
| {{: | {{: | ||
| + | |||
| + | ====== ARDUINO IDE ====== | ||
| + | Nos descargamos la última versión de Arduino IDE, tiene que ser por encima de la 1.6 | ||
| + | |||
| + | Descargamos un plugin para poder conectar con esp32: | ||
| + | |||
| + | https:// | ||
| + | |||
| + | https:// | ||
| + | |||
| + | Ponemos esta URL en file > preferences > Additional Boards Manager URLs: | ||
| + | https:// | ||
| + | |||
| + | Tarda un ratillo en descargárselas | ||
| + | |||
| + | Ahora vamos a tools > Board: “Arduino Uno” y seleccionamos Boards Manager. Buscamos esp32 y damos a install | ||
| + | |||
| + | En Tools > Board: “Arduino Uno” > ESP32 Arduino | ||
| + | |||
| + | Reiniciamos Arduino. Nos aseguramos que python apunte a python3 instalando python-is-python3 | ||
| + | sudo apt install python-is-python3 | ||
| + | |||
| + | Código de ejemplo. Conecta a wifi y nos da la ip. Una vez subido tenemos que reiniciar esp32 (desconectando usb) | ||
| + | |||
| + | < | ||
| + | |||
| + | #include < | ||
| + | |||
| + | const char* ssid = " | ||
| + | const char* password = " | ||
| + | |||
| + | void setup() { | ||
| + | Serial.begin(115200); | ||
| + | delay(10); | ||
| + | Serial.println(' | ||
| + | | ||
| + | WiFi.begin(ssid, | ||
| + | Serial.print(" | ||
| + | Serial.print(ssid); | ||
| + | |||
| + | while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect | ||
| + | delay(500); | ||
| + | Serial.print(' | ||
| + | } | ||
| + | |||
| + | Serial.println(' | ||
| + | Serial.println(" | ||
| + | Serial.print(" | ||
| + | Serial.println(WiFi.localIP()); | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | La salida que nos da es esta: | ||
| + | < | ||
| + | . | ||
| + | |||
| + | Connection established! | ||
| + | IP address: | ||
| + | |||
| + | </ | ||
| + | |||
| + | HAcer petición GET y POST | ||
| + | < | ||
| + | |||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | const char* ssid = " | ||
| + | const char* password = " | ||
| + | |||
| + | //Your Domain name with URL path or IP address with path | ||
| + | String serverName = " | ||
| + | |||
| + | // the following variables are unsigned longs because the time, measured in | ||
| + | // milliseconds, | ||
| + | unsigned long lastTime = 0; | ||
| + | // Timer set to 10 minutes (600000) | ||
| + | //unsigned long timerDelay = 600000; | ||
| + | // Set timer to 5 seconds (5000) | ||
| + | unsigned long timerDelay = 5000; | ||
| + | |||
| + | void setup() { | ||
| + | Serial.begin(115200); | ||
| + | |||
| + | WiFi.begin(ssid, | ||
| + | Serial.println(" | ||
| + | while(WiFi.status() != WL_CONNECTED) { | ||
| + | delay(500); | ||
| + | Serial.print(" | ||
| + | } | ||
| + | Serial.println("" | ||
| + | Serial.print(" | ||
| + | Serial.println(WiFi.localIP()); | ||
| + | |||
| + | Serial.println(" | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | //Send an HTTP POST request every 10 minutes | ||
| + | if ((millis() - lastTime) > timerDelay) { | ||
| + | //Check WiFi connection status | ||
| + | if(WiFi.status()== WL_CONNECTED){ | ||
| + | HTTPClient http; | ||
| + | |||
| + | String serverPath = serverName + "? | ||
| + | | ||
| + | // Your Domain name with URL path or IP address with path | ||
| + | http.begin(serverPath.c_str()); | ||
| + | | ||
| + | // Send HTTP GET request | ||
| + | int httpResponseCode = http.GET(); | ||
| + | | ||
| + | if (httpResponseCode> | ||
| + | Serial.print(" | ||
| + | Serial.println(httpResponseCode); | ||
| + | String payload = http.getString(); | ||
| + | Serial.println(payload); | ||
| + | } | ||
| + | else { | ||
| + | Serial.print(" | ||
| + | Serial.println(httpResponseCode); | ||
| + | } | ||
| + | // Free resources | ||
| + | http.end(); | ||
| + | } | ||
| + | else { | ||
| + | Serial.println(" | ||
| + | } | ||
| + | lastTime = millis(); | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ====== Python ====== | ||
| + | https:// | ||
| + | |||
| + | apt-get install esptool | ||
| + | |||
| + | Descargamos el firmware: | ||
| + | |||
| + | https:// | ||
| + | |||
| + | Descargo este: | ||
| + | | ||
| + | |||
| + | |||
| + | Para borrar la memoria. Si no sabemos el puerto, no lo ponemos y lo detecta, es / | ||
| + | esptool erase_flash | ||
| + | |||
| + | < | ||
| + | esptool.py v2.8 | ||
| + | Found 1 serial ports | ||
| + | Serial port / | ||
| + | Connecting........_ | ||
| + | Detecting chip type... ESP32 | ||
| + | Chip is ESP32D0WDQ6 (revision 1) | ||
| + | Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None | ||
| + | Crystal is 40MHz | ||
| + | MAC: f0: | ||
| + | Enabling default SPI flash mode... | ||
| + | Erasing flash (this may take a while)... | ||
| + | |||
| + | A fatal error occurred: ESP32 ROM does not support function erase_flash. | ||
| + | </ | ||
| + | |||
| + | Da error. Subimos el firmware que hemos descargado. Tarda un poco. Debería devolver un prompt pero no hace nada: | ||
| + | esptool write_flash 0x1000 esp32-idf3-20210202-v1.14.bin | ||
| + | |||
| + | < | ||
| + | esptool.py v2.8 | ||
| + | Found 1 serial ports | ||
| + | Serial port / | ||
| + | Connecting....... | ||
| + | Detecting chip type... ESP32 | ||
| + | Chip is ESP32D0WDQ6 (revision 1) | ||
| + | Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None | ||
| + | Crystal is 40MHz | ||
| + | MAC: f0: | ||
| + | Enabling default SPI flash mode... | ||
| + | Configuring flash size... | ||
| + | Auto-detected Flash size: 4MB | ||
| + | Erasing flash... | ||
| + | Took 2.39s to erase flash block | ||
| + | Wrote 1445888 bytes at 0x00001000 in 140.5 seconds (82.3 kbit/s)... | ||
| + | Hash of data verified. | ||
| + | |||
| + | Leaving... | ||
| + | Hard resetting via RTS pin... | ||
| + | </ | ||
| + | |||
| + | ====== Arduino IDE ====== | ||
| + | https:// | ||
| + | |||
| + | https:// | ||
| + | |||
| + | Ponemos esta URL en file > preferences > Additional Boards Manager URLs: | ||
| + | https:// | ||
| + | |||
| + | Ahora vamos a tools > Board: " | ||
| + | |||
| + | En Tools > Board: " | ||
| + | |||
| + | |||
| + | ====== Energia y consumo ====== | ||
| + | https:// | ||
| + | |||
| + | ====== Pantalla e-paper ====== | ||
| + | https:// | ||
informatica/arduino/esp32.1612712192.txt.gz · Last modified: by jose
