Arduino UNO and ESP8266 Project

Hello guys, this is my first post here, so I hope you can understand what I need advice for.

So, what I have to do is: I need to connect to a WiFi network, through an ESP8266-01, then to connect to an API to take a json file to parse it. So far so good. After I have the json file, or a certain variable I need from that json, I need to send it to the Arduino, in order to print it to and LCD afterwards.

What I have managed to do so far: I managed to program the ESP to take the json, parse it, and print it to the serial monitor in the Arduino IDE. Now I need help in taking the data via serial communication in the Arduino, to print it to the LCD. I have tried with SoftwareSerial, but it doesn't work, maybe i am doing something wrong. I attach here the code that i used to program the ESP.

EDIT: So this is the code i used to program the ESP

#include <HttpClient.h>
#include <ESP8266WiFi.h>


const char* ssid = "MERCUSYS_0392"; //Enter your Wi-Fi SSID
const char* password = "STEAUA123"; //Enter you Wi-Fi Password

String payload; //To store the JSON object as string
const String endpoint = "http://api.openweathermap.org/data/2.5/weather?q=Timisoara,ro&APPID=";
const String key = "52ac89c578549fc9806a451e8e66d792";
 

void setup () {
 
  Serial.begin(9600); //initialise serial monitor to send data to Arduino
  WiFi.begin(ssid, password); //connect to the network specified above 
  while (WiFi.status() != WL_CONNECTED) { //Wait till Wi-Fi is connected
    delay(1000);
    Serial.print("Connecting.."); //Print Connecting.. till connection is established  
  }
  Serial.println("Connected to the WiFi network");
  
 
}
 
void loop() {
  if (WiFi.status() == WL_CONNECTED) {
     //If Wi-Fi connected successfully 
    HTTPClient http;  //start a HTTPClinet as http 
    http.begin(endpoint + key); //Specify the URL
    int httpCode = http.GET();  //Make the request
 
    if (httpCode > 0) { //Check for the returning code
 
        String payload = http.getString();
        Serial.println(httpCode);
        //Serial.println(payload);
        //preluare date fisier JSON
        const size_t bufferSize = JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(1) + 2*JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(4) + JSON_OBJECT_SIZE(5) + JSON_OBJECT_SIZE(6) + JSON_OBJECT_SIZE(12) + 400;
DynamicJsonBuffer jsonBuffer(bufferSize);

const char* json = "{\"coord\":{\"lon\":21.23,\"lat\":45.75},\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"clear sky\",\"icon\":\"01n\"}],\"base\":\"stations\",\"main\":{\"temp\":276.16,\"pressure\":1012,\"humidity\":93,\"temp_min\":275.15,\"temp_max\":277.15},\"visibility\":10000,\"wind\":{\"speed\":3.6,\"deg\":290},\"clouds\":{\"all\":0},\"dt\":1544466600,\"sys\":{\"type\":1,\"id\":6926,\"message\":0.3671,\"country\":\"RO\",\"sunrise\":1544421933,\"sunset\":1544453439},\"id\":665087,\"name\":\"Timisoara\",\"cod\":200}";

JsonObject& root = jsonBuffer.parseObject(json);

float coord_lon = root["coord"]["lon"]; // 21.23
float coord_lat = root["coord"]["lat"]; // 45.75

JsonObject& weather0 = root["weather"][0];
int weather0_id = weather0["id"]; // 800
const char* weather0_main = weather0["main"]; // "Clear"
const char* weather0_description = weather0["description"]; // "clear sky"
const char* weather0_icon = weather0["icon"]; // "01n"

const char* base = root["base"]; // "stations"

JsonObject& main = root["main"];
float main_temp = main["temp"]; // 276.16
int main_pressure = main["pressure"]; // 1012
int main_humidity = main["humidity"]; // 93
float main_temp_min = main["temp_min"]; // 275.15
float main_temp_max = main["temp_max"]; // 277.15

int visibility = root["visibility"]; // 10000

float wind_speed = root["wind"]["speed"]; // 3.6
int wind_deg = root["wind"]["deg"]; // 290

int clouds_all = root["clouds"]["all"]; // 0

long dt = root["dt"]; // 1544466600

JsonObject& sys = root["sys"];
int sys_type = sys["type"]; // 1
int sys_id = sys["id"]; // 6926
float sys_message = sys["message"]; // 0.3671
const char* sys_country = sys["country"]; // "RO"
long sys_sunrise = sys["sunrise"]; // 1544421933
long sys_sunset = sys["sunset"]; // 1544453439

long id = root["id"]; // 665087
const char* name = root["name"]; // "Timisoara"
int cod = root["cod"]; // 200
//Print the variables thorugh serial monitor
Serial.print (name);
Serial.print(" ");//send the location details to Arduino
delay(100); //stability delay
Serial.print (main_temp);
Serial.print(" ");//send the temperature details to Arduino
delay(100); //stability delay






    }
    else {
      Serial.println("Error on HTTP request");
    }
 
    http.end(); //Free the resources
  }
 
  delay(30000);




 
 

  }

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile:

for your question the Uno part is relevant. the 'not working' SoftwareSerial. post that code

Ok, so I have managed to send the data from ESP to Arduino, it was a matter of baud rate i suppose.
Now what i can't manage to do is to prin the data to the lcd.

Here is the code i use:

#include <SoftwareSerial.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>


LiquidCrystal_I2C lcd(0x3F, 2,1,0,4,5,6,7,3, POSITIVE);
SoftwareSerial mySerial(3, 2); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.clear();
  
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  
  mySerial.begin(9600);
  while (mySerial.available())
    {
      lcd.write(mySerial.read());
    }
  
  
}

void loop() { // run over and over
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }  
}

Your code only writes to the LCD during setup(). I doubt that there is any data being sent by the esp at that time. In loop(), your code only writes to the serial monitor. Do you see the received data on the serial monitor?

I am not sure why you think you need the Uno. Just connect the LCD to the esp.

PaulRB:
Your code only writes to the LCD during setup(). I doubt that there is any data being sent by the esp at that time. In loop(), your code only writes to the serial monitor. Do you see the received data on the serial monitor?

I am not sure why you think you need the Uno. Just connect the LCD to the esp.

ESP-01 has 8 pins - pwr/gnd rx/tx GPIO-0/GPI-2 RST and GH_PD
although the ESP can be used as a wifi link, the ESP8266 chip it much more powerful than the Arduino, faster and with more memory.

The only thing it lacks is the number of I/O pins as an UNO. since it cannot run a serial display, you need to do something.

Use the Arduino as the interface for the 16 char, 2-line display as it seems you are
get a serial interface board for the ESP-01 to run the display
get an LCD that is I2C and for which you can address the pixels so you can use fonts and graphics.

To use the UNO and ESP-01 you will need to send the data from the ESP to the UNO, then print that from the UNO to the LCD.

BTW, A WEMOS-mini or NODEMCU offers more pins than the ESP-01.

I would offer that the ESP-01 can power a larger display that is I2C and not use a 16char, 2line display.

As a note, you may want to edit your post, bottom right of the post is where to find the edit or modify buttons.
then block/x-out your password and SSID when posting to the forum. Just a little bit more secure.

LiquidCrystal_I2C lcd(0x3F, 2,1,0,4,5,6,7,3, POSITIVE);

It looks to me like the OP already has an i2c adaptor for the LCD. The esp-01 should be able to drive this directly.

PaulRB:

LiquidCrystal_I2C lcd(0x3F, 2,1,0,4,5,6,7,3, POSITIVE);

It looks to me like the OP already has an i2c adaptor for the LCD. The esp-01 should be able to drive this directly.

Point goes to PaulRB

dave-in-nj:
Point goes to PaulRB

Thanks, but I wasn't trying to score points off you! Just wondering what the OP thinks the Uno is needed for. Maybe there are other components in the circuit. The Wemos is a great suggestion. I use them in more projects then any other kind of Arduino.