Arduino Forum

Using Arduino => Displays => Topic started by: thejack02 on Jun 29, 2020, 10:34 pm

Title: weird symbols appear on my LCD screen
Post by: thejack02 on Jun 29, 2020, 10:34 pm
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.
Title: Re: wired symbols appear on my LCD screen
Post by: Paul__B on Jun 29, 2020, 11:53 pm
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 (http://arduino.cc/forum/index.php/topic,148850.0.html), haven't you?
Title: Re: wired symbols appear on my LCD screen
Post by: thejack02 on Jun 30, 2020, 01:11 am
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.
Title: Re: wEIRd symbols appear on my LCD screen
Post by: Paul__B on Jun 30, 2020, 01:46 am
(https://forum.arduino.cc/index.php?action=dlattach;topic=693071.0;attach=370929) (https://forum.arduino.cc/index.php?action=dlattach;topic=693071.0;attach=370929)

(https://forum.arduino.cc/index.php?action=dlattach;topic=693071.0;attach=370931) (https://forum.arduino.cc/index.php?action=dlattach;topic=693071.0;attach=370931)


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:
Title: Re: weird symbols appear on my LCD screen
Post by: ZinggJM on Jun 30, 2020, 07:40 am
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).
Title: Re: wired symbols appear on my LCD screen
Post by: thejack02 on Jun 30, 2020, 10:16 am
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?
Title: Re: wired symbols appear on my LCD screen
Post by: ZinggJM on Jun 30, 2020, 11:41 am
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
Title: Re: wired symbols appear on my LCD screen
Post by: thejack02 on Jun 30, 2020, 01:37 pm
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;}
  */
}
Title: Re: wired symbols appear on my LCD screen
Post by: Paul__B on Jun 30, 2020, 03:55 pm
(https://forum.arduino.cc/index.php?action=dlattach;topic=693071.0;attach=371014) (https://forum.arduino.cc/index.php?action=dlattach;topic=693071.0;attach=371014)
Title: Re: weird symbols appear on my LCD screen
Post by: thejack02 on Jul 01, 2020, 01:59 am
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)
Title: Re: weird symbols appear on my LCD screen
Post by: thejack02 on Jul 01, 2020, 02:22 am
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?
Title: Re: weird symbols appear on my LCD screen
Post by: Paul__B on Jul 01, 2020, 01:56 pm
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:
Title: Re: weird symbols appear on my LCD screen
Post by: thejack02 on Jul 01, 2020, 02:09 pm
there is no relay module on tinkercad, i don't know how to reproduce the circuit.

anyway, thanks again for the help!!
Title: Re: weird symbols appear on my LCD screen
Post by: Paul__B on Jul 01, 2020, 02:16 pm
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:
Title: Re: weird symbols appear on my LCD screen
Post by: thejack02 on Jul 01, 2020, 04:07 pm
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;}
           }
}
Title: Re: weird symbols appear on my LCD screen
Post by: Paul__B on Jul 01, 2020, 11:44 pm
(https://forum.arduino.cc/index.php?action=dlattach;topic=693071.0;attach=371172) (https://forum.arduino.cc/index.php?action=dlattach;topic=693071.0;attach=371172)

Well, that looks fairly straightforward.  Powering it via USB, operating the servomotor for any significant duration may cause the "polyswitch" on the UNO to shut down, but the problem seems to be more related to impulses generated by the relay.

A 1 mF (one millifarad or 1000 microfarad) capacitor across the 5 V and ground on the relay module itself or a 220 µF capacitor across pins 1 and 2 on the LCD (or both!) would be worth trying.  :smiley-lol:

Beyond that, it would require alternate power supply arrangements - a regulated 5 V power supply of some sort (such as a USB "phone charger" rated at 2.1 A) with certain wiring arrangements.

It is most important that the mains wiring to the relay is bundled together so it forms no open loops and is kept away from all other wiring and all wiring is bundled together as it runs from one part to another, keeping 5 V, ground and signal wires as a bundle.
Title: Re: weird symbols appear on my LCD screen
Post by: thejack02 on Jul 02, 2020, 02:32 pm
Right now i don't have any capacitor but i've found a power supply that is perfect.
I've wired the "+" with the 5v of the relay module and the servomotor(it was a bit "laggy" and now with the power supply it is smooth), and the "-" with the ground of arduino.
it is working fine but the error is still there (maybe it is less frequent).
do you think some capacitors could actually solve the problem?
Title: Re: weird symbols appear on my LCD screen
Post by: TheUNOGuy on Jul 02, 2020, 04:39 pm

It was the same problem with me. I was using the LCD without a petentiometer and I used a temperature sensor with it. It showed weird symbols. But, when the sensor was removed, everything worked fine ( no weird characters ). So my suggestion would be to remove everything and just keep the LCD connected to the arduino.
Title: Re: weird symbols appear on my LCD screen
Post by: thejack02 on Jul 02, 2020, 08:08 pm
unfortunately for my project i need the lcd screen and a sensor for humidity and temperature, i ordered a DTH22 a few weeks ago but it is still on shipment, it is a more precise sensor but i don't know if it will solve this problem.
Title: Re: weird symbols appear on my LCD screen
Post by: thejack02 on Jul 05, 2020, 01:18 am
a 100 uF capacitor on the first two pins of the screen didn't solve the problem, i'll try with a bigger one
Title: Re: weird symbols appear on my LCD screen
Post by: thejack02 on Jul 05, 2020, 04:44 pm
i've read on an old forum that maybe separating the ground of the relay module and the servomotor from the ground of the arduino can reduce the interference but i don't know how to do it, if i connect them to the ground of the power supply the relay and the motor go crazy.

what i don't understand is how also the serial monitor stop working...
Title: Re: weird symbols appear on my LCD screen
Post by: TheUNOGuy on Jul 08, 2020, 09:29 am
You may want to use a potentiometer attached to your lcd or an external power sourece for 5v and gnd. Digital pins can be used from the board itself