Pages: [1]   Go Down
Author Topic: Project keeps randomly crashing  (Read 334 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 0
Posts: 145
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've got 2 Arduino's running. One transmits 4 numbers every minute via a 433MHZ wireless module at 1200 baud (Using VirtualWire)

The other receives these numbers and sends them to the PC via a serial port. The numbers transmitted to computer are in the format "*,no1, no2, no3, no4,#"

Everything is so far working great - the problem I've found is that the receiver randomly stops working (most of the time after an  hour)

If I reset the receiver it starts working again.

I've posted my code below, does anything stand out which could cause a problem. Hopefully I'm missing something simple as I can't understand why the code stops. It seems pretty simple enough.

Code:
#include <VirtualWire.h>

#define rxPin 4
#define txPin 5

int numbers[4];

void setup()
{
 vw_setup(1200); // Bits per sec
 vw_rx_start(); // Start the receiver PLL running

    Serial.begin(9600);
}

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

  if (vw_get_message(buf, &buflen)) // check to see if anything has been received
  {
    Serial.print("*");          //Start Bit
    for (int i = 0; i < 4; i++)
    {
      numbers[i] = word(buf[i*2+1], buf[i*2]);
      Serial.print(numbers[i], DEC);
      Serial.print(",");
    }
   Serial.print("#");          //Stop Bit
  }
  delay(50);
}
Logged

Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 217
Posts: 13742
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

  if (vw_get_message(buf, &buflen)) // check to see if anything has been received

OK you check if anything has been received but you don't check how much -> buflen  ???

=> add  serial.print(buflen, DEC); to check if there is the problem.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

0
Offline Offline
Full Member
***
Karma: 0
Posts: 145
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the tip - I'll have a look at that.
Logged

Pages: [1]   Go Up
Jump to: