Reading array values disables virtual wire

This is somewhat of a followup of this thread I started a while ago: http://forum.arduino.cc/index.php?topic=167109

I am having trouble getting my program to work properly with virtual wire. I have attached the entire source of both the transmitter and receiver for inspection but I seam to have isolated the issue. I am using 2 Arduino Micros for the project.

I have a 24x15 LED matrix that uses a set of arrays to dictate the currently displayed frame. I then have a radio receiver hooked up to the matrix that gets a signal from a separate Arduino. This works perfectly under most situations.

The problem is that certain “frames” from some of the animation arrays stop the radio receiver from getting a message but I can’t quite figure out why it does so.

For example, this array works perfectly:

PROGMEM const byte cautionSignal[defaultAnimationsFrameCount][rowCount][columnCount] = {
  { { 1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1 }, { 0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0 }, { 1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1 }, { 0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0 }, { 1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1 }, { 0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0 }, { 1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1 }, { 0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0 }, { 1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1 }, { 0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0 }, { 1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1 }, { 0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0 }, { 1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1 }, { 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0 }, { 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1 }, },
  { { 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1 }, { 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0 }, { 1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1 }, { 0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0 }, { 1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1 }, { 0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0 }, { 1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1 }, { 0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0 }, { 1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1 }, { 0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0 }, { 1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1 }, { 0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0 }, { 1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1 }, { 0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0 }, { 1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1 }, },
};

But this array stops the radio receiving completely:

PROGMEM const byte sorrySignal[defaultAnimationsFrameCount][rowCount][columnCount] = {
  { { 0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0 }, { 0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0 }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,0,0,0,0,0,0,0,0,1 }, { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }, { 1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1 }, { 1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1 }, { 0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0 }, { 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0 }, { 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0 }, { 0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0 }, { 0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0 }, },
};

But! If I change the same “sorrySignal” array value to the same value of the “cautionSignal”, it works perfectly - receives the radio messages just fine. Each animation has 2 frames and if I change one of the “sorrySignal” frames to either of the “cautionSignal” frames, I only receive messages when the good frame is being displayed.

I am really struggling to figure out what it is in certain frames that is killing the radio. You can find all the code attached and the 2 main functions in the receiver are called byte getBlinkState(int a, int b) and boolean receiveRadioMessage(). If anyone can help I would appreciated it oh so very much.

Backpack.ino (14.9 KB)

Arrays.h (22.7 KB)

Transmitter.ino (2.55 KB)

So, what is returned by getBlinkState() that is different? Does that function have problems reading from one array vs. the other? Are the two arrays the same size? (Running arrays DOWN the page is better than ACROSS the page, in my opinion. It's easier to count rows than columns.)

Since getBlinkState() doesn't seem to have anything to do with the radio data collection, I wouldn't think that it is related to the problem, unless the data about the array doesn't match the array itself.

    if (48 == message) {
      //Serial.println("animation caution received");
      
      receivedAnimationKey = ANIMATION_KEY_CAUTION;
    }
    else if (50 == message) {
      //Serial.println("animation left turn received");
      
      receivedAnimationKey = ANIMATION_KEY_LEFT;
    }
    else if (49 == message) {

Ugh! How am I supposed to know what to put in the message to make stuff happen?

    if ('0' == message) {
      //Serial.println("animation caution received");
      
      receivedAnimationKey = ANIMATION_KEY_CAUTION;
    }
    else if ('2' == message) {
      //Serial.println("animation left turn received");
      
      receivedAnimationKey = ANIMATION_KEY_LEFT;
    }
    else if ('1' == message) {

Now, it's much easier to know...

Knowing what is in the message that is not read correctly would be useful information. Knowing whether it is not read correctly or does not cause the correct behavior would be useful, too. (No, I didn't look at you other thread - you did start a new one, so summarizing the issues here is necessary.)

Sorry, I should have gotten much more specific and made my code more readily available in the post instead of as a download.

My transmitter right now is sending a char number between 0 and 5. This char designates what animation will be displayed. This works just fine.

The problem is in my getBlinkState() function. If I just read an animation array key that it doesn't like then my radio receiver stops working (until it is again reading an animation array key that it likes). My animation arrays are byte arrays of 0's and 1's with a 0 indicating that the LED is off and a 1 indicating that it is on. My arrays look like this:

PROGMEM const byte cautionSignal[defaultAnimationsFrameCount][rowCount][columnCount] = {
  {
   { 1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1 },
   { 0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0 },
   { 1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1 },
   { 0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0 },
   { 1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1 },
   { 0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0 },
   { 1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1 },
   { 0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0 },
   { 1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1 },
   { 0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0 },
   { 1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,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 },
  },
};

This is an example of an array that it likes and which works perfectly at all times. But, if I turn this array into this:

PROGMEM const byte cautionSignal[defaultAnimationsFrameCount][rowCount][columnCount] = {
  {
    { 0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0 },
    { 0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0 },
    { 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0 },
    { 0,0,1,0,0,1,1,1,1,0,0,0,0,0,0,1,1,1,1,0,0,1,0,0 },
    { 0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 },
    { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
    { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
    { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
    { 1,0,0,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,0,0,1 },
    { 1,0,0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,1,0,0,0,0,0,1 },
    { 0,1,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0 },
    { 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0 },
    { 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0 },
    { 0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0 },
    { 0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0 },
  },
  {
    { 0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0 },
    { 0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0 },
    { 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0 },
    { 0,0,1,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,1,0,0 },
    { 0,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0 },
    { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
    { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
    { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
    { 1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1 },
    { 1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1 },
    { 0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0 },
    { 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0 },
    { 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0 },
    { 0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0 },
    { 0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0 },
  },
};

Then the radio receiver stops being able to receive the message. I must stress that everything else works perfectly at all times. The animation is displayed correctly, no errors, no nothing.

I know it is something with reading an array key that the program doesn't like. If I take key 0 (the entire animation frame array) from the first working array and put into the not-working array as key 0 (just replace the bad with the good, then the radio receiver only works while key 0 is being read from the array. I have tried multiple configurations of good and bad and there is just something about certain arrays that it just doesn't like. So, for example this only works half of the time (while reading key 0):

PROGMEM const byte cautionSignal[defaultAnimationsFrameCount][rowCount][columnCount] = {
  {
       { 1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1 },
   { 0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0 },
   { 1,0,1,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
    { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
    { 1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1 },
    { 1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1 },
    { 0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0 },
    { 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0 },
    { 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0 },
    { 0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0 },
    { 0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0 },
  },
};

I have a timer that switches the key to be displayed (each key is 1 frame, each frame stays active for about a second) but I check for a radio message much much more frequently. It is only during these bad frames that I can not receive a radio message. I have not been able to test too fully about what exact line or lines in the array are killing it but it must be that since just changing the array values to one that I know works is enough to fix the issue - no other changes needed.

Any idea what could be causing that?

I know it is something with reading an array key that the program doesn't like.

Arrays don't have keys. They have elements. It is unlikely that the VALUE read from the array element is the problem. Instead, I think that it is more likely that WHERE the value is read from is the problem.

At the start of getBlinkState(), print the inputs.

Before returning from the function, print the value that it is going to return.

If you see inputs but no outputs, you know the problem. If you see inputs and trash for the output, you know the problem.

If you see good input and good output, then the getBlinkState() function is not the problem.

PaulS: Arrays don't have keys. They have elements. It is unlikely that the VALUE read from the array element is the problem. Instead, I think that it is more likely that WHERE the value is read from is the problem.

Sorry, I come from PHP where we call them "keys" but anyway, no matter.

I tried as you suggested but everything was in order. No values were returned other than 1 or 0 (correct) and input variable "a" went from 0 - 14 (correct) and variable "b" went from 0-23 (correct). No missing anything. This makes sense though since the correct LEDs always light up.

You say that it is probably WHERE the value is read from but in what way could that be the problem? It just seams odd that if I change the array to just have a different arrangement of 1's and 0's (same total number, all good to go) it will affect if the radio receiver works.

What else can I try to track down the problem?

You say that it is probably WHERE the value is read from but in what way could that be the problem?

Where would be a problem if you tried reading from array[23][157] wouldn't it?

What else can I try to track down the problem?

Put debug statements in the code that reads from the radio. That seems to be where the problem is happening.

PaulS:
Put debug statements in the code that reads from the radio. That seems to be where the problem is happening.

I have debug code there. I don’t know what else to put other than a “checking for message” when the function is called and a “got message” if anything is received. These already exist and it is just that I never get to the “got message” when these certain elements are in use.

I tried a few other things and noticed that if I try to get the radio message every time I write out a single row to the LED board, then the same rows always block the receiving of the radio message. But, if I take the rows that do not block the receiver and make the array element just those lines, that does not work either.

There is some sort of magic combination that I can’t figure out that causes it but to try every combo would take years. There has to be something more logical to this.

You have some fairly big non-trivial data sets there. The symptoms suggest memory corruption, so the first thing I would check is whether you are running out of memory and the second thing would be whether you are reading beyond the bounds of any of your arrays. I don't spot any writing to arrays in a quick scan through, but if you're doing that then also check whether you're writing past the bounds of any array.

PeterH: You have some fairly big non-trivial data sets there. The symptoms suggest memory corruption, so the first thing I would check is whether you are running out of memory and the second thing would be whether you are reading beyond the bounds of any of your arrays. I don't spot any writing to arrays in a quick scan through, but if you're doing that then also check whether you're writing past the bounds of any array.

I thought that it could be a memory issue but that doesn't make sense if certain array value combinations work while others don't. I mean, no matter what the array values are, they take the same amount of memory.

Also, if I edit the code to change the "currentAnimationKey" variable (the variable that determines which array is read) from the console, then everything works perfectly. Meaning if I change the program so that if I type "1" into the console, then currentAnimationKey = 1 and so on for all the animations. I tried this, and it was able to read everything properly so I don't think it is a memory issue.

If I calculate the size of my Arrays.h file (where all the animation arrays are stored) I get: 1 animation = 720 bytes (byte variable = 8 bits * 24 (column count) * 15 (row count) * 2 (frame count)) All animations (6 total) = 4.2kb Alphabet definitions = 3.5kb (byte variable = 8 bits * 9 (letter columns width) * 15 (row count) * 27 (letters in my alphabet)) Total size of my arrays = 7.7kb all stored in PROGMEM

Since I am using a Micro, I have (32 KB - 4) = 28 KB of available flash memory which is plenty for my 7.7 KB arrays. If my calculations are incorrect, please correct me.

And no, there is no writing to the arrays.

Sorry to reply to myself but I have tracked things down a bit more.

I have a loop that writes each row of the LED matrix 1 by 1 and a function that sets the bits to send to the shift registers and then pushes those bits out. This loop and function look like this:

//blink 1 row at a time
  for (int i = 0; i < rowCount; i++) {
    for (int y = 0; y < columnCount; y++) {
      blinkRowStates[y] = getBlinkState(i, y);
    }
    
    writeRow(i);
  }

//used only if we are blinking row by row only
void writeRow(int row) {
  byte bitsToSend0 = 0;
  byte bitsToSend1 = 0;
  byte bitsToSend2 = 0;
  byte bitsToSend3 = 0;
  byte bitsToSend4 = 0;
  
  if (row <= 7) {
    bitWrite(bitsToSend1, row, HIGH);
  }
  else {
    bitWrite(bitsToSend0, (row - 8), HIGH);
  }
  
  for (int i = 0; i < columnCount; i++) {
    if (0 == blinkRowStates[i]) {
      continue;
    }
    
    if (i <= 7) {
      bitWrite(bitsToSend4, i, HIGH);
    }
    else if (i <= 15) {
      bitWrite(bitsToSend3, (i - 8), HIGH);
    }
    else if (i <= 23) {
      bitWrite(bitsToSend2, (i - 16), HIGH);
    }
  }
  
  digitalWrite(latchPin, LOW);
  
  // shift the bits out
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend0);
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend1);
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend2);
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend3);
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend4);
  
  // turn on the output so the LEDs can light up:
  digitalWrite(latchPin, HIGH);
}

Now, this works properly with the proper LEDs lighting up and everything, good. But, as I have been staying, when certain arrays are being read if they have a certain configuration of 0’s and 1’s then the radio receiver stops working.

I played around a bit and if I comment out the “digitalWrite(latchPin, HIGH);” line, then everything works perfectly all the time. Well, except the LEDs don’t light up obviously - but the radio receiver always works.

I did another test while running an animation that works with the receiver and if I unplug the latch pin from the arduino, the radio receiver stops working. As soon as I put it back in, I get messages again.

This is very strange to me because the only parts of the circuit that are shared by the radio receiver and shift registers is the 5V and Ground lines.

Attached is my circuit diagram. In it I have 4 registers for the columns but in my actual version, I only have 3.

Edit:
Another oddity - if I disconnect any of the pins for the shift registers (dataPin, clearPin, latchPin, or clockPin) from the Arduino, the radio receiver stops working. I don’t quite understand the relationship between these pins and the pin that I am using for the incoming data from the radio receiver.

schmatic.sch (29.1 KB)

Do you still get the problem if you reinstate that line of code but physically disconnect the corresponding output pin so nothing is being switched by it?

Edit: corrected 'by' to 'but'.

PeterH: Do you still get the problem if you reinstate that line of code by physically disconnect the corresponding output pin so nothing is being switched by it?

If I uncomment that line and put all the code back to the desired state, then if I physically remove any of the pins connected to the shift registers (with the exception of the dataPin) the radio receiver stops working - regardless of the animation array that is being used at the time.

Edit: Since I have 2 Micros I thought maybe that one is slightly defective but I switched them and still there is the exact same situation.

Can you clarify - did you reinstate the code to write to the latch pin and then disconnect the circuit from the latch pin (leaving everything else unchanged) and see the same problem?

PeterH: Can you clarify - did you reinstate the code to write to the latch pin and then disconnect the circuit from the latch pin (leaving everything else unchanged) and see the same problem?

Yes - I reinstated the code to write the latch pin. When I am reading the working arrays all works exactly as it should.

Then, when I physically disconnect the latch pin from the circuit (leaving everything else the same), I get the same problem. But, no matter what array is being read I still get this error. So, everything is working and I am getting messages because I am reading the good array and then when I physically disconnect the latch pin, I stop getting messages until I plug it back in.

That suggests that the radio receiver is affected by the latch pin in some way, although as far as I can understand it you didn't intend that.

You need to look at the circuit connecting the receiver and find out how that could be influenced by output to the latch pin. The effect could be indirect since the latch pin will (presumably) be affecting the device it is connected to and causing the device's outputs to change state. Sorry that this probably isn't very helpful and I suppose you've already figured that part for yourself, but I think it's your only option. Perhaps if you posted a circuit drawing somebody else may be able to spot a possible cause.

Yes I figure there is some strange connection between this latch pin and the radio receiver.

Another thing I have just noticed though is that if I physically remove both the latch pin and the clear pin from the circuit, then it works again. But, if I have only 1 of them plugged in (either or), then it doesn’t work. This suggests some deeper connection but I am not sure what it is. I am not positive on what the clear pin actually does as I am just setting it to HIGH in my setup() and leaving it at that. If I don’t have it plugged in though then my registers go crazy. I couldn’t really find anything about it online though since nearly all shift register tutorials don’t have that pin anywhere.

I had attached my circuit diagram in a previous post but I will attach it to this post as well.

Edit: I have also found out that if I disconnect the clear pin only (leaving all other pins in the proper place) then I can play it like a Theremin. Basically, if I disconnect the clear pin wire - the radio receiver stops working. But, if I place my hand near the whole circuit, the radio receiver starts working again. I tried putting in code to hold the clear pin low while I looked for a radio signal and then reset it to high whenever I start pushing data out to the registers but this didn’t help at all.

Holding the clearPin to ground makes my radio receiver work just fine but if I hold the clearPin to the 5V line, then all the regular issues stick around.

schmatic.sch (29.1 KB)

Bump but with some more information. If I try wait to receive a message after every row write I get some strange results.

I am using this loop to write each row and at the same time try to receive a radio message:

for (int i = 0; i < rowCount; i++) {
    for (int y = 0; y < columnCount; y++) {
      blinkRowStates[y] = getBlinkState(i, y);
    }
    
    writeRow(i);
    
    //turning clearPin to low does not affect the results sadly
    //commenting it out gives the same results
    digitalWrite(clearPin, LOW);
    for (int z = 0; z < 10000; z++) {
      if (receiveRadioMessage()) {
        Serial.print("z: ");
        Serial.print(z);
        Serial.print(" row: ");
        Serial.println(i);
        break;
      }
      delay(1);
    }
    //turning it high here has no affect in result times
    //commenting it out gives the same results
    digitalWrite(clearPin, HIGH);
}

My receiveRadioMessage() function looks like this:

boolean receiveRadioMessage() {
  //vw_wait_rx();
  
  byte buf[VW_MAX_MESSAGE_LEN];
  byte buflen = VW_MAX_MESSAGE_LEN;
  //Serial.println("checking for a message");
  
  if (vw_get_message(buf, &buflen)) { // Non-blocking
    return true;
  }
  
  return false;
}

And lastly, my writeRow() function looks like this:

void writeRow(int row) {
  byte bitsToSend0 = 0;
  byte bitsToSend1 = 0;
  byte bitsToSend2 = 0;
  byte bitsToSend3 = 0;
  byte bitsToSend4 = 0;
  
  if (row <= 7) {
    bitWrite(bitsToSend1, row, HIGH);
  }
  else {
    bitWrite(bitsToSend0, (row - 8), HIGH);
  }
  
  for (int i = 0; i < columnCount; i++) {
    if (0 == blinkRowStates[i]) {
      continue;
    }
    
    if (i <= 7) {
      bitWrite(bitsToSend4, i, HIGH);
    }
    else if (i <= 15) {
      bitWrite(bitsToSend3, (i - 8), HIGH);
    }
    else if (i <= 23) {
      bitWrite(bitsToSend2, (i - 16), HIGH);
    }
  }
  
  digitalWrite(latchPin, LOW);
  
  // shift the bits out
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend0);
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend1);
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend2);
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend3);
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend4);
  
  // turn on the output so the LEDs can light up:
  digitalWrite(latchPin, HIGH);
}

Using an array that receives messages well such as this one:

{
	{ 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1 },
	{ 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0 },//1
	{ 1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1 },
	{ 0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0 },//3
	{ 1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1 },
	{ 0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0 },//5
	{ 1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1 },
	{ 0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0 },//7
	{ 1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1 },
	{ 0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0 },//9
	{ 1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1 },
	{ 0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0 },//11
	{ 1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1 },
	{ 0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0 },//13
	{ 1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1 },
},

Results in:
After writing odd number rows it usually takes a long time to receive a message, on average 117ms.
After writing even rows it almost always requires 58ms to receive a message.
These times and rows can vary slightly in their results but the 117ms and 58ms times make up 85% of the results.

Using an array that almost never receives messages such as this one:

{
	{ 0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0 },
	{ 0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0 },//1
	{ 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0 },
	{ 0,0,1,0,0,1,1,1,1,0,0,0,0,0,0,1,1,1,1,0,0,1,0,0 },//3
	{ 0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 },//4
	{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
	{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
	{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
	{ 1,0,0,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,0,0,1 },//8
	{ 1,0,0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,1,0,0,0,0,0,1 },//9
	{ 0,1,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0 },
	{ 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0 },//11
	{ 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0 },
	{ 0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0 },
	{ 0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0 },//14
},

With this array, after writing these rows it can take quite a long time to receive a message: 1, 3, 4, 8, 9, 11, 14
These rows take either 418ms, 358ms, 238ms, 178ms, 298ms to receive a message.
When writing the rest of the rows it takes either 58ms or 59ms to receive a message but always one of those times.
As with the other array, these numbers can vary slightly but 85% of the time it is the same.

Edit: attached a jpeg of my circuit

Without looking at your circuit in detail, the latest description makes me suspect that you have conflicting pin assignments and some of the pins you're using for the virtual wire interface are either floating (and happen to be influenced in a benign way by adjacent pins when they're connected) or are actually connected to something you're driving via the LED output circuits.

Sorry again, because I'm sure this is not a new idea, but that's all that occurs to me.

IMO it is time to simplify the circuit and sketch to try to prove that the two functional areas are independent of each other.

Maybe the problem is not in the coding, but is radio interference. Patterns from the array of 1/0 s may match up with the frequency of the receiver, and produce radio interference. Do you have wires of any length that could be acting as an antenna? Can you isolate the receiver more from the board. Maybe split the power supply, put caps in. My 2cents worth.

@PeterH - This idea did cross my mind but I wasn't sure what could be doing it but I just thought of one idea. There is this PTT built into the virtualwire library that is always set to an input when i run the setup function for virtual wire. I have nothing connected to this pin so it is floating always - maybe this could be the issue? When I get home, I will ground this pin and see what happens but I am not holding my breath for sure.

@jackwp - I have many "longer" wires attached to this since I have it all wired up on 2 breadboards. I thought about the interferance issue so I tried moving the transmitter further away from the receiver (the transmitter is batter powered at the moment) but it didn't help. I did try to separate the receiver from the other circuit with different ground before but no luck. I will see if I can get power / ground the transmitter via a battery and hold it as far away as possible from the rest of the circuit while still connecting the data pin to the arduino...maybe this will work?

Also, what do you mean be "split the power supply, put caps in"?