personas:johnny:proyectos:esp8266
Diferencias
Muestra las diferencias entre dos versiones de la página.
Ambos lados, revisión anteriorRevisión previaPróxima revisión | Revisión previa | ||
personas:johnny:proyectos:esp8266 [2019/06/01 08:09] – [conectar ESp8266 a telegram] kz | personas:johnny:proyectos:esp8266 [2019/06/04 19:14] (actual) – [Conexión pantalla oled SSD1306] kz | ||
---|---|---|---|
Línea 1: | Línea 1: | ||
- | ====== Configuración inicial, blink con ESP8266 | + | ====== Configuración inicial |
===== Materiales ===== | ===== Materiales ===== | ||
Línea 122: | Línea 122: | ||
- | {{ : | + | {{ : |
Línea 234: | Línea 234: | ||
http:// | http:// | ||
+ | |||
+ | ====== Simple led on off página incrustada en código ====== | ||
+ | |||
+ | <code c++> | ||
+ | |||
+ | #include < | ||
+ | |||
+ | const char* ssid = "Your SSID"; | ||
+ | const char* password = "Your password"; | ||
+ | |||
+ | int ledPin = 13; | ||
+ | WiFiServer server(80); | ||
+ | |||
+ | void setup() { | ||
+ | | ||
+ | pinMode(ledPin, | ||
+ | digitalWrite(ledPin, | ||
+ | |||
+ | Serial.begin(115200); | ||
+ | Serial.println(); | ||
+ | Serial.print(" | ||
+ | Serial.println( ssid ); | ||
+ | |||
+ | WiFi.begin(ssid, | ||
+ | |||
+ | Serial.println(); | ||
+ | Serial.print(" | ||
+ | |||
+ | while( WiFi.status() != WL_CONNECTED ){ | ||
+ | delay(500); | ||
+ | Serial.print(" | ||
+ | } | ||
+ | |||
+ | | ||
+ | Serial.println(); | ||
+ | |||
+ | Serial.println(" | ||
+ | Serial.print(" | ||
+ | Serial.println(WiFi.localIP() ); | ||
+ | |||
+ | server.begin(); | ||
+ | Serial.println(" | ||
+ | |||
+ | // Print the IP address | ||
+ | Serial.print(" | ||
+ | Serial.print(" | ||
+ | Serial.print(WiFi.localIP()); | ||
+ | Serial.println("/" | ||
+ | | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | |||
+ | // Check if a client has connected | ||
+ | WiFiClient client = server.available(); | ||
+ | if (!client) { | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | // Wait until the client sends some data | ||
+ | Serial.println(" | ||
+ | while(!client.available()){ | ||
+ | delay(1); | ||
+ | } | ||
+ | |||
+ | // Read the first line of the request | ||
+ | String request = client.readStringUntil(' | ||
+ | Serial.println(request); | ||
+ | client.flush(); | ||
+ | |||
+ | // Match the request | ||
+ | |||
+ | int value = LOW; | ||
+ | if (request.indexOf("/ | ||
+ | digitalWrite(ledPin, | ||
+ | value = HIGH; | ||
+ | } | ||
+ | if (request.indexOf("/ | ||
+ | digitalWrite(ledPin, | ||
+ | value = LOW; | ||
+ | } | ||
+ | |||
+ | // Set ledPin according to the request | ||
+ | // | ||
+ | |||
+ | // Return the response | ||
+ | client.println(" | ||
+ | client.println(" | ||
+ | client.println("" | ||
+ | client.println("< | ||
+ | client.println("< | ||
+ | |||
+ | client.print(" | ||
+ | |||
+ | if(value == HIGH) { | ||
+ | client.print(" | ||
+ | } else { | ||
+ | client.print(" | ||
+ | } | ||
+ | client.println("< | ||
+ | client.println("< | ||
+ | client.println("< | ||
+ | client.println("</ | ||
+ | |||
+ | delay(1); | ||
+ | Serial.println(" | ||
+ | Serial.println("" | ||
+ | | ||
+ | } | ||
+ | |||
+ | </ | ||
====== Cómo programar sensor AQA en rama AQAkit ====== | ====== Cómo programar sensor AQA en rama AQAkit ====== | ||
Línea 287: | Línea 398: | ||
#include < | #include < | ||
- | static const char ssid[] = "manunderworld"; | + | static const char ssid[] = "-------"; |
- | static const char password[] = "alex1988alex"; | + | static const char password[] = "-------"; |
MDNSResponder mdns; | MDNSResponder mdns; | ||
Línea 509: | Línea 620: | ||
#define USE_SERIAL Serial | #define USE_SERIAL Serial | ||
- | static const char ssid[] = "manunderworld"; | + | static const char ssid[] = "-------"; |
- | static const char password[] = "alex1988alex"; | + | static const char password[] = "---------"; |
MDNSResponder mdns; | MDNSResponder mdns; | ||
Línea 888: | Línea 999: | ||
{{: | {{: | ||
- | ===== código telegram bot esp8266c | + | ===== código telegram bot esp8266 |
Se usa esta librería para el [[https:// | Se usa esta librería para el [[https:// | ||
Línea 1005: | Línea 1116: | ||
</ | </ | ||
+ | |||
+ | ====== conexionado de algunos sensores ====== | ||
+ | |||
+ | ===== Conexión relevador ===== | ||
+ | |||
+ | Se puede reemplazar el transistor de la imagen por un ** 2N2222 **. para ensayar el Relay, se puede usar el código __blink__ de arduino | ||
+ | |||
+ | {{: | ||
+ | |||
+ | ===== Conexión DTH11 ===== | ||
+ | |||
+ | Este sensor es un sensor de temperatura y humedad en el aire.Toda la información para conectar el sensor en este [[http:// | ||
+ | |||
+ | {{: | ||
+ | |||
+ | Así conectamos el sensor al arduino o al esp. La resistencia tiene de que ser 10K | ||
+ | |||
+ | {{: | ||
+ | |||
+ | El código que necesitamos para leer los valores del sensor es este: | ||
+ | |||
+ | <code c++> | ||
+ | #include < | ||
+ | |||
+ | dht DHT; | ||
+ | |||
+ | #define DHT11_PIN 7 | ||
+ | |||
+ | void setup(){ | ||
+ | Serial.begin(9600); | ||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | int chk = DHT.read11(DHT11_PIN); | ||
+ | Serial.print(" | ||
+ | Serial.println(DHT.temperature); | ||
+ | Serial.print(" | ||
+ | Serial.println(DHT.humidity); | ||
+ | delay(1000); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Conexión LM35 ===== | ||
+ | |||
+ | [[https:// | ||
+ | a toda la información. En este caso hemos optado por un sensor bastante normal que detecta temperaturas desde -55ºC a 150ºC, 1ºC equivale a 10mV y soporta voltajes de entre 4V y 30V. Todo esta información se ha obtenido de la ficha técnica del LM35. | ||
+ | |||
+ | {{: | ||
+ | |||
+ | <code c++> | ||
+ | /* | ||
+ | Creado: Luis del Valle (ldelvalleh@programarfacil.com) | ||
+ | https:// | ||
+ | */ | ||
+ | |||
+ | // Declaracion de variables globales | ||
+ | float tempC; // Variable para almacenar el valor obtenido del sensor (0 a 1023) | ||
+ | int pinLM35 = 0; // Variable del pin de entrada del sensor (A0) | ||
+ | |||
+ | void setup() { | ||
+ | // Cambiamos referencia de las entradas analógicas | ||
+ | analogReference(INTERNAL); | ||
+ | | ||
+ | // Configuramos el puerto serial a 9600 bps | ||
+ | Serial.begin(9600); | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | // Con analogRead leemos el sensor, recuerda que es un valor de 0 a 1023 | ||
+ | tempC = analogRead(pinLM35); | ||
+ | |||
+ | // Calculamos la temperatura con la fórmula | ||
+ | tempC = (1.1 * tempC * 100.0)/ | ||
+ | |||
+ | // Envia el dato al puerto serial | ||
+ | Serial.print(tempC); | ||
+ | // Salto de línea | ||
+ | Serial.print(" | ||
+ | | ||
+ | // Esperamos un tiempo para repetir el loop | ||
+ | delay(1000); | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Conexión pantalla oled SSD1306 ===== | ||
+ | |||
+ | {{: | ||
+ | |||
+ | Links con información interesante: | ||
+ | |||
+ | - [[https:// | ||
+ | - [[https:// | ||
+ | - [[https:// | ||
+ | |||
+ | Este es el esquema de conexión: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | Este código funciona con la librería de adafruit. | ||
+ | |||
+ | <code c++> | ||
+ | /* | ||
+ | * Demo for SSD1306 based 128x64 OLED module using Adafruit SSD1306 | ||
+ | * library (https:// | ||
+ | | ||
+ | * See https:// | ||
+ | * for more information. | ||
+ | * | ||
+ | */ | ||
+ | |||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | // If using software SPI (the default case): | ||
+ | #define OLED_MOSI | ||
+ | #define OLED_CLK | ||
+ | #define OLED_DC | ||
+ | #define OLED_CS | ||
+ | #define OLED_RESET 10 | ||
+ | |||
+ | Adafruit_SSD1306 display(OLED_MOSI, | ||
+ | |||
+ | void setup() | ||
+ | // Serial.begin(9600); | ||
+ | display.begin(SSD1306_SWITCHCAPVCC); | ||
+ | display.display(); | ||
+ | delay(1000); | ||
+ | display.clearDisplay(); | ||
+ | display.setTextSize(1); | ||
+ | display.setTextColor(WHITE); | ||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | static unsigned long thisMicros = 0; | ||
+ | static unsigned long lastMicros = 0; | ||
+ | display.clearDisplay(); | ||
+ | display.setCursor(0, | ||
+ | display.print(" | ||
+ | display.print(" | ||
+ | display.print(thisMicros - lastMicros); | ||
+ | display.print(" | ||
+ | display.display(); | ||
+ | lastMicros = thisMicros; | ||
+ | thisMicros = micros(); | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | {{: | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
personas/johnny/proyectos/esp8266.txt · Última modificación: 2019/06/04 19:14 por kz