Pages: [1] 2   Go Down
Author Topic: VirtualWire receiver never gets its message  (Read 1084 times)
0 Members and 1 Guest are viewing this topic.
Estonia
Offline Offline
Full Member
***
Karma: 1
Posts: 180
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a radio receiver wired up with an LED array (32 x 15) and am trying to define the animation that is displayed on the LED array based off of what the radio receiver...receives. The problem right now though is that the VirtualWire library is never receiving a message in the main program. But, in the test program (same wiring and everything) I receive all the messages just fine.

The test program that receives everything and which works correctly is here:
Code:
#include <VirtualWire.h>

//Pin to receive data from the radio receiver
const byte receivePin = 4;

void setup() {
  //set pins to output because they are addressed in the main loop
  Serial.begin(9600);
  Serial.println("*");
 
  vw_set_ptt_inverted(true); // Required for DR3100
  vw_set_rx_pin(receivePin);
  vw_setup(2000);// Bits per sec
  vw_rx_start();// Start the receiver PLL running
}

void loop() {
  byte buf[VW_MAX_MESSAGE_LEN];
  byte buflen = VW_MAX_MESSAGE_LEN;
 
  if (vw_get_message(buf, &buflen)) { // Non-blocking
    Serial.println("RECEIVE");
    for (int i = 0; i < buflen; i++) {
      char asciiChar = buf[i];
      Serial.print(asciiChar);
    }
   
    Serial.println();
  }
}

The program that I have that is not receiving anything is attached (slightly too big to post, 672 lines) and the function that is supposed to read the message(s) starts on line 444. In this program you see that I Serial.println() and I always get the message "checking for a message" in my console but I never get "got a message" in the attached program.

Could this be a memory issue? I did try to comment out the largest of my boolean arrays but it didn't help at all. The animations play perfectly fine in the LED board always, but I just can't receive a radio message.

* Backpack.ino (64.43 KB - downloaded 17 times.)
Logged

London-UK
Offline Offline
Full Member
***
Karma: 1
Posts: 106
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Instead of doing posts with a fraction of the program, attach the whole file. At the bottom when you write your post, "Additional options" ...
Then we can see the problem.
Logged

Estonia
Offline Offline
Full Member
***
Karma: 1
Posts: 180
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Instead of doing posts with a fraction of the program, attach the whole file. At the bottom when you write your post, "Additional options" ...
Then we can see the problem.
Im not sure what you mean, I did attach the whole program as an additional file and the code within the post is just the example code that I used to prove that everything is wired up and functioning correctly.
Logged

Estonia
Offline Offline
Full Member
***
Karma: 1
Posts: 180
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry to reply to myself but after a bit more screwing around I found something strange. In an old post that I had here I had the same issue.

Basically, when the program that I attached in my original post has the variable of "currentFrameKey" set to 0, I can not receive any input from the radio receiver. If the currentFrameKey variable is set to anything else, I get my data in.

Why / how could this be?
Logged

London-UK
Offline Offline
Full Member
***
Karma: 1
Posts: 106
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Im not sure what you mean, I did attach the whole program as an additional file and the code within the post is just the example code that I used to prove that everything is wired up and functioning correctly.
didn't see that part. it was late. sorry.
Logged

0
Offline Offline
Jr. Member
**
Karma: 3
Posts: 82
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

1.  Booleans are a whole byte large.  Since you need such large arrays of them, consider packing them into bytes to save a significant amount of space.
2.  This is how you should approach this problem: Start with something that works.  Add in piece by piece the rest of your program until it breaks.  Bingo!  You know what the issue is now.
Logged

Estonia
Offline Offline
Full Member
***
Karma: 1
Posts: 180
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

1.  Booleans are a whole byte large.  Since you need such large arrays of them, consider packing them into bytes to save a significant amount of space.

Oh, I thought that booleans were smaller in memory size than bytes but apparently not. How many bits does a boolean take up? Is there any way to use only 1 bit of memory to store a value of either 0 or 1? I thought that boolean would be that but alas, nope. The smallest I can find is byte but that still takes 8 bits of memory.

Edit:
I found the problem line in the code - in the function writeRow(int row) if I comment out the line digitalWrite(latchPin, HIGH); then I receive all radio messages just perfectly. Obviously this is a problem since if I don't turn the latchPin high the shift registers never turn off/on. How / why could this affect it?
« Last Edit: May 20, 2013, 05:14:04 am by shiznatix » Logged

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

Just a heads up, you cant use any PWM on pins 9 or 10, because the virtualwire library uses that timer. If you have anything on 9 or 10 it will give you weird results.
Logged

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

Estonia
Offline Offline
Full Member
***
Karma: 1
Posts: 180
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just a heads up, you cant use any PWM on pins 9 or 10, because the virtualwire library uses that timer. If you have anything on 9 or 10 it will give you weird results.
Well I wasn't using the PWM abilities but I did move the clear pin and clock pins from 9 and 10 to pins 2 and 3. Sadly, this didn't change anything, I still have to comment out digitalWrite(latchPin, HIGH); to receive any radio messages. The latchPin is set to pin 11 on my Mirco.
Logged

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

digitalWrite(latchPin, HIGH); ?
I was under the impression that you were using the code you posted above. What code are you using now?
Logged

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

Estonia
Offline Offline
Full Member
***
Karma: 1
Posts: 180
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

digitalWrite(latchPin, HIGH); ?
I was under the impression that you were using the code you posted above. What code are you using now?
The code posted in my first post is just proof that all my stuff is wired up correctly. The code that isn't working properly is the code that is attached as a file to my first post.
Logged

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

I see that you have two digitalWrite(latchPin, HIGH); Which one are you commenting out?
Im also wondering if it is because of your AcceleroMMA7361.h library, did you copy those pin arrangements from an example sketch? They might already be set to output as PWM, from within the library.

In the code you posted before, try to insert the library along with the same pins for clock, latch, data, and clear, and see if your able to receive data. Is that also the same library for your animation stuff?

One last thing, you can make a seperate tab and store your program mem arrays in it, so that your code does not look so cluttered. Just make sure to save it as a .h file and remember to #include it. If you want an example of what Im talking about, download the Gameduino library, and open up the Ball sketch.
Logged

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

Estonia
Offline Offline
Full Member
***
Karma: 1
Posts: 180
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, I have tried to make the most basic program that has this error which is here:
Code:
#include <VirtualWire.h>

//Pin to clear the register
const byte clearPin = 2;
//Pin connected to clock pin (SH_CP) of 74HC595
const byte clockPin = 3;
//Pin connected to latch pin (ST_CP) of 74HC595
const byte latchPin = 11;
//Pin connected to Data in (DS) of 74HC595
const byte dataPin = 12;

//Pin to receive data from the radio receiver
const byte receivePin = 4;

void setup() {
  //set pins to output because they are addressed in the main loop
  pinMode(clearPin, OUTPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT); 
  pinMode(clockPin, OUTPUT);
  Serial.begin(9600);
  Serial.println("*");
 
  // Always start by sentting SRCLR high
  digitalWrite(clearPin, HIGH);
 
  vw_set_ptt_inverted(true); // Required for DR3100
  vw_set_rx_pin(receivePin);
  vw_setup(2000);// Bits per sec
  vw_rx_start();// Start the receiver PLL running
}

void loop() {
  getMessage();
  writeRow(5);
  delay(500);
 
  getMessage();
  writeRow(6);
  delay(500);
}

void getMessage() {
  byte buf[VW_MAX_MESSAGE_LEN];
  byte buflen = VW_MAX_MESSAGE_LEN;
 
  if (vw_get_message(buf, &buflen)) { // Non-blocking
    Serial.print("RECEIVE: ");
    for (int i = 0; i < buflen; i++) {
      char asciiChar = buf[i];
      Serial.print(asciiChar);
    }
   
    Serial.println();
  }
}

//used only if we are blinking row by row only
void writeRow(int row) {
  Serial.print("write row: ");
  Serial.println(row);
  byte bitsToSend0 = 0;
  byte bitsToSend1 = 0;
  byte bitsToSend2 = 0;
  byte bitsToSend3 = 0;
  byte bitsToSend4 = 0;
  byte bitsToSend5 = 0;
 
  if (row <= 7) {
    bitWrite(bitsToSend1, row, HIGH);
  }
  else {
    bitWrite(bitsToSend0, row - 8, HIGH);
  }
 
  for (int i = 0; i < 32; i++) {
    if (i <= 7) {
      bitWrite(bitsToSend5, i, HIGH);
    }
    else if (i <= 15) {
      bitWrite(bitsToSend4, i - 8, HIGH);
    }
    else if (i <= 23) {
      bitWrite(bitsToSend3, i - 16, HIGH);
    }
    else {
      bitWrite(bitsToSend2, i - 24, 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);
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend5);
 
  // turn on the output so the LEDs can light up:
  digitalWrite(latchPin, HIGH);
}
The output is as follows:
Quote
write row: 6
write row: 5
write row: 6
write row: 5
write row: 6
write row: 5
RECEIVE: vBHrz0ZqM70
write row: 6
RECEIVE: vBHrz0ZqM70
write row: 5
write row: 6
write row: 5
write row: 6
write row: 5
RECEIVE: vBHrz0ZqM70
write row: 6
RECEIVE: vBHrz0ZqM70
write row: 5
write row: 6
write row: 5
write row: 6
write row: 5
write row: 6
RECEIVE: vBHrz0ZqM70
write row: 5
RECEIVE: vBHrz0ZqM70
write row: 6
write row: 5
write row: 6
write row: 5
write row: 6
RECEIVE: vBHrz0ZqM70
write row: 5
RECEIVE: vBHrz0ZqM70
write row: 6
write row: 5
write row: 6
So you can see that sometimes, it just doesn't work properly but with some pattern to it.

Also, with this sketch, the lights are not lighting up very properly. The shift register that I am sending bit "bitsToSend2" is always out of sync in a way, not lighting up until it switches for only a brief instant. I have a capacitor between the ground and VCC on this register and if I hold the capacitor between my fingers then it works just fine. I am not sure if that has anything to do with it but it is still quite strange.

Any ideas?
Logged

Estonia
Offline Offline
Full Member
***
Karma: 1
Posts: 180
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

*bump* can anyone see why I am only receiving radio messages some of the time? I should get the "RECEIVE: ..." message between each blink (the transmitter is transmitting quite quickly) but it only comes every so many seconds as shown.
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 86
Posts: 3466
"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 might need to add vw_wait_rx(); Maybe it will help, maybe not.
Logged

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

Pages: [1] 2   Go Up
Jump to: