LCD display doesnt like Serial Monitor

Im using a code to print stuff to an lcd display.

The simple tutorial sketch works fine:

void setup() {
  // Set up LCD
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Hola Arduino HN!");
  Serial.begin(19200);
  Serial.print("Done printing to lcd");
}

But this sketch in this order doesnt work:

void setup(){
  
  lcd.begin(16,2);  
  lcd.print("Weather Station>");
  lcd.setCursor(0,1);
  lcd.print("loading...");
  
  delay(2000);

  lcd.setCursor(0,1);
  lcd.print("what is it");

  pinMode(led, OUTPUT);
  
  delay(2000);

  lcd.setCursor(0,1);
  lcd.print("after led");
  
  // VirtualWire
  // Bits por seg
  vw_setup(2000);
  // set pin para conectar receptor
  vw_set_rx_pin(9);
  // Iniciar el receptor PLL funcionando
  vw_rx_start();
  
  lcd.setCursor(0,1);
  lcd.print("after rx");

Everything before the VirtualWire setup and pin and start prints fine but anything after that doesnt show up.

Why is that?

Can you show your full sketches so we can see all the code you are using?

Here is the full sketch.

Im focusing on the setup() at the moment.

//#include <Wire.h> // Wire library para i2c (A4 = SDA & A5 = SCL)
//#include <LiquidCrystal_I2C.h> // LiquidCrystal_I2C library para control LCD en i2c protocol
#include <VirtualWire.h> // Virtual library para decode señal de Rx
#include <LiquidCrystal.h>

byte thermometer[8] = { //icono para thermometer
B00100,
B01010,
B01010,
B01110,
B01110,
B11111,
B11111,
B01110
};

byte droplet[8] = { //icono para gota
B00100,
B00100,
B01010,
B01010,
B10001,
B10001,
B10001,
B01110,
};
byte hi[8]= {//icono para indice de calor
0B00000,
0B00000,
0B10101,
0B01110,
0B11111,
0B01110,
0B10101,
0B00000,
}; 

//(addr, EN,RW,RS,D4,D5,D6,D7,BL,BLpol)
//Originally in instructables code - must be outdated
//LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); //cambiar address según i2c
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

//borrowed from library examples LCDI2C
//LiquidCrystal_I2C lcd(0x27, 16, 2);

// Sensores
int humidity=0;
int temp=0;
int heat_index=0;
char MsgReceived[21];
int led = 13; //pin para LED

void setup(){
  
  lcd.begin(16,2);  
  lcd.print("Weather Station>");
  lcd.setCursor(0,1);
  lcd.print("loading...");

  pinMode(led, OUTPUT);
  
  delay(2000);

  lcd.setCursor(0,1);
  lcd.print("after led");
  
  // VirtualWire
  // Bits por seg
  vw_setup(2000);
  lcd.setCursor(0,1);
  lcd.print("after vwsetup");
  
  // set pin para conectar receptor
  vw_set_rx_pin(9);
  lcd.setCursor(0,1);
  lcd.print("after rx");
  // Iniciar el receptor PLL funcionando
  vw_rx_start();
  
  lcd.setCursor(0,1);
  lcd.print("after start");
  
  lcd.setCursor(0,1);
  lcd.print("temp...");
  ////lcd.createChar(0, thermometer);
  ////lcd.createChar(1, droplet);
  //lcd.createChar(3,hi);   // only 2 rows!
  

} // END void setup

void loop(){
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
//Tomar data de control base

  //Serial.print("Listening for messsage...");

if (vw_get_message(buf, &buflen)){
  Serial.print("Got a messsage");
  digitalWrite(led, HIGH);
  delay(100);
  int i;
  // Mensaje con checksum correcta recibida, botar.
  for (i = 0; i < buflen; i++){
    // Llenar Msg Char array con chars del buffer.
    MsgReceived[i] = char(buf[i]);
    Serial.print(MsgReceived[i]);
  }
  
  sscanf(MsgReceived, "%d,%d,%d",&humidity, &temp,&heat_index); // Converts a string to an array
  digitalWrite(led, LOW);
  lcd_display();
  memset( MsgReceived, 0, sizeof(MsgReceived));// This line is for reset the StringReceived
}
}

void lcd_display() { 
lcd.setCursor(1,0);
lcd.print(" WEATHER STATION ");
lcd.setCursor(4,1);
lcd.print("TEMP");
lcd.setCursor(9, 1);
lcd.write(1);
lcd.setCursor(11, 1);
lcd.print(temp);
lcd.write(0b11011111);
lcd.print("C");
lcd.setCursor(4,2);
lcd.print("HUM");
lcd.setCursor(9, 2);
lcd.write(2);
lcd.setCursor(11, 2);
lcd.print(humidity);
lcd.print("%");
lcd.setCursor(4,3);
lcd.print("HI");
lcd.setCursor(9, 3);
lcd.write(3);
lcd.setCursor(11, 3);
lcd.print(heat_index);
lcd.write(0b11011111);
lcd.print("C");
}

What is the purpose of using "virtualwire"? You commented out LCD code indicates you are not sure which LCD library to use. If you are NOT using I2C / SPI you do not need "wire" library, that is why I am asking what "virtualwire" does for you, assuming it is an offspring of "wire" library to control SPI /I2C devices.

If the LCD is connected via controls ( write , enable etc. ) and uses data bus (4 bits) use "plain " LiquidCrystal library and eventually delete all of the unnecessary and commented out code for SPI / I2C connected LCD. .

I commented out the lcd_i2c because I'm using the old lcd library which is why you see the constructor (12,11,5,4,3,2).

The lc_i2c code that is commented out because the sketch in the tutorial used i2c but I don't.

Virtual wire is for RF COMM.

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
vw_setup(2000);
vw_set_rx_pin(9);

I think there is still a pin conflict on pin 11 in that vw_setup is setting the default rx pin 11 to an input, before the pin is changed to pin 9. Try changing the order

vw_set_rx_pin(9);
vw_setup(2000);

Oh you mean that vw sets pin 11 as default until the user sets it otherwise?

Ok I just saw that:

// The digital IO pin number of the receiver data
static uint8_t vw_rx_pin = 11;

// The digital IO pin number of the transmitter data
static uint8_t vw_tx_pin = 12;

Thanks, ill try changing that!

In your full code, I did not find Serial.begin() in your setup, but I saw Serial.print("Got a messsage"); in the script.

Yeah jack I know. I started weeding out the serial commands because originally I thought the serial was conflicting with the virtual wire. That's why my post has that title.

Then I realized it only got stuck when I made the call, whether the Serial or lcd call, after the vwire setup.

Ok guys, I got it working. I was just wondering why my last serial.print (in the Tx sketch) didn’t work.

The sketch is like this:

// Envío de Datos y Dormir Modulo
#include <VirtualWire.h>
#include "LowPower.h"
#include "DHT.h"

#define DHTPIN 8 // Pin para el DHT11
#define DHTTYPE DHT11 // Objeto DHT 11
DHT dht(DHTPIN, DHTTYPE);

int ledPin = 13;
char Msg[30];// Para el string que enviaremos por el RF

void setup(){
  dht.begin(); // initializar el DHT11
  pinMode(ledPin,OUTPUT);
  // VirtualWire
  vw_setup(2000); // Bits por seg
  vw_set_tx_pin(12);// Settear Tx pin. Default es 12
  
  Serial.begin(19200);
  Serial.print("Setting up...");
}

void loop() {// Leer y almacenar data
  int humidity = dht.readHumidity();
  int temp = dht.readTemperature();
  int f = dht.readTemperature(true);
  int hi_f = dht.computeHeatIndex(f,humidity); //Indice calor en F
  int heat_index =(hi_f-32)*5/9; // conversión a C
  sprintf(Msg, "%d,%d,%d", humidity,temp ,heat_index);
  // Encender LED para mostrar Tx
  digitalWrite(ledPin, HIGH);
  //LowPower.powerDown(SLEEP_250MS, ADC_OFF, BOD_OFF);
  delay(100);
  Serial.print("About to send message");
  vw_send((uint8_t *)Msg, strlen(Msg));
  //print message
  Serial.print("The message is");
  Serial.print(Msg);
  vw_wait_tx(); // Esperar hasta que todo el string se transmita
  // Apagar luz después de transmision
  digitalWrite(ledPin, LOW);
  Serial.print("Message sent!"); <<<<<<<<<THIS ONE
  // Dormir durante 5 minutos
  // As lowpower library support maximam 8s ,we use for loop to take longer (5mins) sleep
  // 5x60=300
  //300/4=75
  for(int i=0;i<75;i++){
    LowPower.powerDown(SLEEP_4S, ADC_OFF, BOD_OFF); // En lugar de delay(4000);
  }
}
Serial.print(Msg);
  vw_wait_tx(); // Esperar hasta que todo el string se transmita
  // Apagar luz después de transmision
  digitalWrite(ledPin, LOW);
  Serial.print("Message sent!"); <<<<<<<<<THIS ONE

Did the digitalWrite(ledPin, LOW); work?
If not, may be from the vw_wait_tx(); just above it.

else, what if you use Serial.println(Msg); in case your monitor is not wrapping as expected.

The Serial.print(Msg); works fine and its received in the Rx module because I can see it on the lcd.

And yes the led did turn off.

"The Serial.print(Msg); works fine and its received in the Rx module because I can see it on the lcd. "

Sorry, I must have been confused, I thought the Serial.print() was going to your pc monitor. So I guess you feel that Serial.println() is not need.

Here is the reason LCD quit working after you used "virtualwire" - both devices - RF and LCD use same I/O pins. You can do that but your software needs to be smart enough to switch to and disable unwanted device. This goes back to same - RTFM or better yet - read the source code and do not just cut and paste / use a library.

/// Set the digital IO pin to be for transmit data. /// This pin will only be accessed if /// the transmitter is enabled /// \param[in] pin The Arduino pin number for transmitting data. Defaults to 12. extern void vw_set_tx_pin(uint8_t pin);

/// Set the digital IO pin to be for receive data. /// This pin will only be accessed if /// the receiver is enabled /// \param[in] pin The Arduino pin number for receiving data. Defaults to 11. extern void vw_set_rx_pin(uint8_t pin);

Jack

I meant to say that the Msg is indeed printed in the serial monitor and it is also sent to the Rx module fine (and displayed in the Rx modules lcd just fine Vaclav).

However I thought it weird that the Serial which prints "Message sent!" On the serial does not show up.

Everything else works fine. I'll try it again today, maybe it did scroll sideways and I missed it. Or maybe that lone was commented before upload and I un commented it later and don't remember.