Pages: [1]   Go Down
Author Topic: vw_get_message ----- Rx issue  (Read 1448 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi There,

Programming newbie here......

I have a arduino uno setup. Im trying to send a signal between transmitter and receiver.
I have tx on pin 13 and rx on pin 11.
vw have message is true
but vw_get_message(buf, &buflen) is false
the receiver does not seem to be working is there anyway that I can confirm that the receiver works

any help is much appreciated

Code


Code:
#include <VirtualWire.h>  //TxRx
#include <iostream>
#include <math.h>
#include <TimerOne.h>
#include <ctime.h>


using namespace std;  //using standard library
 


  //int led_pin_sent = 8; //led test for message sent confirmation
  //int led_pin_receive = 7; //led test for message received confirmation
  int motor1Pin = 9; //motor 1
  int motor2Pin = 10; //motor 2
  int potPin = A0; //potentiometer pin 23 ADC
  int receive_1_pin = 11;  //receiver 1
 


  int transmit_pin = 13;  //dummy transmitter to act as ball


  byte count =0; //byte stores a 8 bit numerical value without decimals points. 0-255




    TimerOne t;   //declare t as timer1 function for timing receiver to work out distance
    
/************************************************************************************************/


void setup()
{                
 /***********************************************************************************************/          
                  //this section will be remove
                  //transmiter start with bit speed, in future the ball should start when receiver is in range
  vw_setup(1000); //Bits per sec
  
  vw_set_tx_pin(transmit_pin);  //set pin 13 for transmiter
  
 /**********************************************************************************************/
 
  //vw_set_rx_pin(receive_1_pin);  //set pin 11 for receiver 1
  
  vw_set_ptt_inverted(true); // ?????????
  
 
  t.initialize(1000);   //1 second period
  
 


 
 //declare IO ports  
  
    pinMode(13,OUTPUT);  //T
    pinMode(11,INPUT);  //R1
    
    
    Serial.begin(9600); // sets serial rate for pc monitoring purposes
    Serial.println("receivers active and waiting"); //print line in monitoring
    delay(100);  //delay to allow print to finish


}


void loop()
{
//receiver settings
  
  
  
   vw_rx_start();       // Start the receiver PLL running
   delay(100);    //ms  
  
//temp transister section


  //digitalWrite(led_pin_sent, HIGH);    //led on for message sending
 Serial.print("cycle number ");
  Serial.println(count);
  delay(100);  //ms
  Serial.println("message sending");
  delay(100);  //ms
  
  int i;
  i = count;
  
  
  t.restart();   //restart timer value
  
 //testing message send
 
   const char *msg = "hello";
          vw_send((uint8_t *)msg, strlen(msg));
          delay(400);
          
  vw_wait_tx(); // Wait until the whole message is gone
  t.start();    //start timer to determine the
  
  count = count +1;
  
  if  (vw_send((uint8_t *)msg, strlen(msg)))
          
  {
     Serial.println("message sent");
  delay(100);  //ms
  }
  
 if (vw_have_message() == 1); //condition to prove message is received
 {
   unsigned int time[] = {0,0,0};
   byte l = 0;
   time[l] = t.read();   //time is seconds
    Serial.println(msg);
    delay(100);
  
  
  
   /**********************************************************************************************/
 //distance calculation
 
  int tm;  //time taken
  int d; // distance
    tm = time[l];
    
  d = 320 * tm; //distance in [m]
 
   /**********************************************************************************************/
 
  
 
  Serial.println("message recieved");  
    delay(100);  //ms
  Serial.print("Receiver_1  ");  //show receiver 1 received message and time value
    delay(100);  //ms
  Serial.print(d);
      delay(100);  //ms
  Serial.println(" [m] ");
      delay(100);  //ms
       Serial.print("Time recorded was ");
      delay(100);  //ms
   Serial.println(time[l]);    
      delay(1000);
      Serial.println(" ");
  
 }
  
//receiver message

uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;

 if (vw_get_message(buf, &buflen))    //check if any messages have been received
 {
   int m;
   Serial.print("got");
  
   for(m = 0; m < buflen; m ++)
   {
  Serial.println("message recieved");  
    delay(1000);  //ms
  Serial.println('Receiver_1', t.read());  //show receiver 1 received message and time value
    delay(1000);  //ms  
 }
 }

return;
}
« Last Edit: June 21, 2012, 02:28:49 am by leeperrin » Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3368
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Put your code inbetween the code tags, it makes it a lot easier to read.

Have you tried some of the example code that came with VW to confirm that your hardware is working?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

Thank you for the reply.

I will read up on code tags and use it next time.I have looked at a few basic example codes to connect the tx rx and all fail to communicate.

vw_have_message works but get_message stays false which makes me think that the receiver might be faulty.


Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3368
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

Thank you for the reply.

I will read up on code tags and use it next time.I have looked at a few basic example codes to connect the tx rx and all fail to communicate.

vw_have_message works but get_message stays false which makes me think that the receiver might be faulty.




You should edit your above code to use the code tags in your original post.

If the example code doesn't even work, then that typically points to either a bad module, or incorrect wiring.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What I have noticed and realise that I might not have mentioned is that I am using one Arduino uno board. And the sample code available is in two sections. One for Rx and the other for Tx this to connect two Arduino boards wirelessly. What I am doing is defining an output for the Tx and defining a input for the Rx, could this not be the problem? Or is this possible?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset





Could the RX TX I am using be incorrect, here are there specs.

http://www.ebay.co.uk/itm/433Mhz-RF-transmitter-and-receiver-link-kit-for-ARM-MCU-WL-/330748921917?pt=LH_DefaultDomain_2&hash=item4d022c083d#ht_1415wt_933

Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3368
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What I have noticed and realise that I might not have mentioned is that I am using one Arduino uno board. And the sample code available is in two sections. One for Rx and the other for Tx this to connect two Arduino boards wirelessly. What I am doing is defining an output for the Tx and defining a input for the Rx, could this not be the problem? Or is this possible?

Do you have the RX and TX modules hooked up to the same Uno? I doubt that would work.


Link doesn't work.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Link doesn't work.


A part on ebay with this name:

433Mhz RF transmitter and receiver link kit for ARM/MCU WL

Here is another link:
http://www.ebay.co.uk/sch/i.html?_from=R40&_trksid=m570.l2736&_nkw=433Mhz+RF+transmitter+and+receiver+link+kit+for+ARM%2FMCU+WL

Quote

Do you have the RX and TX modules hooked up to the same Uno? I doubt that would work.

And yes the Rx and Tx is on the same board. I assumed that by assigning a output for the Tx and a input for the Rx would work. But it feels as if this may well be the problem. Can two Rx units be used on one board? Can they be named differently, meaning vw_set_rx(pin1). This name defines the pin, but does not define the Rx. Is there something like vw_set_rx_1(pin1)?

Sorry for bombarding problems
« Last Edit: June 21, 2012, 04:11:25 pm by leeperrin » Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3368
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And yes the Rx and Tx is on the same board. I assumed that by assigning a output for the Tx and a input for the Rx would work. But it feels as if this may well be the problem. Can two Rx units be used on one board? Can they be named differently, meaning vw_set_rx(pin1). This name defines the pin, but does not define the Rx. Is there something like vw_set_rx_1(pin1)?

Sorry for bombarding problems

I'm not aware of any provisions in the virtual wire library that allow you to hook up multiple RX pins, although I don't see any reason why that would be necessary.

Why don't you give us a broader idea of what you are trying to do?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


I'm not aware of any provisions in the virtual wire library that allow you to hook up multiple RX pins, although I don't see any reason why that would be necessary.

Why don't you give us a broader idea of what you are trying to do?

Im trying to measure the distance between a Tx unit and two Rx units for a application up to 100m as illustrated

             Tx


  Rx1                Rx2

To do this I would lie to time the message received by each Rx unit and form the time I can calculate the distance. So ideally I would like to use one Arduino board for both Rx units, but can move tx unit to another Arduino if need be.

Hope this helps.

Logged

Pages: [1]   Go Up
Jump to: