0

On my Arduino Uno, when I'm not using the serial everything seems in order:

#include <LiquidCrystal.h>

LiquidCrystal lcd(1, 2, 4, 5, 6, 7);

void setup()
{
    // put your setup code here, to run once:
    lcd.begin(16, 2);
    lcd.clear();
    lcd.print("Prints");
    lcd.setCursor(0, 1);
    lcd.print("Well");
}

void loop()
{
    delay(1000);
}

However the moment I open the serial port with:

Serial.begin(9600);

The problem starts.

Clearing the LCD does not clear it but prints a character with 4 horizontal lines. Trying to move the cursor will print a different unrecognisable character. Sending things to the Arduino via the Serial port prints gibberish on the LCD.

character with 4 horizontal lines

Any idea why? Is there a way to work with the LCD and the serial port simultaneously? I require the serial port in order to control the Arduino from NodeJS.

#include <LiquidCrystal.h>

LiquidCrystal lcd(1, 2, 4, 5, 6, 7);

void setup()
{
    // put your setup code here, to run once:
    lcd.begin(16, 2);
    lcd.clear();
    lcd.print("Prints");
    lcd.setCursor(0, 1);
    lcd.print("Well");

    Serial.begin(9600);

    while (!Serial)
    {
        ; // wait for serial port to connect. Needed for Native USB only
    }
}
    
void loop()
{
    lcd.clear(); // This will print 4 horizontal lines character instead of clearing
    delay(500); 
}
5
  • 2
    What type of Arduino? On some pin 1 is one of the hardware serial pins. You can’t use that pin for other things like LCDs if you are using serial.
    – Delta_G
    Jun 26, 2020 at 1:07
  • @Delta_G The board is Arduino Uno and you are right. Changing the pin from 1 to 3 solved the issue. Tnx! I wonder how many of 846,000 viewers of this youtube had the same issue? youtube.com/watch?v=dZZynJLmTn8&pbjreload=101 :-)
    – Guy
    Jun 26, 2020 at 1:16
  • 1
    I will make it an answer. Please accept
    – Delta_G
    Jun 26, 2020 at 1:20
  • @jsotola the question was downvoted so I thought perhaps I misrepresented the issue. I restored the previous title to your suggestion. tnx.
    – Guy
    Jun 26, 2020 at 2:02
  • somebody probably downvoted the post because you did not check which pins are used by the serial port
    – jsotola
    Jun 26, 2020 at 2:11

1 Answer 1

3

On an UNO pin 1 is one of the hardware serial pins. You can’t use pin 0 or pin 1 for other things if you are using Serial in your code.

Even if you aren’t using Serial, you use pins 0 and 1 when uploading your code and having other things connected can mess up that process. It’s generally advisable to stay away from pins 0 and 1 unless you absolutely must use them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.