[SOLVED] I can have VirtualWire OR LCD running, not both.

Hello everyone!
I have a sparkfun 5V LCD screen, wired to an Atmega328p on breadboard.
I have managed to get the LCD printing text.
I also connected an 433Mhz reviever (and i have another Atmega328p on breadboard sending data through the corresponding 433Mhz emitter).

Both Atmega are running at 8Mhz, without external crystal.
Using virtualwire, i could transmit data between the two arduinos.

However, my problem is that once i want to revieve and print stuff on the LCD, i can only recieve the data.

If i remove the vw_setup(2000); in my setup function, the lcd prints what it is told to.
However, when i add the vw_setup(2000); back, i have no printing.
I noticed that anything above “vw_setup(2000);” is printed, and after that command nothing is printed.

Using the serial monitor, i can see that my data are beeing recieved correctly, when the LCD screen is connected, or when it is not there.
So in any case, the arduino recieve correctly the data.

Would anyone have an idea of why this is doing it?

I must say that previously the reciever whas on an Arduino Uno board, and i got it to work and display stuff on the screen, minus a small printing bug.
I do not use the same pins anymore, because i didn’t write down the previous pins on the Uno board. however, i made sure that the LCD works, then that the reciever works, and then that i had no conflicting pins.

i join the source code of the reciever :

#include <VirtualWire.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
    lcd.begin(16, 2);
    lcd.print("Milapli");
    delay(300);
  
    Serial.begin(9600);             
    vw_setup(2000);                 
    vw_set_rx_pin(8);               
    vw_rx_start();                  
}

void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    char buf2[VW_MAX_MESSAGE_LEN];

    if (vw_get_message(buf, &buflen))
    {
      int i;
      for (i = 0; i < buflen; i++)
      {
          buf2[i]= (char)buf[i];
      }
       char t[10];
       lcd.setCursor(0, 0);
       int i2=0;
       char line1[16];
       char line2[16];
       int returns=0;
       for (i = 0; i < buflen; i++)
       {
         if(buf2[i]=='\n')
         {
           buf2[i]=' ';
           returns=returns+1;
         }
         if(buf2[i]=='\0'){buf2[i]=' ';}
         if(returns==2){ lcd.setCursor(0, 1);}
          lcd.print(buf2[i]);
       }
      for (i = 0; i < buflen; i++)
      {
        Serial.write(buf2[i]);
      }
      Serial.println(""); 
    }
    lcd.setCursor(0, 1);
    lcd.print(millis()/1000);
}

Thanks in advance!

Virtualwire takes over timer1. "Caution: VirtualWire takes over Arduino Timer1, and this will affect the PWM capabilities of the digital pins 9 and 10."

Does the LCD library also try to use timer1?

I think the problem is the pin assignment.

vw_set_tx_pin(transmit_pin) Configure the transmit pin. Default is pin 12.

vw_set_rx_pin(receive_pin) Configure the receive pin, Default is pin 11.

vw_set_ptt_pin(transmit_en_pin) Configure the transmit enable pin, or "push to talk". Default is pin 10.

The tx pin is 12 by default. This is the conflict with the LCD, I would guess.

Cheers!

CrossRoads:
Virtualwire takes over timer1.
“Caution: VirtualWire takes over Arduino Timer1, and this will affect the PWM capabilities of the digital pins 9 and 10.”
Does the LCD library also try to use timer1?

Hello!
I just used <LiquidCrystal.h>, and i don’t know if it uses any timer. However, considering what kowalski said :

kowalski:
I think the problem is the pin assignment.
vw_set_tx_pin(transmit_pin)
Configure the transmit pin. Default is pin 12.
vw_set_rx_pin(receive_pin)
Configure the receive pin, Default is pin 11.
vw_set_ptt_pin(transmit_en_pin)
Configure the transmit enable pin, or “push to talk”. Default is pin 10.
The tx pin is 12 by default. This is the conflict with the LCD, I would guess.
Cheers!

I moved the LCD pins so that none of the conflicting pins are used by the LCD anymore, and i could get the LCD to print the recieved messages.

So many thanks, because i had no idea that pins would be used even if i didn’t configure them to!

Many thanks to both of you!