Trouble using LCD display and serial monitor to print data

Hello there,

firs of all, I’m new to the community, but love what you are doing. Thanks for all the help I’ve found on the forum. Without any experience in electronics whatsoever, I have managed to build some equipments and tools I now use everyday.

That being said, I have now run into a problem to which I can’t find a solution. I’ve spent two nights goolging it and scrolling through the forum.

What I’d like to do:
Have a device that:

  • Measures pH of a solution (that part works very well).
  • Output the pH via the serial monitor to Excel (that works very well thanks to PLX-DAQ)
  • Output the pH on an LCD display (that works very well on a 20x4 LCD)

Now, do all three at the same time. That’s when my LCD starts outputting gibberish (random signs, mostly pound sign, cent signs, ö etc).

I’ve figure out it’s a problem in the code (The LCD and Serial Monitor work great independently)

Here’s a simplified code leaving out all the pH stuff

#include <LiquidCrystal.h>
LiquidCrystal  lcd(5, 4, 3, 2, 1, 0); 
void setup()
{  
  lcd.begin(20, 4);
  delay(1000);
  lcd.clear();
  lcd.setCursor(0, 0);  
  lcd.print("before serial.begin.");
  lcd.setCursor(0, 1);  
  lcd.print("before serial.begin.");
  lcd.setCursor(0, 2);  
  lcd.print("before serial.begin.");
  lcd.setCursor(0, 4);  
  lcd.print("before serial.begin.");
  delay(2500); 
  Serial.begin(9600); 
  lcd.clear();
  lcd.setCursor(0, 0);  
  lcd.print("after serial.begin.");
  lcd.setCursor(0, 1);  
  lcd.print("after serial.begin.");
  lcd.setCursor(0, 2);  
  lcd.print("after serial.begin.");
  lcd.setCursor(0, 4);  
  lcd.print("after serial.begin.");
  delay(2500); 
  Serial.println("CLEARDATA");  //clears all data from previous projects
  Serial.println("LABEL,Time,Time (sec),pH,uL / minute added"); //always write LABEL, so excel 
  Serial.println("RESETTIMER"); //resets timer to 0
  Serial.println("Ready");    //Test the serial monitor
}
void loop()
{
  Serial.print("DATA,TIME,TIMER"); //writes the time in the first column A and the time since the measurements started in column B
  Serial.print(",");                //next cell 
  delay(1000);  
}

To troubleshoot the code, I deliberately put in twice some piece of text for the LCD. The first rounds works good, the second (after Serial.begin(9600); ) messes evertyhing up. The lcd.clear(); is even ignored. So, I see part of the innitial text with gibberish next to it.
The serial monitor works fine, btw.

I am working with an arduino uno, macbook pro and a Backlight 2004 20x4 HD44780 LCD .

Can anyone help me with this? Why does the LCD coding stop working after serial.begin?

Many thanks,
Jobbus.

Digital pin 0 and 1 are used for serial communication. Don't use the same pins for the LCD. Also avoid pin 13. Leo..

Awh, man. That would make a lot of sense. Will try ASAP and come back to. I've got all the digital pins occupied right now, so it requires some rewiring. Thanks a lot.

Analogue pins are digital pins with the added function of analogue input. Just use spare analogue pins if you run out of digital pins. Leo..

Pin 13 is a red herring. It connects to an op-amp to drive the onboard L LED. There is no issue using it as an input output.

"Pin 13 ...connects to an op-amp to drive the onboard L LED."

It's a simple series circuit, LED and resistor (RN2A, RN2B) between PB5 and Gnd. Is it not?

[quote author=Runaway Pancake link=msg=2671897 date=1458435512] "Pin 13 ...connects to an op-amp to drive the onboard L LED."

It's a simple series circuit, LED and resistor (RN2A, RN2B) between PB5 and Gnd. Is it not? [/quote] I guess you have to look at the diagram of the Arduino you are working with. The Uno Rev3 and the Mega have a buffer opamp between the MCU pin and the LED. Other Arduinos might just have a resistor.

Pin13 might do strange things during bootup, so best to avoid if you can. Unless you deliberately want to flash an onboard LED. Leo..

Wawa: Digital pin 0 and 1 are used for serial communication. Don't use the same pins for the LCD. Also avoid pin 13. Leo..

Done, and fixed. Thanks a million. LCD works like a charm and so does the serial monitor.

Wawa: Analogue pins are digital pins with the added function of analogue input. Just use spare analogue pins if you run out of digital pins. Leo..

Thanks for the suggestion. It's pretty cramped in there, but I'll try this.

CrossRoads: Pin 13 is a red herring. It connects to an op-amp to drive the onboard L LED. There is no issue using it as an input output.

and

Wawa: I guess you have to look at the diagram of the Arduino you are working with. The Uno Rev3 and the Mega have a buffer opamp between the MCU pin and the LED. Other Arduinos might just have a resistor.

Pin13 might do strange things during bootup, so best to avoid if you can. Unless you deliberately want to flash an onboard LED. Leo..

This explains so much too me now. I've go a stepper driver on pin 13,12 and 11. When I reboot or upload, the pump connected to the stepper motor makes all kind of funky noises. Avoid 13. Thanks all!

Sorry for being such an amateur, but again, without this forum I would have never jumped into the field of arduino. Now I'm building equipments at home for my lab at the university. Saves me a ton of money (the device I'm building costs 1000s of dollars) and it's fun too. Thanks again.

i just had the same issue with running out of pins, but then just used the Rx pin anyway, because my program on the board does not use this pin in any other form than what i actually told it to output? so there is atleast 1 extra pin to use because the Tx cant be used anyway?(if you want to print to serial) altho i am not using it for a screen... so it cant affect much stuff anyway and i get a free extra pin?=)

Be careful using the Rx pin because it is needed to upload code to the board. If you want to be able to update your code make sure that whatever you connected to Rx can be easily removed while uploading.

Get an i2c backpack for your LCD display. This will free up a few pins. You will need to use A4 & A5 (on Uno). These are the i2c pins. You will need to make a few code changes also.

so i basically used a passive speaker on the Rx pin, but then i discovered that it actually ticks constantly while waiting for a command, so dunno what is up with that...

so i basically used a passive speaker on the Rx pin

So basically don't.

banjabi1: so i basically used a passive speaker on the Rx pin, but then i discovered that it actually ticks constantly while waiting for a command, so dunno what is up with that...

Waiting for a command? That implies that you are receiving over serial in addition to sending. So you are using Rx.

The Serial connection over the USB cable still uses those pins. They're connected internally.

well, buzzer's purpose is to buzz when commanded, but i probably need to discard it anyway then...