Node MCU ESP 8266 Text To I2C LCD Example

Go down

Node MCU ESP 8266 Text To I2C LCD Example Empty Node MCU ESP 8266 Text To I2C LCD Example

Post by jamied_uk on 15th August 2017, 03:46




Code:
// (c) J~NET
// jnet.forumotion.com/t1549-node-mcu-esp-8266-text-to-i2c-lcd-example#2350
// https://tttapa.github.io/ESP8266/Chap10%20-%20Simple%20Web%20Server.html
// https://startingelectronics.org/tutorials/arduino/web-page-to-LCD

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x38, 16, 2);

// Clear Serial Buffer
void serialFlush(){  
 while(Serial.available() > 0) {    
 char text_display = Serial.read();  
 }
}

// #define OLED_RESET 4

const char* ssid = "WIFI-AP-NAME";
const char* password = "WIFI-AP-PASSWORD";

ESP8266WebServer server(80);

const int output1 = 14;
const int output2 = 12;
const int output3 = 13;
const int output4 = 15;

boolean device1 = false;
boolean device2 = false;
boolean device3 = false;
boolean device4 = false;

void handleRoot() {
  //digitalWrite(led, 1);
  http://server.send(200, "text/plain", "hello from esp8266!");
  //digitalWrite(led, 0);
  http://server.send(200, "text/plain", "<!DOCTYPE HTML>\r\n");
  String msg;
  String cmd;    
      cmd += "<!DOCTYPE HTML>\r\n";
      cmd += "<html>\r\n";
      cmd += "<header><title>I2C LCD Text Server</title>";
      cmd += "<head>";
      cmd += "<h1>\"I2C LCD Text Server\"</h1></header>";
      cmd += "</head>";
      cmd += "<form action=\"/submit\">Text To Display:<br><input type=\"text\" name=\"text_display\"><br><input type=\"submit\" value=\"Submit\"></form>";
      server.send(200, "text/html", cmd);

}

void handleNotFound(){
  //digitalWrite(led, 1);
  String message = "File Not Found\n\n";
  String msg;
  // char readString = client.read();
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_POST)?"GET":"POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i=0; i<server.args(); i++){
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
    // put message into lcd
    lcd.clear();
   // message myArray[] = message;
    lcd.print(server.arg(4)); // text_display
    msg = server.arg(0); //
    lcd.print(msg); // text_display
    // add delay and scroll effects here
    handleRoot();

  }
  server.send(404, "text/plain", message);
  //digitalWrite(led, 0);
}

void setup(void){
  lcd.begin();
  lcd.backlight();
  // lcd.print("Please Wait...");
 
  pinMode(output1, OUTPUT);
  pinMode(output2, OUTPUT);
  pinMode(output3, OUTPUT);
  pinMode(output4, OUTPUT);

  digitalWrite(output1, LOW);
  digitalWrite(output2, LOW);
  digitalWrite(output3, LOW);
  digitalWrite(output4, LOW);
  
  Serial.begin(115200);
  WiFi.mode(WIFI_STA); // comment out this line to NOT use a router as an AP
  WiFi.begin(ssid, password);
  http://lcd.print("");

  Serial.println("IP:");
  Serial.println(WiFi.localIP());

  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  http://display.begin(SSD1306_SWITCHCAPVCC, 0x3D);      // initialize with the I2C addr 0x3D (for the 128x64)

  delay(2000);

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
 // Serial.print(".");
    // lcd.print("Please Wait...");


  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  lcd.print(WiFi.localIP());
  Serial.println(WiFi.localIP());

  if (MDNS.begin("esp8266")) {
    Serial.println("MDNS responder started");
  }

  server.on("/", handleRoot);

 // server.on("/submit", handleSubmit);

  if (server.args() > 0 ) {
    for ( uint8_t i = 0; i < server.args(); i++ ) {
      if (server.argName(i) == "text_display") {
        // server.arg("text_display");
         // do something here with value from server.arg(i);
         // output text to serial console & lcd
         Serial.println("text_display");
         lcd.print("text_display");

        
      }
   }
}

  server.onNotFound(handleNotFound);
  server.begin();
  Serial.println("HTTP server started");
}

void loop(void){
  server.handleClient();
}


Now im working on a scroll after a short delay, I think this will look smart so watch out for part 2 Smile
More info about scroll here arduino.cc/en/Tutorial/LiquidCrystalScroll


Last edited by jamied_uk on 15th August 2017, 05:09; edited 3 times in total
jamied_uk
jamied_uk
Admin

Posts : 2471
Join date : 2010-05-09
Age : 36
Location : UK

http://address-shortner.co.uk

Back to top Go down

Node MCU ESP 8266 Text To I2C LCD Example Empty Re: Node MCU ESP 8266 Text To I2C LCD Example

Post by jamied_uk on 15th August 2017, 04:23

Please remember to unplug after uploading new web servers to esp and plug back in give it 20 seconds or so and then goto the ip!
jamied_uk
jamied_uk
Admin

Posts : 2471
Join date : 2010-05-09
Age : 36
Location : UK

http://address-shortner.co.uk

Back to top Go down

Node MCU ESP 8266 Text To I2C LCD Example Empty Re: Node MCU ESP 8266 Text To I2C LCD Example

Post by jamied_uk on 15th August 2017, 04:46

Also you can post to this server from another system via command line


Code:
curl --data "param1=value1¶m2=value2" http://hostname/resource

Example:

Code:
curl --data "text_display=TEXT-HERE" 192.168.0.100/



For more info see
askubuntu.com/questions/299870/http-post-and-get-using-curl-in-linux
jamied_uk
jamied_uk
Admin

Posts : 2471
Join date : 2010-05-09
Age : 36
Location : UK

http://address-shortner.co.uk

Back to top Go down

Node MCU ESP 8266 Text To I2C LCD Example Empty Re: Node MCU ESP 8266 Text To I2C LCD Example

Post by jamied_uk on 15th August 2017, 16:25

Send Text To LCD Display With Linux Command Line Or Script




Code:
#!/bin/bash
# (c) J~NET 2017
# ./run.sh
# jnet.forumotion.com/t1549-node-mcu-esp-8266-text-to-i2c-lcd-example#2352
#
echo "Input Text To Send To LCD"
read uin
curl --data "text_display=$uin" 192.168.0.62/submit
clear
echo "Text Sent"
#
jamied_uk
jamied_uk
Admin

Posts : 2471
Join date : 2010-05-09
Age : 36
Location : UK

http://address-shortner.co.uk

Back to top Go down

Node MCU ESP 8266 Text To I2C LCD Example Empty Re: Node MCU ESP 8266 Text To I2C LCD Example

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum