displaying text from webpage to lcd

its not showing anything on lcd.

its not showing any error also.

can anyone help me for modifying this code

#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include "rgb_lcd.h"
#include <Wire.h>
rgb_lcd lcd;

#define REQ_BUF_SZ   90

#define LCD_BUF_SZ   17


byte mac[] = { 
  0x98, 0x4F, 0xEE,0x01, 0x65, 0x4E };
IPAddress ip(192,168,19,170);
String readString;



EthernetServer server(80);      // create a server at port 80
File webFile;                    // the web page file on the SD card
char HTTP_req[REQ_BUF_SZ] = {0}; // buffered HTTP request stored as null terminated string
char req_index = 0;              // index into HTTP_req buffer
char lcd_buf_1[LCD_BUF_SZ] = {0};// buffer to save LCD line 1 text to
char lcd_buf_2[LCD_BUF_SZ] = {0};// buffer to save LCD line 2 text to
//LiquidCrystal lcd(3, 2, 8, 7, 6, 5);

void setup()
{
    // disable Ethernet chip
    pinMode(10, OUTPUT);
    digitalWrite(10, HIGH);
    
    Serial.begin(115200);       // for debugging

    lcd.begin(16, 2);
    // Message on LCD
    lcd.print(F("Initializing"));
    
    // initialize SD card
    Serial.println("Initializing SD card...");
    if (!SD.begin(4)) {
        Serial.println("ERROR - SD card initialization failed!");
        lcd.print(F("SD init failed"));
        return;    // init failed
    }
    Serial.println("SUCCESS - SD card initialized.");
    // check for index.htm file
    if (!SD.exists("index.htm")) {
        Serial.println("ERROR - Can't find index.htm file!");
        return;  // can't find index file
    }
    Serial.println("SUCCESS - Found index.htm file.");

    Ethernet.begin(mac, ip);  // initialize Ethernet device
    server.begin();           // start to listen for clients

    // End of initialization message on LCD + print IP address
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(F("Done."));
    lcd.setCursor(0, 1);
    lcd.print(ip);
}

void loop()
{
    EthernetClient client = server.available();  // try to get client

    if (client) {  // got client?
        boolean currentLineIsBlank = true;
        while (client.connected()) {
            if (client.available()) {   // client data available to read
                char c = client.read(); // read 1 byte (character) from client
                // limit the size of the stored received HTTP request
                // buffer first part of HTTP request in HTTP_req array (string)
                // leave last element in array as 0 to null terminate string (REQ_BUF_SZ - 1)
                if (req_index < (REQ_BUF_SZ - 1)) {
                    HTTP_req[req_index] = c;          // save HTTP request character
                    req_index++;
                }
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                if (c == '\n' && currentLineIsBlank) {
                    // send a standard http response header
                    client.println("HTTP/1.1 200 OK");
                    // remainder of header follows below, depending on if
                    // web page or XML page is requested
                    // Ajax request - send XML file
                    if (StrContains(HTTP_req, "ajax_inputs")) {
                        // send rest of HTTP header
                        client.println("Content-Type: text/xml");
                        client.println("Connection: keep-alive");
                        client.println();

                        // print the received text to the LCD if found
                        if (GetLcdText(lcd_buf_1, lcd_buf_2, LCD_BUF_SZ)) {
                          // lcd_buf_1 and lcd_buf_2 now contain the text from
                          // the web page
                          // write the received text to the LCD
                          lcd.clear();
                          lcd.setCursor(0, 0);
                          lcd.print(lcd_buf_1);
                          lcd.setCursor(0, 1);
                          lcd.print(lcd_buf_2);
                        }
                    }
                    else {  // web page request
                        // send rest of HTTP header
                        client.println("Content-Type: text/html");
                        client.println("Connection: keep-alive");
                        client.println();
                        // send web page
                        webFile = SD.open("index.htm");        // open web page file
                        if (webFile) {
                            while(webFile.available()) {
                                client.write(webFile.read()); // send web page to client
                            }
                            webFile.close();
                        }
                    }
                    // reset buffer index and all buffer elements to 0
                    req_index = 0;
                    StrClear(HTTP_req, REQ_BUF_SZ);
                    break;
                }
                // every line of text received from the client ends with \r\n
                if (c == '\n') {
                    // last character on line of received text
                    // starting new line with next character read
                    currentLineIsBlank = true;
                } 
                else if (c != '\r') {
                    // a text character was received from client
                    currentLineIsBlank = false;
                }
            } // end if (client.available())
        } // end while (client.connected())
        delay(1);      // give the web browser time to receive the data
        client.stop(); // close the connection
    } // end if (client)
}

// get the two strings for the LCD from the incoming HTTP GET request
boolean GetLcdText(char *line1, char *line2, int len)
{
  boolean got_text = false;    // text received flag
  char *str_begin;             // pointer to start of text
  char *str_end;               // pointer to end of text
  int str_len = 0;
  int txt_index = 0;
  char *current_line;

  current_line = line1;

  // get pointer to the beginning of the text
  str_begin = strstr(HTTP_req, "&L1=");

  for (int j = 0; j < 2; j++) { // do for 2 lines of text
    if (str_begin != NULL) {
      str_begin = strstr(str_begin, "=");  // skip to the =
      str_begin += 1;                      // skip over the =
      str_end = strstr(str_begin, "&");

      if (str_end != NULL) {
        str_end[0] = 0;  // terminate the string
        str_len = strlen(str_begin);

        // copy the string to the buffer and replace %20 with space ' '
        for (int i = 0; i < str_len; i++) {
          if (str_begin[i] != '%') {
            if (str_begin[i] == 0) {
              // end of string
              break;
            }
            else {
              current_line[txt_index++] = str_begin[i];
              if (txt_index >= (len - 1)) {
                // keep the output string within bounds
                break;
              }
            }
          }
          else {
            // replace %20 with a space
            if ((str_begin[i + 1] == '2') && (str_begin[i + 2] == '0')) {
              current_line[txt_index++] = ' ';
              i += 2;
              if (txt_index >= (len - 1)) {
                // keep the output string within bounds
                break;
              }
            }
          }
        } // end for i loop
        // terminate the string
        current_line[txt_index] = 0;
        if (j == 0) {
          // got first line of text, now get second line
          str_begin = strstr(&str_end[1], "L2=");
          current_line = line2;
          txt_index = 0;
        }
        got_text = true;
      }
    }
  } // end for j loop

  return got_text;
}

// sets every element of str to 0 (clears array)
void StrClear(char *str, char length)
{
    for (int i = 0; i < length; i++) {
        str[i] = 0;
    }
}

// searches for the string sfind in the string str
// returns 1 if string found
// returns 0 if string not found
char StrContains(char *str, char *sfind)
{
    char found = 0;
    char index = 0;
    char len;

    len = strlen(str);
    
    if (strlen(sfind) > len) {
        return 0;
    }
    while (index < len) {
        if (str[index] == sfind[found]) {
            found++;
            if (strlen(sfind) == found) {
                return 1;
            }
        }
        else {
            found = 0;
        }
        index++;
    }

    return 0;
}

index.htm.txt (1.18 KB)

The title of your thread is "displaying text from webpage to LCD"
Where is the web server that you are going to contact to obtain this web page (IP address or hostname) ?

Having had a quick look at your code, it is still not clear what you are trying to achieve. You appear to be attempting to run a web server to publish information from an SD card.

Have you a more complete description of what you are trying to achieve ?

You have said you see nothing on the LCD screen. If you do not see the message "Initializing" on the LCD screen
then you are not even getting past the early part of setup().

Can you post a link to the sample code that you have based your solution on, or is the code you have posted here all your own design ?

i used code from this website

actually what i want is i have to read string from text file and have to display that string on lcd.

as i am not getting enough information on internet i thaught to modify the above code.

Just to be clear. Your immediate objective is to read data from a text file (which is stored on an SD card) and display the contents of the file on an LCD screen. Is that so ?

Well trying to hack code out of an extremely complex web application is a very difficult way to achieve what seems to be a simple task.

Have you written some fixed text to the LCD screen, e.g. "Hello World" ?
Have you already got a text file loaded onto the SD card which you can print to the serial console ?

do u have any code for reading text file and displaying on lcd(using sd card or without using sd card) actualy i am new to this and working on it from past few days.

Post a link to the exact LCD display you are using.
Step 1 will be to display "Hello World" on that display.

Just let us know what display you are using.
Here is an example Basic 16x2 Character LCD - Black on Green 5V - LCD-00255 - SparkFun Electronics
and another: LCD Shield Kit w/ 16x2 Character Display - Only 2 pins used! [BLUE AND WHITE] : ID 772 : $19.95 : Adafruit Industries, Unique & fun DIY electronics and kits

Once that is clear, you can be helped with code to write something on that display.

i will tell the full part.
i have created one website.

actually i am doing iot project in that for one application what ever i wrote on text box on website it has to display on lcd.

i post the same thing in forum 4 or 5 days back.

one person suggested me to whatever u write in that text area box create one file to save that text and read that text file.

http://forum.arduino.cc/index.php?topic=432745.msg2983588#msg2983588

this is what he suggested in that forum

"Yes. It's pretty simple, really.

Forget about the Arduino for a while. Create a script, using php is fine, on the xamp server. Have that script write the data to a file.

Have the script return an html file containing a form containing a text field and a submit button, with an action that calls the same script.

Point the browser to the script. Verify that the form looks correct. Enter some text, and submit.

Check the contents of the file that the script wrote to/appended to. When the data in the file is added correctly, you'll know that the html with form is correct.

Then, you can make the Arduino serve up that same html. All it should do in response to a GET request is print the request data to the serial port.

When that works, store the GET request, and then print the stored GET request.

When that works, parse the stored GET request, to collect the data to display on the LCD. Print the scraped data.

When that works, print the data to the LCD."

i am using nokia 5110 lcd.

but as of now i will try for 16*2 lcd.

if i get proper output then i will modify it for nokia 5110 lcd.

I've just looked back and it appears you have opened a huge number of threads on this or strongly related issues which appear to belong to the same assignment .

Project Guidance / Re: displaying text from webpage to lcd
displaying text from webpage to lcd - Project Guidance - Arduino Forum

Project Guidance / Re: webpage to lcd without using sd card
webpage to lcd without using sd card - Project Guidance - Arduino Forum

Project Guidance / Re: can we read data from database?
can we read data from database? - Project Guidance - Arduino Forum

Project Guidance / text to lcd (aurduino+ethernet)
text to lcd (aurduino+ethernet) - Project Guidance - Arduino Forum

Project Guidance / Re: lcd+aurduino+ethernet
lcd+aurduino+ethernet - Project Guidance - Arduino Forum

Project Guidance / Re: textfile to aurduino
textfile to aurduino - Project Guidance - Arduino Forum

Project Guidance / Re: aurduino+ethernet+nokia5110+php
aurduino+ethernet+nokia5110+php - Project Guidance - Arduino Forum

Project Guidance / aurduino+nokia5110 lcdd
aurduino+nokia5110 lcdd - Project Guidance - Arduino Forum

You appear to have extreme difficulty in both accurately formulating your requirements clearly and in being consistent about the environment on which the solution has to function.

It looks like some sort of school work which you have attempted to distribute over various sub task and it presents a very confused picture.

If you are willing to pay for someone to help you, then the best course of action would be to open a (yet another) thread under "Gigs and Collaborations" Jobs and Paid Consultancy - Arduino Forum stating that you want to pay for help with a "web project" and then deal with the matter by personal messages with who whoever accepts the assignment from you.

Prudhvi:
do u have any code for reading text file and displaying on lcd(using sd card or without using sd card) actualy i am new to this and working on it from past few days.

I have several example terminal programs for a variety of GLCD: Nokia, ILI9341 here.

Ray

hey there, i have the same project going on. the code is same only i used an I2C on a 16x2 lcd. i have the same problem as u had. did u find any resolution to this? if do could u kindly share?