NodeMCU ESP8266 and OLED 0.96 Tutorial for Beginner
ฝัง
- เผยแพร่เมื่อ 18 พ.ย. 2017
- NodeMCU ESP8266 and OLED 0.96 Tutorial for Beginner
This tutorial setup NodeMCU ESP8266 dev kit v3 with OLED 0.96 inch
128x64
Source code
github.com/jumejume1/Arduino/... ::::::::::: SUPPORT CHANNEL ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Please Donate To Help Me Afford New Equipment And Software To Make My Videos More : goo.gl/1m8Dg2
Don't forget to subscribe! - วิทยาศาสตร์และเทคโนโลยี
HEY THANKS FOR POSTING THIS VIDEO .IT HAS HELPED ME A LOT!!!!!!!
Thank You for time and effort!
Good luck. From Spain.
gracias!
Do you have an email I can contact you with for advice?
ESP8266-12F+WIFI+OLED 0.96 SPI 7 PINES
Code:
/*ESP8266 NODECU conectamos el DHT11 a 5vol y GND igual la OLED
del ESP8266-12E, la señal DHT11 al D6 GPIO 12
OLED ESP8266
#define OLED_MOSI 13 //D7 GPIO13 los Dx son los pines del esp8266
#define OLED_CLK 14 //D5 GPIO14 los GPIO los del programa
#define OLED_DC 4 //D2 GPIO4 los define los pines de Oled
#define OLED_CS 15 //D8 GPIO15
#define OLED_RESET 5 //D1 GPIO5
Abrir el monitor serial y resetear con el
boton del nodecu, veremos la IP:192.168.0.103
Segun el modulo utilizado, ir al navegador chrome
salen los datos IGUAL EN LA OLED
por RAMON 07/07/2019
*/
//-----------------------------------------------ESP8266
#include
const char* ssid = "XXXXXXXXXXX"; // Reemplazar con usuario y clave de su red
const char* password = "XXXXXXX";
WiFiServer server(80); // Objeto Servidor Web en puerto 80
//--------------------------------------------------SPI
#include //Bus SPI
#include
//--------------------------------------------------OLED
#include // GRAFICA
#include //biblioteca SSD1306 editada con 128X64
//Declaración para display SSD1306 display por software SPI y 5 PINES DECLARADOS
#define SCREEN_WIDTH 128 // OLED display width, in pixels DEPENDE DE LA PANTALLA
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_MOSI 13 //D7 GPIO13 los Dx son los pines del esp8266 los GPIO los del programa
#define OLED_CLK 14 //D5 GPIO14
#define OLED_DC 4 //D2 GPIO4
#define OLED_CS 15 //D8 GPIO15
#define OLED_RESET 5 //D1 GPIO5
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
//-----------------------------------------------DHT11
#include
#define DHTTYPE DHT11 //Se declara el TIPO del sensor DHT 11
int t; // variable para almacenar valor de temperatura sin decimales por Oled(espacio)
int h; // variable para almacenar valor de humedad
const int SENSOR = 12; // D6 GPIO 12 Sensor DHT
DHT dht(SENSOR, DHTTYPE); // Inicializar Sensor DHT se crea el objeto dht
//-------------------------------------------------------------------------------------
void setup() {
Serial.begin(115200); // Inicializar puerto serial
dht.begin(); //Inicializar DHT11
//---------------------------------------------------------OLED
if (!display.begin(SSD1306_SWITCHCAPVCC)) { // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
Serial.println(F("SSD1306 INICIO FALLIDO"));
for (;;); // Bucle infinito
}
// Show initial display buffer contents on the screen LOGO
// the library initializes this with an Adafruit splash screen.
//display.display();
//delay(2000); // Pausa 2 seg
display.clearDisplay(); // Limpia el buffer
display.drawPixel(64, 32, WHITE); // Dibuja un pixel azúl en (68,32)
display.display();
delay(2000);
display.invertDisplay(true); // Invierte la pantalla y la vuelve a invertir con una pausa de 1 seg
delay(1000);
display.invertDisplay(false);
delay(1000);
//-----------------------------------------------------------ESP8266
// Conectando con la red WiFi
Serial.println();
Serial.print("Conectando con ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi conectado");
// Arranque del servidor Web
server.begin();
Serial.println("Direccion IP:");
delay(10000);
// Imprimiendo direccion IP
Serial.println(WiFi.localIP());
}
//-------------------------------------------------------------
void loop() {
//------------------------------------------------ESP8266
WiFiClient client = server.available(); // Esperando por nuevos clientes
if (client) {
Serial.println("Nuevo cliente");
boolean line = true; // Boleano para identificar cuando finaliza la solicitud HTTP
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (c == '
' && line) {
h = dht.readHumidity(); // Humedad
t = dht.readTemperature(); //Temperatura en Celsius
if (isnan(h) || isnan(t)) { // Verifique si alguna lectura falló (intentar de nuevo).
Serial.println("Fallo al leer el sensor DHT11");
return;
}
///////////////////HTML//////////////////////////////
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
// Servidor Web muestra datos de temperatura y humedad
client.println("");
client.println("");
client.println("Enviando datos al servidor Web con DHT y ESP8266");
client.println("Temperatura: ");
client.println(t);
client.println("*C");
client.println("Humedad: ");
client.println(h);
client.println("%");
client.println("");
break;
}
if (c == '
') {
// Cuando comienza a leer una nueva linea
line = true;
}
else if (c != '
') {
// Cuando en encuntra un caracter en la línea actual
line = false;
}
}
}
// closing the client connection
delay(1);
client.stop();
Serial.println("Cliente desconectado");
}
h = dht.readHumidity();
t = dht.readTemperature(); //Temperatura en Celsius
SENSORDHT11(); // PANTALLA OLED LLAMADA FUNCION
}
//-----------FUNCION QUE DIBUJA LOS DATOS DHT11
void SENSORDHT11(void) {
display.clearDisplay();
display.setTextSize(2); // ESCALA 1:2 pixel scale 2x
display.setTextColor(WHITE);
display.setCursor(2, 0);
display.print("Temp C: ");
display.print(t);
display.setCursor(2, 30);
display.print("Hum %: ");
display.print(h);
display.display();
delay(1000);
}
Hi !
No http over TLS = not secure !
Thank You for time and effort!