Conflict between VirtualWire library and RGB Matrix Panel?

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
tywalch
 
Posts: 26
Joined: Mon Jan 06, 2014 2:40 am

Conflict between VirtualWire library and RGB Matrix Panel?

Post by tywalch »

I am building a two screen scoreboard. One screen, operated by buttons and an Arduino Mega also has a 433Mhz transmitter on it which will send a signal to another arduino uno which will update values on that screen.

Below are two snippets of code. The first is the code for VirtualWire that when placed into the second (into the setup function) makes the screen go completely black. The second code is my button/screen code for the arduino mega that works perfectly. Lastly, when I put in the first snippet it compiles just fine. I've decided the first snippet is the problem by adding each part of the virtualwire code until it stopped working.

First Snippet:

Code: Select all

   vw_setup(1000); 
   vw_set_tx_pin(14);
Second Snippet (Works just fine):

Code: Select all

#include <Adafruit_GFX.h>   
#include <RGBmatrixPanel.h>

#define CLK 11
#define LAT A3
#define OE  10
#define A   A0
#define B   A1
#define C   A2
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);
int homeScoreFirstDigit;
int homeScoreSecondDigit;
int awayScoreFirstDigit;
int awayScoreSecondDigit;
uint8_t homeScoreAddDebounce = 0;
uint8_t homeScoreSubtractDebounce = 0;
uint8_t awayScoreAddDebounce = 0;
uint8_t awayScoreSubtractDebounce = 0;
uint8_t clearScoreDebounce = 0;

void setup() {
  matrix.begin();
  digitalWrite(A4, LOW);
  digitalWrite(A5, LOW);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  matrix.fillScreen(0);
}

void loop() {
  addHomeButton();
  subtractHomeButton();
  addAwayButton();
  subtractAwayButton();
  clearScore();
  
    matrix.setTextColor(matrix.Color333(7,0,0));
    matrix.print('H');
    matrix.setTextColor(matrix.Color333(7,0,0)); 
    matrix.print('M');
    matrix.setTextColor(matrix.Color333(7,0,0));
    matrix.print('E');
    matrix.setTextColor(matrix.Color333(7,0,7)); 
    matrix.print(homeScoreFirstDigit);
    matrix.setTextColor(matrix.Color333(7,0,7));  
    matrix.print(homeScoreSecondDigit);
  
    matrix.setCursor(1, 9);   // next line
    matrix.setTextColor(matrix.Color333(7,0,0)); 
    matrix.print('A');
    matrix.setTextColor(matrix.Color333(7,0,0)); 
    matrix.print('W');
    matrix.setTextColor(matrix.Color333(7,0,0));
    matrix.print('Y');
    matrix.setTextColor(matrix.Color333(7,0,7)); 
    matrix.print(awayScoreFirstDigit);
    matrix.setTextColor(matrix.Color333(7,0,7)); 
    matrix.print(awayScoreSecondDigit);
    delay(100);
}

void addHomeButton() {
    if(digitalRead(A4) == HIGH) {
    homeScoreAddDebounce = 0;
    return;
  }
  
  if(++homeScoreAddDebounce >= 5) {
    matrix.setCursor(1,0);
    matrix.setTextSize(1);
    homeScoreSecondDigit++;
  
    if (homeScoreSecondDigit > 9) {
      homeScoreSecondDigit = 0;
      homeScoreFirstDigit++;
    }
    
    delay(100);
    matrix.fillScreen(0);
    homeScoreAddDebounce = 0;
  }
}

void subtractHomeButton() {
    if(digitalRead(A5) == HIGH) {
    homeScoreSubtractDebounce = 0;
    return;
  }
  
  if (++homeScoreSubtractDebounce >= 5) {
    matrix.setCursor(1,0);
    matrix.setTextSize(1);
    homeScoreSecondDigit--;
    if ((homeScoreSecondDigit < 0) && (homeScoreFirstDigit > 0)) {
      homeScoreSecondDigit = 9;
      homeScoreFirstDigit--;
      if (homeScoreFirstDigit < 0) {
       homeScoreFirstDigit = 0; 
      }
    }
  else if ((homeScoreSecondDigit < 0) && (homeScoreFirstDigit == 0)) {
    homeScoreSecondDigit = 0;
  }
  delay(200);
  matrix.fillScreen(0);
  homeScoreSubtractDebounce = 0;
  }
}

void addAwayButton() {
    if(digitalRead(2) == HIGH) {
    awayScoreAddDebounce = 0;
    return;
  }
  
  if(++awayScoreAddDebounce >= 5) {
    matrix.setCursor(1,0);
    matrix.setTextSize(1);
    awayScoreSecondDigit++;
    
    if(awayScoreSecondDigit > 9) {
      awayScoreSecondDigit = 0;
      awayScoreFirstDigit++;
    }
    
    delay(100);
    matrix.fillScreen(0);
    awayScoreAddDebounce = 0;
  }
}
  
void subtractAwayButton() {
    if(digitalRead(3) == HIGH) {
    awayScoreSubtractDebounce = 0;
    return;
  }
  
  if (++awayScoreSubtractDebounce >=5) {
    matrix.setCursor(1,0);
    matrix.setTextSize(1);
    awayScoreSecondDigit--;
    if ((awayScoreSecondDigit < 0) && (awayScoreFirstDigit > 0)) {
      awayScoreSecondDigit = 9;
      awayScoreFirstDigit--;
      if (awayScoreFirstDigit < 0) {
       awayScoreFirstDigit = 0; 
      }
    }
  else if ((awayScoreSecondDigit < 0) && (awayScoreFirstDigit == 0)) {
    awayScoreSecondDigit = 0;
  }
  delay(200);
  matrix.fillScreen(0);
  awayScoreSubtractDebounce = 0;
  }
}
  
  void clearScore() {
   if(digitalRead(4) == HIGH) {
    clearScoreDebounce = 0;
   }
   
   if(++clearScoreDebounce >= 5) {
     matrix.setCursor(1,0);
     matrix.setTextSize(1);
     awayScoreFirstDigit = 0;
     awayScoreSecondDigit = 0;
     homeScoreSecondDigit = 0;
     homeScoreFirstDigit = 0;
     delay(200);
     matrix.fillScreen(0);
     clearScoreDebounce = 0;
   }
 }
Before you make the comment, I of course include the VirtualWire libraries to the second snippet when I add VW code.

User avatar
tywalch
 
Posts: 26
Joined: Mon Jan 06, 2014 2:40 am

Re: Conflict between VirtualWire library and RGB Matrix Pane

Post by tywalch »

tywalch wrote:I am building a two screen scoreboard. One screen, operated by buttons and an Arduino Mega also has a 433Mhz transmitter on it which will send a signal to another arduino uno which will update values on that screen.

Below are two snippets of code. The first is the code for the VirtualWire library that when placed into the second (into the setup function) makes the screen go completely black. The second code is my button/screen code for the arduino mega that works perfectly. Lastly, when I put in the first snippet it compiles just fine. I've decided the first snippet is the problem by adding each part of the virtualwire code until it stopped working.

First Snippet:

Code: Select all

   vw_setup(1000); 
   vw_set_tx_pin(14);
Second Snippet (Works just fine):

Code: Select all

#include <Adafruit_GFX.h>   
#include <RGBmatrixPanel.h>

#define CLK 11
#define LAT A3
#define OE  10
#define A   A0
#define B   A1
#define C   A2
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);
int homeScoreFirstDigit;
int homeScoreSecondDigit;
int awayScoreFirstDigit;
int awayScoreSecondDigit;
uint8_t homeScoreAddDebounce = 0;
uint8_t homeScoreSubtractDebounce = 0;
uint8_t awayScoreAddDebounce = 0;
uint8_t awayScoreSubtractDebounce = 0;
uint8_t clearScoreDebounce = 0;

void setup() {
  matrix.begin();
  digitalWrite(A4, LOW);
  digitalWrite(A5, LOW);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  matrix.fillScreen(0);
}

void loop() {
  addHomeButton();
  subtractHomeButton();
  addAwayButton();
  subtractAwayButton();
  clearScore();
  
    matrix.setTextColor(matrix.Color333(7,0,0));
    matrix.print('H');
    matrix.setTextColor(matrix.Color333(7,0,0)); 
    matrix.print('M');
    matrix.setTextColor(matrix.Color333(7,0,0));
    matrix.print('E');
    matrix.setTextColor(matrix.Color333(7,0,7)); 
    matrix.print(homeScoreFirstDigit);
    matrix.setTextColor(matrix.Color333(7,0,7));  
    matrix.print(homeScoreSecondDigit);
  
    matrix.setCursor(1, 9);   // next line
    matrix.setTextColor(matrix.Color333(7,0,0)); 
    matrix.print('A');
    matrix.setTextColor(matrix.Color333(7,0,0)); 
    matrix.print('W');
    matrix.setTextColor(matrix.Color333(7,0,0));
    matrix.print('Y');
    matrix.setTextColor(matrix.Color333(7,0,7)); 
    matrix.print(awayScoreFirstDigit);
    matrix.setTextColor(matrix.Color333(7,0,7)); 
    matrix.print(awayScoreSecondDigit);
    delay(100);
}

void addHomeButton() {
    if(digitalRead(A4) == HIGH) {
    homeScoreAddDebounce = 0;
    return;
  }
  
  if(++homeScoreAddDebounce >= 5) {
    matrix.setCursor(1,0);
    matrix.setTextSize(1);
    homeScoreSecondDigit++;
  
    if (homeScoreSecondDigit > 9) {
      homeScoreSecondDigit = 0;
      homeScoreFirstDigit++;
    }
    
    delay(100);
    matrix.fillScreen(0);
    homeScoreAddDebounce = 0;
  }
}

void subtractHomeButton() {
    if(digitalRead(A5) == HIGH) {
    homeScoreSubtractDebounce = 0;
    return;
  }
  
  if (++homeScoreSubtractDebounce >= 5) {
    matrix.setCursor(1,0);
    matrix.setTextSize(1);
    homeScoreSecondDigit--;
    if ((homeScoreSecondDigit < 0) && (homeScoreFirstDigit > 0)) {
      homeScoreSecondDigit = 9;
      homeScoreFirstDigit--;
      if (homeScoreFirstDigit < 0) {
       homeScoreFirstDigit = 0; 
      }
    }
  else if ((homeScoreSecondDigit < 0) && (homeScoreFirstDigit == 0)) {
    homeScoreSecondDigit = 0;
  }
  delay(200);
  matrix.fillScreen(0);
  homeScoreSubtractDebounce = 0;
  }
}

void addAwayButton() {
    if(digitalRead(2) == HIGH) {
    awayScoreAddDebounce = 0;
    return;
  }
  
  if(++awayScoreAddDebounce >= 5) {
    matrix.setCursor(1,0);
    matrix.setTextSize(1);
    awayScoreSecondDigit++;
    
    if(awayScoreSecondDigit > 9) {
      awayScoreSecondDigit = 0;
      awayScoreFirstDigit++;
    }
    
    delay(100);
    matrix.fillScreen(0);
    awayScoreAddDebounce = 0;
  }
}
  
void subtractAwayButton() {
    if(digitalRead(3) == HIGH) {
    awayScoreSubtractDebounce = 0;
    return;
  }
  
  if (++awayScoreSubtractDebounce >=5) {
    matrix.setCursor(1,0);
    matrix.setTextSize(1);
    awayScoreSecondDigit--;
    if ((awayScoreSecondDigit < 0) && (awayScoreFirstDigit > 0)) {
      awayScoreSecondDigit = 9;
      awayScoreFirstDigit--;
      if (awayScoreFirstDigit < 0) {
       awayScoreFirstDigit = 0; 
      }
    }
  else if ((awayScoreSecondDigit < 0) && (awayScoreFirstDigit == 0)) {
    awayScoreSecondDigit = 0;
  }
  delay(200);
  matrix.fillScreen(0);
  awayScoreSubtractDebounce = 0;
  }
}
  
  void clearScore() {
   if(digitalRead(4) == HIGH) {
    clearScoreDebounce = 0;
   }
   
   if(++clearScoreDebounce >= 5) {
     matrix.setCursor(1,0);
     matrix.setTextSize(1);
     awayScoreFirstDigit = 0;
     awayScoreSecondDigit = 0;
     homeScoreSecondDigit = 0;
     homeScoreFirstDigit = 0;
     delay(200);
     matrix.fillScreen(0);
     clearScoreDebounce = 0;
   }
 }
Before you make the comment, I of course include the VirtualWire libraries to the second snippet when I add VW code.

User avatar
tywalch
 
Posts: 26
Joined: Mon Jan 06, 2014 2:40 am

Re: Conflict between VirtualWire library and RGB Matrix Pane

Post by tywalch »

As a follow up, it seems to just be the following line that causes the LED matrix to go blank]

Code: Select all

vw_setup(1000); 

User avatar
pburgess
 
Posts: 4161
Joined: Sun Oct 26, 2008 2:29 am

Re: Conflict between VirtualWire library and RGB Matrix Pane

Post by pburgess »

Looks like both libraries are dependent on the Arduino's Timer/Counter 1. They won't work together unless one or the other can be modified to work with Timer/Counter 2. This is a big undertaking, and I have some doubts whether this can be done with the RGBmatrixPalen library...it's pretty deeply integrated into Timer/Counter 1 as I recall.

User avatar
tywalch
 
Posts: 26
Joined: Mon Jan 06, 2014 2:40 am

Re: Conflict between VirtualWire library and RGB Matrix Pane

Post by tywalch »

pburgess wrote:Looks like both libraries are dependent on the Arduino's Timer/Counter 1. They won't work together unless one or the other can be modified to work with Timer/Counter 2. This is a big undertaking, and I have some doubts whether this can be done with the RGBmatrixPalen library...it's pretty deeply integrated into Timer/Counter 1 as I recall.
What a bummer! Is there another easy way to communicate integer values between arduinos?

User avatar
pburgess
 
Posts: 4161
Joined: Sun Oct 26, 2008 2:29 am

Re: Conflict between VirtualWire library and RGB Matrix Pane

Post by pburgess »

Serial.write and read. Connect pin 0 on one Arduino to pin 1 on the other, and 1 to 0. You'd need to disconnect the two any time you upload code to one or the other (the bootloader uses the serial port for transferring code), and it kind of puts a damper on using Serial.print for debugging.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”