LiquidCrystal conflicts

Hello,

Here I’m writing as I’m getting desperate with my LiquidCrystal 2004A LCD (20x4).

I was doing a test with a temperature sensor mlx90614, each time I would mlx.begin();, the display would start printing random characters and breaking the display. The sensor was working, printing the temperature to the SerialPort but the LCD was full of random characters. So I thought, maybe I burnt the mlx by mistake, so ok, I’m going to try with a DHT and indeed. It was better and I could display the temperature and humidity on my LCD. Then I wanted to trigger functions based on the IR receiver, for example to change the information received on the LCD. Same problem! Working perfectly appart, working perfectly with all the others functions except the liquide crystal is totally broken. lcd.clear() and lcd.setCursor() won’t work anymore. If I comment the irrecv.decode, the problem is the same, if I comment the irrecv.enableIRIn, then the LiquidCrystal works perfect again.

Here is the full working code (with the irrecv calls commented out):

#include <LiquidCrystal.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ArduinoJson.h>
#include "DHT.h"
#include <IRremoteESP8266.h>
#include <IRrecv.h>
#include <IRutils.h>

#define DHTPIN D9
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

const uint16_t RECV_PIN = D6;
IRrecv irrecv(RECV_PIN);

LiquidCrystal lcd(D12, D11, D5, D4, D3, D2);

const int buzzer = D8;

const int b = 247;
const int c = 261;
const int d = 294;
const int dH = 311;
const int e = 329;
const int f = 349;
const int fH = 370;
const int g = 391;
const int gS = 415;
const int a = 440;
const int aS = 455;
const int cH = 523;
const int cSH = 554;
const int dSH = 622;
const int eH = 659;
const int fSH = 740;
const int gH = 784;
const int gSH = 830;
const int aH = 880;

HTTPClient http;
DynamicJsonDocument doc(1024);
decode_results results;

bool wifiReady = false;

float tempLM35;
int tempLM35Pin = A0;
float analogMvToCDivisor;

void setup()
{
  Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY);
  Serial.println();

  pinMode(buzzer, OUTPUT);
  
  dht.begin();
  
  lcd.begin(20, 4);

  analogMvToCDivisor = 0.48828125; // ((5000.0 / 1024.0) / 10.0); // mv / ADC sampling / 10mv/°C
  
  //irrecv.enableIRIn();
}

void loop() {
  connectWifi();
  lcd.clear();
  
  String datetime = getDatetimeFromWeb();
  writeDatetime(datetime);
  
  float h =  dht.readHumidity();
  float t =  dht.readTemperature();
  if(isnan(t) || isnan(h)){
    lcd.setCursor(0, 0);
    lcd.print("Failed to read from DHT");
  } else {
    lcd.setCursor(0, 0);
    lcd.print("Humidity:");
    lcd.print(h);
    lcd.print("%");
    lcd.setCursor(0, 1);
    lcd.print("Temp:");
    lcd.print(t);
    lcd.print("c");
  }
  /*
  if (irrecv.decode(&results)){
    switch (results.value) {
      case 0xFFC23D:
        Serial.println("play comme un voilier");
        playCommeUnVoilier();
        break;
      case 0XFF22DD:
        Serial.println("clear LCD");
        lcd.clear();
        break;
      case 0XFF02FD:
        Serial.println("fill LCD");
        lcd.setCursor(0, 0);
        lcd.print("Test.");
        break;
    }

    irrecv.resume();
  }*/
  
  tempLM35 = analogRead(tempLM35Pin) * analogMvToCDivisor;
  Serial.print("Temp LM23:");
  Serial.println(tempLM35);
  
  delay(1000);
}

void playCommeUnVoilier() {
  beep(b, 300);
  beep(e, 300);
  beep(fH, 300);
  
  beep(g, 900);
  beep(fH, 300);
  beep(g, 600);
  beep(a, 600);
  
  beep(fH, 1200);
  delay(300);
  beep(a, 300);
  beep(g, 300);
  beep(fH, 300);
  
  beep(e, 900);
  beep(g, 300);
  beep(fH, 600);
  beep(d, 600);
  
  beep(b, 1200);
  delay(300);
  beep(b, 300);
  beep(e, 300);
  beep(fH, 300);
  
  beep(g, 900);
  beep(fH, 300);
  beep(g, 600);
  beep(a, 600);
  
  beep(fH, 1200);
  delay(300);
  beep(a, 300);
  beep(g, 300);
  beep(fH, 300);
  
  beep(e, 900);
  delay(10);
  beep(e, 300);
  beep(dH, 600);
  beep(b, 600);
  
  beep(e, 1200);
}

void beep(int freq, int duration) {
  tone(buzzer, freq);
  delay(duration);
  noTone(buzzer);
}

void connectWifi() {
  if (wifiReady) {
    return;
  }

  WiFi.begin("Orange XXXXXXX", "XXXXXXXX");
  lcd.clear();
  Serial.print("Connecting");
  lcd.setCursor(0, 2);
  lcd.write("Connection...");
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println();

  Serial.print("Connected, IP address: ");
  Serial.println(WiFi.localIP());
  lcd.clear();
  lcd.setCursor(0, 2);
  lcd.write("Connected!");
  delay(1000);
  lcd.clear();
  wifiReady = true;
}


String getDatetimeFromWeb() {
  connectWifi();

  http.begin("http://worldtimeapi.org/api/timezone/Europe/Paris.json");
  int httpCode = http.GET();
  String payload = http.getString();
  DeserializationError error = deserializeJson(doc, payload);

  String datetime = doc["utc_datetime"];
  http.end();
  return datetime.substring(0, 19);
}

void writeDatetime(String datetime) {
  if(datetime && datetime != "null") {
    Serial.println("wd");
    lcd.setCursor(0, 2);
    lcd.write("Datetime: ");
    lcd.setCursor(0, 3);
    lcd.write(datetime.c_str());
  }
}

With the irrecv :

And the full setup:

Any help would be much appreciated as I’m out of ideas and of ressources (and read all libraries documentations, forums, etc…) ! And also a very beginner!

I can provide with more pictures if needed!

The pictures show that your not using an Arduino UNO but you failed to tell us what model you actually use. I also miss a complete wiring diagram, the pictures don't allow to see the connections clearly.

My guess is that you used one of the I2C signals to connect the LCD but that's only a wild guess without the necessary information.

Sorry about that.

I use a Wemos D1 ESP8266 board, a 2004A LCD display, a DHT11 temp/humidity sensor, a LM35 temp sensor, a simple piezo speaker, and finaly, a VS1838B infrared receiver.

Find the diagram here attached in PDF or here under as an image.

Thank you for your help! :slight_smile:

Untitled Sketch 2_bb.pdf (1.18 MB)

Ok. So what happened is that I changed the input and used D1 instead of D6 or D7 which I tried.
D6 breaks, D7 breaks, D1 works. Spent hours on this. If you have an explanation, I'd be very interested to understand this mysteries of Arduino.

Maybe in that way I would understand what is going on with my MLX90614 (which was plugged on SCL and SDA for I2C).