Arduino, esp-01 and display 16x2

groundFungus:
Here is a test sketch for an ESP8266 and Uno to illustrate software serial between the 2 and display the data sent by the ESP to the Uno on a LCD. Tested and prints the data from ESP to LCD connected to Uno. Not perfect but should work for testing the hardware and as a basis for future code. NOTE: change the LCD constructor and software serial pins as necessary.

The Uno code.

#include <LiquidCrystal.h>

#include <SoftwareSerial.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
SoftwareSerial esp(8, 9);

char inputBuffer[17]; // one LCD line + NULL
int strIndex = 0;

void setup()
{
  Serial.begin(115200);
  esp.begin(38400);
  lcd.begin(16, 2);
  lcd.print("LCD  UP");
  delay(2000);
}

void loop()
{
  if (esp.available())
  {
    char c = esp.read();
    if (c != '\n')
    {
      Serial.print(c);
      inputBuffer[strIndex] = c;
      strIndex++;
      inputBuffer[strIndex] = '\0';
    }
    else
    {
      Serial.println();
      lcd.clear();
      lcd.print(inputBuffer);
      strIndex = 0;
      inputBuffer[strIndex] = '\0';
    }
  }
}




The ESP code:



void setup()
{
  Serial.begin(38400);
}

void loop()
{
  static unsigned long timer = 0;
  unsigned long interval = 1000;
  static unsigned int index = 0;
  if (millis() - timer >= interval)
  {   
    timer = millis();
    Serial.print("The index ");
    Serial.println(index);
    index++;
  }
}




The circuit:

![ESP-UNO TEST.jpg|1500x1328](upload://3ftX4DFS6hOi0VtPb8m3GS6jybs.jpeg)

Tell me if i what i think is right.

So i take the esp code, i upload it while the esp is on, after that i disconnect the esp, i upload the code of the display on the arduino, then i connect the esp back ?