Go Down

Topic: weird symbols appear on my LCD screen (Read 616 times) previous topic - next topic

thejack02

Jun 29, 2020, 10:34 pm Last Edit: Jul 01, 2020, 01:52 am by thejack02
i created an incubator so my arduino has to stay on for 20 days, however after a few minutes that my lcd screen is showing some data normally it starts showing up random numers, letters and symbols.
if you need the code i will post it.

Paul__B

And the full circuit schematic and pictures of your contraption and the resulting display.  :smiley-lol:

So you have read the instructions for how to post code, haven't you?

thejack02

here's the code:

Code: [Select]

#include <Servo.h>
#include <LiquidCrystal.h>
#include <DHT.h>
int rele=2;
int t,u,temperatura=35,intervallo=10,c0=0,c=0,c1=0,c2=0;
int m=0,h=0,g=1;
extern unsigned long timer0_millis;
DHT dht(4,DHT11);
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
Servo servomotore;
void resetMillis() {
  cli();
  timer0_millis = 0;
  sei();
}
void setup() {
  dht.begin();
  lcd.begin(16, 2);
  servomotore.attach(6);
  pinMode(rele, OUTPUT);
  Serial.begin(9600);
  lcd.setCursor(7, 0);
  lcd.print("tempo:");
  lcd.setCursor(9, 1);
  lcd.print("g");
  lcd.setCursor(12, 1);
  lcd.print("h");
  lcd.setCursor(15, 1);
  lcd.print("m");
  servomotore.write(111);
}
void loop() {
  delay(1000);
  t=dht.readTemperature();
  u=dht.readHumidity();
  Serial.println("temperatura = "+String(t)+" C");
  Serial.println("umidità = "+String(u)+" %");
  lcd.setCursor(0, 0);
  lcd.print("T= "+String(t)+"C");
  lcd.setCursor(0, 1);
  lcd.print("U= "+String(u)+"%");
  lcd.setCursor(7, 1);
  lcd.print(g);
  int tempo=(millis()/1000);
  if (m==0) {lcd.setCursor(13, 1);
            lcd.print("0");}
  if (h==0) {lcd.setCursor(10, 1);
            lcd.print("0");}
  if (tempo>58) {resetMillis();
                 m++;}
  if (m>0) {lcd.setCursor(13, 1);
            lcd.print(m);}
  if (m>59) {m=0;
            lcd.setCursor(13, 1);
            lcd.print("  ");
            h++;}
  if (h>0) {lcd.setCursor(10, 1);
            lcd.print(h);}
  if (h>23) {h=0;
            lcd.setCursor(10, 1);
            lcd.print("  ");
            g++;}
  /*
  if(t>temperatura){
    digitalWrite(rele, HIGH);
  }
  else{
    digitalWrite(rele, LOW);
  }
  if(u<40){if(c0==0){servomotore.write(80);
                               delay(2000);
                               servomotore.write(111);}
                      c0++;
                      if(c0==15){c0=0;}
           }
  if((u>=40)&&(u<50)){c0=0;
                      if(c==0){servomotore.write(80);
                               delay(1000);
                               servomotore.write(111);}
                      c++;
                      if(c==1200){c=0;}
           }
  if((u>=50)&&(u<55)){c=0;
                      if(c1==0){servomotore.write(80);
                                delay(500);
                                servomotore.write(111);}
                      c1++;
                      if(c1==600){c1=0;}
           }
  if((u>=55)&&(u<60)){c1=0;
                      if(c2==0){servomotore.write(80);
                                delay(200);
                                servomotore.write(111);}
                      c2++;
                      if(c2==300){c2=0;}
           }
  if(u>=60) {servomotore.write(111);
             c2=0;}
  */
}


the error is every time a bit different and it happens at a random time.
i'll add the tinkercad circuit with just the screen attached, the actual lcd screen model is 1602.
thanks for the help.

Paul__B

#3
Jun 30, 2020, 01:46 am Last Edit: Jun 30, 2020, 10:44 am by Paul__B




It appears as if the nonsense only appears on the part of the display where you are attempting to print the values.  One possibility is that the sensor is not reading correctly and generating "nan" values - not actual numbers.

I do know that "String"s - those defined with the capital "S" cause program crashes in microcontroller code, but I'm not sure about the "String" functions.  Someone else may pass judgement on this.  :smiley-roll:

ZinggJM

#4
Jun 30, 2020, 07:40 am Last Edit: Jun 30, 2020, 07:59 am by ZinggJM
Quote
I do know that "String"s - those defined with the capital "S" cause program crashes in microcontroller code, but I'm not sure about the "String" functions.  Someone else may pass judgement on this.  
The "String functions" are actually String constructors, used for conversion. This forces the compiler to also convert the string literals to Strings, and to add Strings.

I would expect current compilers to not cause memory leaks with Strings. But you never know.

I would avoid this on low RAM microprocessors, such as AVR Arduinos.

Jean-Marc

added:

I am surprised that the compiler accepts this:

Code: [Select]
Serial.println("temperatura = "+String(t)+" C");

I thought you would need to write it to compile:

Code: [Select]
Serial.println(String("temperatura = ") + String(t) + " C");

(the last " C" is converted automatically).
No personal message please; any question may be useful for other users. Use code tags for code. Make links clickable with URL tags. Provide links to the product in question.

thejack02

so is it a memory leak due to the low amount of RAM? in this case i can't do anything to fix it, can i?

the "error" often appears in the zone where i am trying to write the time maybe it's an error of that part of code even if i have no clue of what it could be.

should i try to write the values individually to cause less stress to the RAM?

ZinggJM

Yes, it is easier to avoid trouble, than to analyze and investigate where the trouble comes from.

There are many potential causes, missing destructor calls, missing destructor calls for auto-generated class instances, heap release management code...

I use the String class only with "grown up" processors such as ESP32, ESP8266, STM32...
Any network capable processor needs a heap management that works.

Jean-Marc
No personal message please; any question may be useful for other users. Use code tags for code. Make links clickable with URL tags. Provide links to the product in question.

thejack02

#7
Jun 30, 2020, 01:37 pm Last Edit: Jun 30, 2020, 03:20 pm by thejack02
thank you so much, it works!!

update: after about an hour a new type of error showed up.

this is the new code:

Code: [Select]

#include <Servo.h>
#include <LiquidCrystal.h>
#include <DHT.h>
int rele=2;
int t,u,temperatura=35,intervallo=10,c0=0,c=0,c1=0,c2=0;
int m=0,h=0,g=1;
extern unsigned long timer0_millis;
DHT dht(4,DHT11);
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
Servo servomotore;
void resetMillis() {
  cli();
  timer0_millis = 0;
  sei();
}
void setup() {
  dht.begin();
  lcd.begin(16, 2);
  servomotore.attach(6);
  pinMode(rele, OUTPUT);
  Serial.begin(9600);
  lcd.setCursor(0, 0);
  lcd.print("T= ");
  lcd.setCursor(5, 0);
  lcd.print("C");
  lcd.setCursor(0, 1);
  lcd.print("U= ");
  lcd.setCursor(5, 1);
  lcd.print("%");
  lcd.setCursor(7, 0);
  lcd.print("tempo:");
  lcd.setCursor(9, 1);
  lcd.print("g");
  lcd.setCursor(12, 1);
  lcd.print("h");
  lcd.setCursor(15, 1);
  lcd.print("m");
}
void loop() {
  delay(1000);
  t=dht.readTemperature();
  u=dht.readHumidity();
  lcd.setCursor(3,0);
  lcd.print(t);
  lcd.setCursor(3,1);
  lcd.print(u);
  lcd.setCursor(7,1);
  lcd.print(g);
  int tempo=(millis()/1000);
  if (m==0) {lcd.setCursor(13, 1);
            lcd.print("0");}
  if (h==0) {lcd.setCursor(10, 1);
            lcd.print("0");}
  if (tempo>58) {resetMillis();
                 m++;}
  if (m>0) {lcd.setCursor(13, 1);
            lcd.print(m);}
  if (m>59) {m=0;
            lcd.setCursor(13, 1);
            lcd.print("  ");
            h++;}
  if (h>0) {lcd.setCursor(10, 1);
            lcd.print(h);}
  if (h>23) {h=0;
            lcd.setCursor(10, 1);
            lcd.print("  ");
            g++;}
  /*
  if(t>temperatura){
    digitalWrite(rele, HIGH);
  }
  else{
    digitalWrite(rele, LOW);
  }
  if(u<40){if(c0==0){servomotore.write(80);
                               delay(2000);
                               servomotore.write(111);}
                      c0++;
                      if(c0==15){c0=0;}
           }
  if((u>=40)&&(u<50)){c0=0;
                      if(c==0){servomotore.write(80);
                               delay(1000);
                               servomotore.write(111);}
                      c++;
                      if(c==1200){c=0;}
           }
  if((u>=50)&&(u<55)){c=0;
                      if(c1==0){servomotore.write(80);
                                delay(500);
                                servomotore.write(111);}
                      c1++;
                      if(c1==600){c1=0;}
           }
  if((u>=55)&&(u<60)){c1=0;
                      if(c2==0){servomotore.write(80);
                                delay(200);
                                servomotore.write(111);}
                      c2++;
                      if(c2==300){c2=0;}
           }
  if(u>=60) {servomotore.write(111);
             c2=0;}
  */
}

Paul__B


thejack02

i noticed that not only the lcd screen stops working but also the serial monitor, when i close and reopen the serial monitor the arduino resets and it works for a bit.

more and more questions. (i deleted all the strings functions)

thejack02

i have attached to the arduino a dht11, a servomotor, a relay module and the lcd screen... i tried to unplug individually every component and the error shows up only when the relay module is attached, if i unplug it the lcd screen works.

could it be an "energy supply" problem?

Paul__B

could it be an "energy supply" problem?
If we had some (accurate) idea of your overall wiring (clearly your diagram in #2 is not relevant to your current application) we might know.  :smiley-lol:

thejack02

there is no relay module on tinkercad, i don't know how to reproduce the circuit.

anyway, thanks again for the help!!

Paul__B

Then don't use tinkercad.  :smiley-roll:

Properly taken photographs - in outside daylight but not full sun, rather than in a dark room, angled so that all connections are visible with multiple views if needed, with adequate focus and resolution - will go a long way.  :smiley-lol:

thejack02

#14
Jul 01, 2020, 04:07 pm Last Edit: Jul 01, 2020, 04:09 pm by thejack02
unfortunately i've closed the arduino in a box (before it started giving me that error), i've sealed it with screws and glue (i'm dumb).
i've tried to create the circuit using photoshop.

Code: [Select]

#include <Servo.h>
#include <LiquidCrystal.h>
#include <DHT.h>

int rele=2;
int t,u,temperatura=39,c0=0,c=0,c1=0,c2=0;
int m=0,h=0,g=1;
extern unsigned long timer0_millis;
DHT dht(4,DHT11);
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
Servo servomotore;

void resetMillis() {
  cli();
  timer0_millis = 0;
  sei();
}

void setup() {
  dht.begin();
  lcd.begin(16, 2);
  servomotore.attach(6);
  pinMode(rele, OUTPUT);
  Serial.begin(9600);
  lcd.setCursor(0, 0);
  lcd.print("T= ");
  lcd.setCursor(5, 0);
  lcd.print("C");
  lcd.setCursor(0, 1);
  lcd.print("U= ");
  lcd.setCursor(5, 1);
  lcd.print("%");
  lcd.setCursor(7, 0);
  lcd.print("tempo:");
  lcd.setCursor(9, 1);
  lcd.print("g");
  lcd.setCursor(12, 1);
  lcd.print("h");
  lcd.setCursor(15, 1);
  lcd.print("m");
}

void loop() {
  delay(1000);
  t=dht.readTemperature();
  u=dht.readHumidity();
  Serial.print("temperatura = ");
  Serial.print(t);
  Serial.println(" C");
  Serial.print("umidità = ");
  Serial.print(u);
  Serial.println(" %");
  lcd.setCursor(3,0);
  lcd.print(t);
  lcd.setCursor(3,1);
  lcd.print(u);
  lcd.setCursor(7,1);
  lcd.print(g);
  int tempo=(millis()/1000);
  if (m==0) {lcd.setCursor(13, 1);
            lcd.print("0");}
  if (h==0) {lcd.setCursor(10, 1);
            lcd.print("0");}
  if (tempo>58) {resetMillis();
                 m++;}
  if (m>0) {lcd.setCursor(13, 1);
            lcd.print(m);}
  if (m>59) {m=0;
            lcd.setCursor(13, 1);
            lcd.print("  ");
            h++;}
  if (h>0) {lcd.setCursor(10, 1);
            lcd.print(h);}
  if (h>23) {h=0;
            lcd.setCursor(10, 1);
            lcd.print("  ");
            g++;}
  if(t>temperatura){
    digitalWrite(rele, HIGH);
  }
  else{
    digitalWrite(rele, LOW);
  }
  if(u<60){if(c2==0){servomotore.write(150);
                     delay(40);
                     servomotore.write(170);}
                     c2++;
                     if(c2==50){c2=0;}
           }
}

Go Up