Pullup resistors for I2C display

Are pullup resistors necessary for i2C 20x4 LCD display. I ask because when ever i upload a code, at times the display does not seem to respond when the arduino resets. It hangs on to the previous display other it resets.

The display, I believe holds onto the last data sent to it - so resetting the Arduino has no effect, until the next message is sent.
If you clear the display in setup then it will go blank on a reboot

Show your code. It will answer the question.

I had the lcd.clear () in the setup() just before writing to the lcd.seems to be ok after i had set the lcd.clear() at the beginning of setup()/

Well lets see.

that does not seem to working, here is my sketch

[code]
byte zCd = 2;  // Zero Crossing Detect
const byte TRIAC = 3;  //Load Output
const byte rdy = 4;
const byte btn = 6 ;
const byte bzr = 8; // Previously 8, did not buzz at times.
const byte L8   = 9;
const byte L7   = 10;
const byte L6   = 11;
const byte L5   = 12;
const byte L4   = 13;
const byte L3   = A2;
const byte L2   = A3;
const byte L1   = A4;
const byte Pot = A5;  //POT value pin
const int debounce = 10; // ms debounce period to prevent flickering when pressing or releasing the button
const int holdTime = 800; // ms hold period: how long to wait for press+hold event
int WeldCounter = 0; // prevents weld at boot
int counter1 = 0;
int counter = 0;
int WeldStepValue;    // Value of POT in milliseconds
int OldWeldStepValue; // Old value of POT
int PotValue;         // Actual POT value
volatile boolean zeroCrossingFlag = false;
int btnState = 0; // value read from button
int buttonLast = HIGH; // buffered value of the button's previous state
long btnDnTime; // time the button was pressed down
long btnUpTime; // time the button was released
boolean ignoreUp = false; // whether to ignore the button release because the click+hold was triggered

void setup()
{
  pinMode(Pot, INPUT);
  pinMode(TRIAC, OUTPUT);
  pinMode(rdy, OUTPUT);
  pinMode(L1, OUTPUT);
  pinMode(L2, OUTPUT);
  pinMode(L3, OUTPUT);
  pinMode(L4, OUTPUT);
  pinMode(L5, OUTPUT);
  pinMode(L6, OUTPUT);
  pinMode(L7, OUTPUT);
  pinMode(L8, OUTPUT);
  pinMode(bzr, OUTPUT);
  pinMode(zCd, INPUT_PULLUP);
  pinMode(btn, INPUT_PULLUP);
  attachInterrupt(0, setFlag, FALLING);//zero cross attach
  delay(500);
  LedRun();
  Serial.begin(9600);
}
void setFlag()
{
  zeroCrossingFlag = true; //interrupt sets flag true
}

int WeldStep()          // Map POT value from A5 to increments of 50 from 100 to 450
{
  int WeldStep;
  PotValue = analogRead(Pot);
  WeldStepValue = map(PotValue, 0, 1023, 100, 500);
  if (WeldStepValue >= 100 && WeldStepValue < 150)
    WeldStepValue = 100;
  if (WeldStepValue >= 150 && WeldStepValue < 200)
    WeldStepValue = 150;
  if (WeldStepValue >= 200 && WeldStepValue < 250)
    WeldStepValue = 200;
  if (WeldStepValue >= 250 && WeldStepValue < 300)
    WeldStepValue = 250;
  if (WeldStepValue >= 300 && WeldStepValue < 350)
    WeldStepValue = 300;
  if (WeldStepValue >= 350 && WeldStepValue < 400)
    WeldStepValue = 350;
  if (WeldStepValue >= 400 && WeldStepValue < 450)
    WeldStepValue = 400;
  if (WeldStepValue >= 450)
    WeldStepValue = 450;
  return WeldStepValue;
}

void WeldStepVal()      // Display POT value for Debug
{
  Serial.print("Set weld time: ");
  Serial.print(WeldStep());
  Serial.println("ms");
}

void LedRun()           // Test output from IC to all LED
{
  LED_OFF();
  digitalWrite(L1, HIGH);
  delay(100);
  LED_OFF();
  digitalWrite(L2, HIGH);
  delay(100);
  LED_OFF();
  digitalWrite(L3, HIGH);
  delay(100);
  LED_OFF();
  digitalWrite(L4, HIGH);
  delay(100);
  LED_OFF();
  digitalWrite(L5, HIGH);
  delay(100);
  LED_OFF();
  digitalWrite(L6, HIGH);
  delay(100);
  LED_OFF();
  digitalWrite(L7, HIGH);
  delay(100);
  LED_OFF();
  digitalWrite(L8, HIGH);
  delay(100);
  LED_OFF();
}

const int Weld(int pre, int pause)  //Actual weld
{
  delay(400);
  zeroCrossingFlag = false; //set flag false and wait for next zero crossing
  while (!zeroCrossingFlag) {};
  delayMicroseconds(5630);                  //delay to trigger at peak sine wave
  digitalWrite(rdy, LOW);
  digitalWrite(TRIAC, HIGH);
  delay(pre);               //preWeld time
  zeroCrossingFlag = false; //set flag false and wait for next zero crossing
  while (!zeroCrossingFlag) {};
  digitalWrite(TRIAC, LOW);
  delay(pause);
  while (counter1 < 1) { // Set multiple Welds after Pre-weld, deault is 1
    delay(50);
    zeroCrossingFlag = false; //set flag false and wait for next zero crossing
    while (!zeroCrossingFlag) {};
    delayMicroseconds(5630);
    digitalWrite(TRIAC, HIGH);
    delay(WeldStep());
    zeroCrossingFlag = false; //set flag false and wait for next zero crossing
    while (!zeroCrossingFlag) {};
    digitalWrite(TRIAC, LOW);
    counter1++;
  }
  counter1 = 0;
  zeroCrossingFlag = false;
  while (!zeroCrossingFlag) {};
  digitalWrite(TRIAC, LOW);
  delay(300);
  digitalWrite(bzr, HIGH);
  delay(70);
  digitalWrite(bzr, LOW);
}

void continousWeld()
{
  delay(400);
  digitalWrite(bzr, HIGH);
  delay(60);
  digitalWrite(bzr, LOW);
  delay(50);
  digitalWrite(bzr, HIGH);
  delay(60);
  digitalWrite(bzr, LOW);
  while (counter < 6) {
    delay(1000);
    Weld(50, 500);
    counter++;
  }
  counter = 0;
  delay(500);
  digitalWrite(bzr, HIGH);
  delay(500);
  digitalWrite(bzr, LOW);
}

void LED_OFF()
{
  digitalWrite(L1, LOW);
  digitalWrite(L2, LOW);
  digitalWrite(L3, LOW);
  digitalWrite(L4, LOW);
  digitalWrite(L5, LOW);
  digitalWrite(L6, LOW);
  digitalWrite(L7, LOW);
  digitalWrite(L8, LOW);
}

void PulseSetLed()      // Display weld time 100, 150...... as LED
{
  const int wait = 200;
  switch (WeldStep())
  {
    case 100:
      delay(wait);
      LED_OFF();
      digitalWrite(L1, HIGH);
      break;
    case 150:
      delay(wait);
      LED_OFF();
      digitalWrite(L2, HIGH);
      break;
    case 200:
      delay(wait);
      LED_OFF();
      digitalWrite(L3, HIGH);
      break;
    case 250:
      delay(wait);
      LED_OFF();
      digitalWrite(L4, HIGH);
      break;
    case 300:
      delay(wait);
      LED_OFF();
      digitalWrite(L5, HIGH);
      break;
    case 350:
      delay(wait);
      LED_OFF();
      digitalWrite(L6, HIGH);
      break;
    case 400:
      delay(wait);
      LED_OFF();
      digitalWrite(L7, HIGH);
      break;
    case 450:
      delay(wait);
      LED_OFF();
      digitalWrite(L8, HIGH);
      break;
  }
}

void loop()
{
  btnState = digitalRead(btn);
  while (!zeroCrossingFlag)
  {
    digitalWrite(rdy, LOW);
  }
  digitalWrite(rdy, HIGH);
  // For debug
  if (OldWeldStepValue != WeldStep())
  {
    WeldStep();
    OldWeldStepValue = WeldStep();
  }
  PulseSetLed();

  // Test for button pressed and store the down time
  if (btnState == LOW && buttonLast == HIGH && (millis() - btnUpTime) > long(debounce))
  {
    btnDnTime = millis();
  }

  // Test for button release and store the up time
  if (btnState == HIGH && buttonLast == LOW && (millis() - btnDnTime) > long(debounce))
  {
    if (ignoreUp == false) Weld(50, 500);
    else ignoreUp = false;
    btnUpTime = millis();
  }

  // Test for button held down for longer than the hold time
  if (btnState == LOW && (millis() - btnDnTime) > long(holdTime))
  {
    continousWeld();
    ignoreUp = true;
    btnDnTime = millis();
  }
  buttonLast = btnState;
  zeroCrossingFlag = false;
}

[/code]

here is my sketch

I don't believe you posted the correct code. There is no lcd display in the sketch you posted.

anishkgt:
I had the lcd.clear () in the setup() just before writing to the lcd.seems to be ok after i had set the lcd.clear() at the beginning of setup()/

Well lets see.

At the beginning of setup only does it once.
You need to clear before every write because the screen holds what was last written to each and every spot.
Either clear before each update or use appropriate blank spaces to clear old characters.

The characters that are not overwritten or cleared will stay there.
That can be used to your advantage, e.g. with a temperature display.
LCD.print "Temp: C" in void setup(), and update the temp value in void loop() at the right place with setCursor() could give a much faster refresh without flickering.

Leo..

Oops posted the wrong sketch. Attached new.

sketch.txt (15.9 KB)

lcd.clear();
  lcd.begin(20, 4);

All lcd commands need to be after lcd.begin() so reverse the order of these two lines in setup. lcd.begin() should clear the display, but if for some reason it is not doing so. the lcd.clear() can't hurt.

lcd.begin(20, 4);
lcd.clear();

Are there any particular instances of persistance of unwanted characters on the screen you can point out.