Go Down

Topic: RF Link Kit problem / Virtual Wire (Read 2 times) previous topic - next topic

Borb

This is the RF Link Kit in question:
http://www.seeedstudio.com/depot/2km-long-range-rf-link-kits-w-encoder-and-decoder-p-321.html
(2KM Long Range RF link kits w/ encoder and decoder)

------------------

I am building a wireless link to be able to remotely monitor a greenhouse temperature. The temperature will be represented by an analogue voltage derived from a thermistor, say in range 0-3V.

I am using an Arduino Mega to convert the analogue input to a digital output and plan to feed this into a wireless board. I then have a matching wireless receiver which feeds a Arduino Duemilanove which is connected to the PC via USB.

The wireless transmitter and receiver work OK over the required distance - I can transmit a binary signal to flash an LED on the receiver, using the following code

Code: [Select]

// RECEIVER - DUEMILANOVE
void setup()
{
  pinMode(A1, INPUT);  // Receiver (using analog as digital for convenience)
  pinMode(13, OUTPUT);
}

void loop()
{
  int sig = digitalRead(A1);
 
  if (sig) {
    digitalWrite(13, HIGH);
  }
    else{
    digitalWrite(13, LOW);
  }
}

// TRANSMITTER - MEGA

void setup()
{
  Serial.begin(9600);
 
  pinMode(13, OUTPUT);
  pinMode(50, OUTPUT); // transmitter, digital pin
}

void loop()
{
    digitalWrite(50, HIGH);
    digitalWrite(13,HIGH);
    delay(200);
    digitalWrite(50, LOW);
    digitalWrite(13,LOW);
    delay(200);
}


However I can't figure out how to get it to send a data message representing the analogue signal from the thermistor. My plan was to use virtual wire, but I haven't got the following code to work...

Code: [Select]

// RECEIVER

#include <VirtualWire.h>

void setup()
{
  pinMode(13, OUTPUT);
  vw_set_ptt_inverted(true);
  Serial.begin(9600);
  vw_set_rx_pin(A1);
  vw_setup(500);
  vw_rx_start();
}

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

  if (vw_get_message(buf, &buflen))
  {
    Serial.print("Got: ");
    Serial.print(buf[0]);
    digitalWrite(13, HIGH);
    delay(100);
  }
}

// TRANSMITTER

#include <VirtualWire.h>
void setup()
{
  pinMode(13, OUTPUT);
  vw_set_ptt_inverted(true);
  vw_set_tx_pin(50);
  vw_setup(500);
}

void loop()
{
    char message = 'test';
    vw_send((uint8_t *)&message, strlen(&message));
    vw_wait_tx();
    digitalWrite(13,HIGH);
    delay(400);
    digitalWrite(13,LOW);
    delay(400);
}


I have read something about soldering the pads on the tx and rx boards but I don't see how this would help transmit a message that will vary according to the analogue input to the Arduino....and then pass this on to the PC to decode and translate into a temperature reading.

Can anyone help ? Thanks in advance

CrossRoads

The pads on the back are just for setting the 'address' of the Tx & Rx units. If you only have this one set, you can leave them as is.

Take out this line, your part does not need it.
vw_set_ptt_inverted(true);

For your transmitter, you can load up an array and send it like this:

Code: [Select]

     msg[0]=key;                               // load the array with the key character  --> fill this as needed

    digitalWrite(ledPin, true);               // Flash a light to show transmitting

    vw_send((uint8_t *)msg, strlen(msg));     // send the character out

//    Serial.println(key);                // for debugging only

    vw_wait_tx();                             // Wait until the whole message is gone

    delay (50);                               // need some delay or seem to miss key presses

    digitalWrite(ledPin, false);              // turn off the flash of LED


The receive side will get the data as a string of character
Code: [Select]

// **********************************************************************************************
// look for wireless input

uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;

if (vw_get_message(buf, &buflen)) // Non-blocking
{
  int i;
  digitalWrite(ledPin, LOW); // Turn on LED to show working a message

  // Message with a good checksum received, dump it.
  //Serial.println("Got: ");  // Show on PC for debugging

  //    for (i = 0; i < buflen; i++)
  //    {
  //Serial.print(byte(buf[i]));
  //    }
  //Serial.println(""); // spaces it out for the monitor


So I think you're pretty close.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Borb

Hi, Thanks for your reply.

I have tried that code but to no avail. Below is the precise code I used.
Does anyone else have any other ideas, perhaps alternative to virtualwire or pointers on how I could implement my own software to achieve my goal?

Thanks

Code: [Select]

// TRANSMITTER
#include <VirtualWire.h>

const int ledPin = 13;
const int txPin = 50;

void setup()
{
  pinMode(ledPin, OUTPUT);
  vw_set_tx_pin(txPin);
  vw_setup(100);
}

void loop()
{   
    char msg[0];
    msg[0]='a';   
    digitalWrite(ledPin, true);               // Flash a light to show transmitting
    vw_send((uint8_t *)msg, strlen(msg));     // send the character out
    Serial.println(msg[0]);                // for debugging only
    vw_wait_tx();                             // Wait until the whole message is gone
    delay (500);                               // need some delay or seem to miss key presses
    digitalWrite(ledPin, false);              // turn off the flash of LED
    delay(500);
   
}


Code: [Select]

// RECEIVER
#include <VirtualWire.h>

const int ledPin = 13;

void setup(){
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
  vw_set_rx_pin(A1);
  vw_setup(500);
  vw_rx_start();
}

void loop(){

uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;

if (vw_get_message(buf, &buflen)) // Non-blocking
{
  int i;
  digitalWrite(ledPin, LOW); // Turn on LED to show working a message

  // Message with a good checksum received, dump it.
  Serial.println("Got: ");  // Show on PC for debugging

  for (i = 0; i < buflen; i++){
    Serial.print(byte(buf[i]));
  }
  Serial.println(""); // spaces it out for the monitor
}

}



CrossRoads

Post your wiring.

This needs to go before setup()

    char msg[0];  << and how can you have an array of size 0? Make this bigger, at least 1. Then msg[0] = 'a' should give vald result

why do you transmit at 100
vw_setup(100);

and receive at 500?
  vw_setup(500);

That's not gonna work.

May not make a difference, but use a digital pin here, even if same pin but called by digital name.
  vw_set_rx_pin(A1);
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Borb

#4
Mar 12, 2011, 10:31 pm Last Edit: Mar 12, 2011, 10:34 pm by Borb Reason: 1
Thanks, I'm now using
Code: [Select]
const char msg[] = "a"; and have equalized the tx/rx speeds (tried 1,100,500,2000). Wasn't sure what you meant by "even if same pin but called by digital name".

Here is my wiring. Note that I am not using the variable resistor analog signal in my test code, but will be eventually.
Also note that it looks like I am TXing on a pin that should be RXed at A0. In my testing where I was just sending a high/low pulse (which worked), it was in fact RXed at the A1 pin (not sure why). I've tried both A0 and A1 in the code to no avail



Go Up