Pages: [1]   Go Down
Author Topic: Problem using the VirtualWire- and LiquidCrystal libraries together  (Read 426 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First post!

I have been using both VirtualWire and LiquidCrystal separately for some time now and today I tried to combine them, connecting a 16x2 LCD and a transmitter to my Leonardo. However I was not able to display any messages on the LCD and after some debuging I found that the vw_setup() function seems to interfere with the lcd.write/print functions. Giving the input value zero, vw_setup(0), would allow me to print but anything above that simply makes the LCD useless! Do you have any ideas on this?

Thanks for any help smiley
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 65
Posts: 2934
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How is your LCD wired? What wires are going into what pins. Might I suggest an I2C LCD
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It is wired just as in this picture but with power and ground to connections 15 and 16. And like I said, it works just fine whenever I remove vw_setup(). smiley-small



Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Where's your code?

Read this before posting a programming question
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 65
Posts: 2934
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Swap the wire in pin 11 with pin 8 and update your code.
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks a lot HazardsMind, it worked! Any good explanation to why?

I guess this was rather a question about the libraries, but here is however my code (after changing pin 11 to 8 ). The program uses a potentiometer to edit the values of a predefined array, 'disp', and then sends the whole thing with the VirtualWire functions:

 
Code:


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

LiquidCrystal lcd(12, 8, 5, 4, 3, 2);

boolean switch1value = 0;
boolean switch2value = 0;
boolean preswitch2value = 1;
const int switch1pin = 7;
const int switch2pin = 9;
const int transmitpin = 13;
double potSensor=0;
double potPart = 0;
int prePotSensor=0;
byte disp[] = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '};
int i = 0;
int elementcount = sizeof(disp); //längd av textarray


void setup () {
 
  lcd.begin(16,2);
  pinMode(transmitpin,OUTPUT);
  pinMode(switch1pin,INPUT);
  pinMode(switch2pin,INPUT);
  vw_set_tx_pin(transmitpin);
  vw_setup(2000); 
  Serial.begin(9600);

}

void loop() {

    switch1value = digitalRead(switch1pin);

 if(switch1value) { //sändning då switch1==1

    vw_send((uint8_t *)disp,elementcount); //sänd array
    vw_wait_tx(); //vänta tills sändning är avklarad
 
}
 
    switch2value = digitalRead(switch2pin);
 
 if(switch2value) { //edit då switch2 == 1
       
   lcd.setCursor(0,0);
   lcd.print("Välj meddelande:");
   
   while(1) {

    switch2value = digitalRead(switch2pin);
    switch1value = digitalRead(switch1pin);
   
    if(switch1value) {
     
      lcd.clear();
      i=0;
      preswitch2value = 1;
      break;
     
      } //avslutar whileloop
   
    if(switch2value == 1 && switch2value != preswitch2value) {
      i++;
      } //byter element i arrayet disp

    for(int cp = 0; cp < sizeof(disp); cp++) { //printa disp
      int k = disp[cp];
      lcd.setCursor(cp,1);
      lcd.write(k);
     }

  potSensor = analogRead(1); //avläs potentiometer
     
  disp[i] = 65 + round(potSensor)/40;//byt DEC-värde på respektive tecken i disp
     
  preswitch2value = switch2value;
       
    }
  }
 
}

« Last Edit: August 13, 2013, 06:23:50 pm by oskarbjo » Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Read this before posting a programming question

Code tags please.
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 65
Posts: 2934
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You need to put your code in the proper code tags, its the # above the smiley faces.

The reason it works now is because the virtual wire library takes over pins 10 and 11, so if your using the VW library, you wont be able to use those pins.
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Aha, so that's it. Thanks a lot for telling me!
Logged

Pages: [1]   Go Up
Jump to: