Various issues & inconsistencies using AZdelivery ESP32

Epiktete
Posts: 1
Joined: Wed Dec 02, 2020 2:21 pm

Various issues & inconsistencies using AZdelivery ESP32

Postby Epiktete » Wed Dec 02, 2020 3:06 pm

Hello,

I'm building an automated aquarium with a bunch of valves, LED, lights and sensors.

I'm using :
8 relay module board, which is working fine.
AZDelivery HD44780 1602 LCD, 16x2 LCD, linked to the ESP32 by I2C, which is working randomly
220V powered DC 24V Trotec power supply connected to two LM2596 in order to have DC12V and DC5V
MH-Z14 CO2 sensor linked to the ESP32 by UART
BME280, linked to the ESP32 by I2C, which is working randomly

I'm used to Arduino board and manage to work with them. With the ESP32 board I've bought, I have inconsistent results and different from tutos I've seen online using same code and wiring.

First weird thing,
I can't upload code if anything is connected to the Vin Pin, either supplying or draining current.
If the board is powered by my 5V DC supply (which might have a lot of ripple) at Vin AND the USB, I cannot upload code.
If the Vin pin is used to power the LCD module while the ESP32 is powered by USB, I cannot upload code.
The 5V from the LM2596 might be shitty, I've tried to put a 100µF capacitor between the 5V output and GND but it did nothing.


2nd weird thing,
If the 24V DC power supply is ON, that means that I have a bunch of sensor powered by it, these sensors may output something on the I2C and UART ESP32 pins.
When the 24V DC power supply is ON while I boot the ESP32, powered by USB cable and nothing connected to its Vin Pin, it keeps rebooting forever. Now, If I boot the ESP32, powered by USB, while the 24V DC power supply is OFF, it is booting properly and then I can turn ON the power supply and get my sensors to work.
You cannot boot this board if it receives any signal on its digital pins or any load on its Vin ?

3rd weird thing,
The LCD is giving me absolute random and inconsistent results. I've seen some tutos online such as this one :https://randomnerdtutorials.com/esp32-e ... duino-ide/
First thing to notice, the wiring shown in this tutorial just does not work, at least for my esp32 boards. The LCD is supplied with 5V while the digital pins work with 3,3V. I had to add a bidirectionnal level shifter to make it work. I'm using the LiquidCrystalDisplay_I2C library introduced in this tuto.
Now, it is not working anymore for some reasons, even with the simple code below :

Code: Select all

#include <LiquidCrystal_I2C.h>

// set the LCD number of columns and rows
int lcdColumns = 16;
int lcdRows = 2;

// set LCD address, number of columns and rows
// if you don't know your display address, run an I2C scanner sketch
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);  

void setup(){
  // initialize LCD
  lcd.init();
  // turn on LCD backlight                      
  lcd.backlight();
}

void loop(){
  // set cursor to first column, first row
  lcd.setCursor(0, 0);
  // print message
  lcd.print("Hello, World!");
  delay(1000);
  // clears the display to print new message
  lcd.clear();
  // set cursor to first column, second row
  lcd.setCursor(0,1);
  lcd.print("Hello, World!");
  delay(1000);
  lcd.clear(); 
}
It gives me gibberish or white rectangles. I'm using pin G21 for SDA and G22 for SCL.
Using the same code in my project give me random results, sometimes the LCD does not show anything, just "white squares", sometimes it shows gibberish, sometimes for some mysterious reasons it works properly for few tens of seconds before starting to show gibberish.
Also, I've another I2C sensor at another adress, the BME280, which sometimes gives good value, sometimes gives crap.
I've no possible hypothesis for such blatant randomness.

Here is the code of the full project

Code: Select all

//libraries
#include <LiquidCrystal_I2C.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <Wire.h>

//BME stuff
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme;
float temperature, humidity, pressure, altitude;

//Various PINs definition
#define MH_RST_PIN 33
#define MODE_PIN 18

//Relay board PINs definition
#define COMP_PIN 13
#define LED220V_PIN 12
#define VENT_PIN 14
#define VALVECO2_PIN 27
#define LED24V_PIN 26
#define VALVEH2O_PIN 4

//HMI LED PINs definition
#define LED_ERROR_PIN 19
#define LED_VENT_PIN 0
#define LED_UPH2O_PIN 36
#define LED_UPCO2_PIN 2
#define LED_HIGHCO2_PIN 39
#define LED_LIGHT_PIN 5
#define LED_COMP_PIN 15

//Variable initialization
uint8_t cmd[9] = {0xFF,0x01,0x86,0x00,0x00,0x00,0x00,0x00,0x79};
uint8_t reset[9] = {0xFF,0x01,0x87,0x00,0x00,0x00,0x00,0x00,0x78};
uint8_t res[9] = {};
uint8_t idx = 0;
bool flag = false;
uint16_t co2=0;
const int Analog_channel_pin1= 34;
const int Analog_channel_pin2= 35;
const int Analog_channel_pin3= 32;

uint16_t Hygro_VALUE1 = 0;
uint16_t Hygro_VALUE2 = 0;
uint16_t Hygro_VALUE3 = 0; 

// set the LCD number of columns and rows
int lcdColumns = 16;
int lcdRows = 2;

// set LCD address, number of columns and rows
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);  

//Functions
void Errordetection(bool errorstatus){
  if (errorstatus == true){
  digitalWrite(LED_ERROR_PIN, HIGH);
  digitalWrite(VALVECO2_PIN, HIGH);
  }
  else{
  digitalWrite(LED_ERROR_PIN, LOW);
  }
}

void Led220v(bool led220vstatus){
  if (led220vstatus==true){
  digitalWrite(LED220V_PIN, LOW);
  digitalWrite(LED_LIGHT_PIN, HIGH);
  }
  else{
  digitalWrite(LED220V_PIN, HIGH);
  digitalWrite(LED_LIGHT_PIN, LOW);
  }
}

void Led24v(bool led24vstatus){
  if (led24vstatus==true){
  digitalWrite(LED24V_PIN, LOW);
  digitalWrite(LED_LIGHT_PIN, HIGH);
  }
  else{
  digitalWrite(LED24V_PIN, HIGH);
  digitalWrite(LED_LIGHT_PIN, LOW);
  }
}

void Comp(bool compstatus){
  if (compstatus==true){
  digitalWrite(COMP_PIN, LOW);
  digitalWrite(LED_COMP_PIN, HIGH);
  }
  else {
  digitalWrite(COMP_PIN, HIGH);
  digitalWrite(LED_COMP_PIN, LOW);
  }
}


void Vent(bool ventstatus){
  if (ventstatus==true){
  digitalWrite(VENT_PIN, LOW);
  digitalWrite(LED_VENT_PIN, HIGH);
  }
  else{
  digitalWrite(VENT_PIN, HIGH);
  digitalWrite(LED_VENT_PIN, LOW);
  }
}

void Valveh2o(bool valveh2ostatus){
  if (valveh2ostatus==true){
  digitalWrite(VALVEH2O_PIN, LOW);
  digitalWrite(LED_UPH2O_PIN, HIGH);
  }
  else{
  digitalWrite(VALVEH2O_PIN, HIGH);
  digitalWrite(LED_UPH2O_PIN, LOW);
  }
}

void Valveco2(bool valveco2status){
  if (valveco2status==true){
  digitalWrite(VALVECO2_PIN, LOW);
  digitalWrite(LED_UPCO2_PIN, HIGH);
  }
  else{
  digitalWrite(VALVECO2_PIN, HIGH);
  digitalWrite(LED_UPCO2_PIN, LOW);
  }
}

float Gethum(){
  float humidity;
  humidity = bme.readHumidity();
  delay(1000);
  lcd.setCursor(0, 0);
  lcd.print("hum:" +String(humidity)+ " %");
  Serial.println("hum:" +String(humidity)+ " %");
  delay(2000);
  lcd.clear();
  return humidity;
}

float Gettemp(){
  float temp;
  temp = bme.readTemperature();
  delay(1000);
  lcd.setCursor(0, 0);
  lcd.print("temp:" +String(temp)+" °C");
  Serial.println("temp:" +String(temp)+" °C");
  delay(2000);
  lcd.clear();;
  return temp;
}

uint16_t Getco2(){
  Serial2.write(cmd,9);
  while(Serial2.available()>0)
  {
    res[idx++]=Serial2.read();
    flag=true;
  }
  idx = 0;
  if(flag)
  {
    flag=false;
    co2 = 0;
    co2 += (uint16_t)res[2] <<8;
    co2 += res[3];
  }
  Serial.println("co2 : " + String(co2)+" ppm");
  lcd.clear();
  lcd.print("co2 : " + String(co2)+" ppm");
  delay(1000);
  if (co2>= 4000) {
    digitalWrite(LED_HIGHCO2_PIN, HIGH);
    Errordetection(true);
    }
   else {
    digitalWrite(LED_HIGHCO2_PIN, LOW);
    Errordetection(false);
   }
   return co2;
  }


uint16_t Gethygro(int pot){
   uint16_t hyg;
   if (pot == 1){
    uint16_t hyg = analogRead(Analog_channel_pin1);
    Serial.print("pot 1 hygrometry VALUE = ");
    Serial.println(hyg);
    delay(1000);
    lcd.setCursor(0, 0);
    lcd.clear();
    lcd.println("hyg1 : " + String(hyg)+" u.a.");
    delay(1000);
  }
   if (pot == 2){
    uint16_t hyg = analogRead(Analog_channel_pin2);
    Serial.print("pot 2 hygrometry VALUE = ");
    Serial.println(hyg);
    delay(1000);
    lcd.setCursor(0, 0);
    lcd.clear();
    lcd.println("hyg2 : " + String(hyg)+" u.a.");
    delay(1000);
  }
   if (pot == 3){
    uint16_t hyg = analogRead(Analog_channel_pin3);
    Serial.print("pot 3 hygrometry VALUE = ");
    Serial.println(hyg);
    delay(1000);
    lcd.setCursor(0, 0);
    lcd.clear();
    lcd.println("hyg3 : " + String(hyg)+" u.a.");
    delay(1000);
  }
    if ((pot!=1) and (pot!=2) and (pot!=3)) {
    Serial.print("Wrong argument");
  }
    
return hyg;
}
void Selftest(){
  lcd.setCursor(0, 0); 
  
  Serial.println("Testing Compressor");
  lcd.print("Comp test");
  Comp(true);
  delay(2000);
  Comp(false);
  delay(1000);
  lcd.clear();
  
  Serial.println("Testing LED220V");
  lcd.print("LED220V test");
  Led220v(true);
  delay(2000);
  Led220v(false);
  delay(1000);
   lcd.clear();

  Serial.println("Testing extractor");
  lcd.print("Extractor test");
  Vent(true);
  delay(2000);
  Vent(false);
  delay(1000);
   lcd.clear();
   
  Serial.println("Testing CO2 valve");
  lcd.print("CO2 valve test");
  Valveco2(true);
  delay(2000);
  Valveco2(false);
  delay(1000);
   lcd.clear();
  Serial.println("Testing h2O valve");
  lcd.print("H2O valve test");
  Valveh2o(true);
  delay(2000);
  Valveh2o(false);
  delay(1000);
  lcd.clear();

  Serial.println("Testing LED 24V");
  lcd.print("LED 24V test");
  Led24v(true);
  delay(2000);
  Led24v(false);
  delay(1000);
  lcd.clear();
}

//SETUP---------------------------------------------------------------------------------------------------------------------------------------
void setup(){
  //Various PIN initialization
  pinMode(MODE_PIN, INPUT);
  pinMode(MH_RST_PIN,OUTPUT);
  
  //Relay PIN initialization
  pinMode(COMP_PIN,OUTPUT);
  digitalWrite(COMP_PIN,HIGH);
  pinMode(LED220V_PIN,OUTPUT);
  digitalWrite(LED220V_PIN,HIGH);
  pinMode(VENT_PIN,OUTPUT);
  digitalWrite(VENT_PIN,HIGH);
  pinMode(VALVECO2_PIN,OUTPUT);
  digitalWrite(VALVECO2_PIN,HIGH);
  pinMode(LED24V_PIN,OUTPUT);
  digitalWrite(LED24V_PIN,HIGH);
  pinMode(VALVEH2O_PIN,OUTPUT);
  digitalWrite(VALVEH2O_PIN,HIGH);


  //LED PIN initialization
  pinMode(LED_ERROR_PIN,OUTPUT);
  digitalWrite(LED_ERROR_PIN,LOW);
  pinMode(LED_VENT_PIN,OUTPUT);
  digitalWrite(LED_VENT_PIN,LOW);
  pinMode(LED_UPH2O_PIN,OUTPUT);
  digitalWrite(LED_UPH2O_PIN,LOW);
  pinMode(LED_UPCO2_PIN,OUTPUT);
  digitalWrite(LED_UPCO2_PIN,LOW);
  pinMode(LED_HIGHCO2_PIN,OUTPUT);
  digitalWrite(LED_HIGHCO2_PIN,LOW);
  pinMode(LED_LIGHT_PIN,OUTPUT);
  digitalWrite(LED_LIGHT_PIN,LOW);
  pinMode(LED_COMP_PIN, OUTPUT);
  digitalWrite(LED_COMP_PIN, LOW);
  
  //UART communication initialization
  Serial.begin(115200);
  Serial2.begin(9600);
  delay(100);
  
  //LCD initialization
  lcd.init();                     
  lcd.backlight();
  lcd.setCursor(0, 0);

  //MH-Z14 initialization
  lcd.print("Warming up");
  digitalWrite(MH_RST_PIN,LOW);
  delay(8000);
  digitalWrite(MH_RST_PIN,HIGH);
  lcd.clear();
  delay(100);
  
  //BME initialization
   bme.begin(0x76); 

  //Self-test
  Selftest();
  
}

void loop(){
  // set cursor to first column, first row
  lcd.setCursor(0, 0);
  lcd.clear();
  Gethygro(1);
  delay(2000);
  lcd.clear();
  Gethygro(2);
  delay(2000);
  lcd.clear();
  Gethygro(3);
  delay(2000);
  lcd.clear();
  Getco2();
  lcd.clear();
  Gethum();
  Gettemp();
  Selftest();
  

}


If someone can help me with these various issues, I would be glad.

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: Various issues & inconsistencies using AZdelivery ESP32

Postby chegewara » Wed Dec 02, 2020 8:42 pm

Recently i had similar garbage on my 20x4 display, but it was all my fault.
When LCD is detected and during work SDA or SCL lose connection, because i have bad wires then all you will see after that is garbage similar to what you described. It may be also power rail for display.
In my case i dont really care about it because its all in design with breadboard. If i dont touch wires, then it works hours without issue.

Who is online

Users browsing this forum: No registered users and 70 guests