Go Down

Topic: LCD screen flickering while printing serial data (Read 220 times) previous topic - next topic

YasinT

hi All,

I'm new to Arduino programming and am experiencing the following issue.

Whenever my code is printing its serial data from an NTC sensor (which works fine on serial print) on a 20x4 HITACHI lcd screen, the screen flickers. I would like some insight on what could be wrong with my code.

My hardware setup works as it is (other code with static text is displayed wthout flickering and such) but I have a different setup as i don't use resistors and a potentiometer for the lcd. The setup is as followed.

Using an Arduino Mega btw

VSS - 5V
VDD - GND
VO - Analog pin 3 (I replaced the potentiometer with an analogpin and use analogWrite to give the lcd contrast
RS -  TX0 / Digital 1
RW - GND
E - analog 2
D4 - digital 4
D5 - digital 5
D6 - digital 6
D7 - digital 7

Anode - not connected
Cathode - GND (parallel with VDD)

my code is as followed

Code: [Select]
#include <LiquidCrystal.h> 
int Contrast=20;
LiquidCrystal lcd(1, 2, 4, 5, 6, 7);   

int TempPin = A0; 
int Vo;                   

 void setup()
  {
    analogWrite(3,Contrast);   //This code replaces the potentiometer by connecting Vo to an Analog pin
    {
    lcd.begin(20, 4);
    }
  }
   
     void loop()
  {
 
   Vo = analogRead(TempPin);     
   lcd.setCursor(0,0);
   lcd.print("Temp");
   lcd.print(Vo);
   
   }
   
 


I'm uncertain if the command analogWrite(3, contrast) is causing the flicker as it is present in void loop.

I'd appreciate any help on this matter.


Nick_Pyner

#1
Jan 10, 2018, 01:10 am Last Edit: Jan 10, 2018, 01:15 am by Nick_Pyner
The analogwrite command is in setup and cannot possibly cause flicker. It is usual to put some sort of timer control in the loop, the simplest being an appropriate delay. As things are, the main thing controlling the loop is probably the time taken to write on the display. 

The
Code: [Select]
   lcd.setCursor(0,0);
   lcd.print("Temp");
need only be printed once and is better in the setup, hence perhaps
Code: [Select]
   lcd.setCursor(10,0);
   lcd.print(Vo);
   delay(1000);

in the loop

YasinT

#2
Jan 10, 2018, 07:59 am Last Edit: Jan 10, 2018, 08:16 am by YasinT
Setting lcd.print("temp") in setup and delaying loop by 1000ms didn't help. It only made the flickering more apparant every 1000ms. I've attached a video to demonstrate the flickering.

Nick_Pyner

If what I see is truly representative of what is going on, I wouldn't call that "flickering", I would call it "intermittent operation", and I doubt that it has anything to do with code. It could have quite a lot to do with power supply.

YasinT

The gif was taken in the dark but when the backlight is off, it's still updating the data on the screen, when it updates the lcd backlight flickers on and off and sometimes just goes on for a bit

Nick_Pyner

I imagine the backlight requires several times more power than the rest of the display, and whatever you are doing to run it isn't enough.

YasinT

#6
Jan 10, 2018, 04:35 pm Last Edit: Jan 10, 2018, 06:19 pm by YasinT Reason: UPDATE
Could it be that i didn't connect the anode pin? If I do the screen just shows some gibberish.

*Update*

Connected the anode pin with a 100 0hm resistor and still the screen is flickering.

The flickering changes when i change the delay function in void loop, maybe it has to do with that?

*Added another gif to demonstrate with a lower delay of 500ms

Nick_Pyner

The GIF shows a flash about once a second, so I cannot see a connection with a 500 delay, but at least it appears to be regular. I don't see any text on it when it flashes. I would guess that no amount of coding will fix this, it is all to do with wiring and power. If you can see text with no backlight, I think that would prove I am right, and most of the wiring is kosher. If you can't see any text, it does not prove I'm wrong, and it doesn't prove your code is wrong either.

The problem could be in the sensor. You could test this with dummy values.

Please don't tell us you are running this off a 9v PP3 battery.   


Nick_Pyner

#9
Jan 11, 2018, 04:21 pm Last Edit: Jan 11, 2018, 04:31 pm by Nick_Pyner
BTW, I see you have a LCD pin connected to hardware serial, and the whole line
Code: [Select]
LiquidCrystal lcd(1, 2, 4, 5, 6, 7);  is probably suss. While you are not actually using serial, using TX0 cannot possibly be a good idea. It might even be indicative of something.

Go Up