Go Down

Topic: Have problem with programming (Read 42 times) previous topic - next topic

nabeel007

Hello every one,

I have some problems at programming and I can not fix it.

Using two  Arduino Uno for communicating between cheap and simple RF 433 MHz transceivers.

I need to sort out how fast it can communicate, by sending 32 Byte data from TX and when the RX revived sent back the data to the TX.




Transmitter@@@@@@@@@@@@@@@@@@@@@@@@@
//TX

#include <VirtualWire.h>

// device_t role = DEVICE0;


// debounce time (in ms)
int debounce_time = 10;

// maximum debounce timeout (in ms)
int debounce_timeout = 100;

// starting state is off
char state = 0;
// pin for Button A on the RGB Shield
int button_a = 13;

void setup()
{
// Initialize the IO and ISR
Serial.begin(57600);
vw_setup(4000); // Bits per sec
vw_set_tx_pin(12);

pinMode(8, OUTPUT);
}

int debounce(int button, int state)
{


int start = millis();
  int debounce_start = start;
 
  while (millis() - start < debounce_timeout)
    if (digitalRead(button) == state)
    {
      if (millis() - debounce_start >= debounce_time)
        return 1;
    }
    else
      debounce_start = millis();

  return 0;
}

int delay_until_button(int button, int state)
{
  while (! debounce(button, state))
    ;
}

unsigned long send_micros;
int num_received;


void loop()
{
  delay_until_button(button_a, HIGH);
 
  // toggle state
  state = ! state;
 
  // send state to Host
  unsigned int len=32; //length of packet
  char payload[len];
  num_received = 0;
  send_micros = micros();
  Serial.print("Starting send at ");
  Serial.print(send_micros);
Serial.println(" microsecs");
for (int i = 0; i<200; ++i) { //number of packet send
    state = !state;
    payload[0] = state;

  vw_send(payload, len);
    delay(50);
  }
  delay_until_button(button_a, LOW);
}

vw_get_message(device_t device, int rssi, char *data, int len)
{
  num_received++;
    Serial.print("packet number= ");
    Serial.print(num_received);
   Serial.print(" time in micros ");
    Serial.println(micros()-send_micros);
     
       // state = !state;
    digitalWrite(8, state);

 
}


Receiver @@@@@@@@@@@@@@@@@@@@@@@@@

// RX
#include <VirtualWire.h>
byte message[VW_MAX_MESSAGE_LEN]; // a buffer to store the incoming messages
byte messageLength = VW_MAX_MESSAGE_LEN; // the size of the message


void setup()
{
Serial.begin(115200);
Serial.println("Device is ready");
pinMode(13,OUTPUT);
// Initialize the IO and ISR
vw_setup(4000); // Bits per sec
vw_rx_start(); // Start the receiver
}
void loop()
{
}

vw_get_message(char *data, int len)
{
  char state = data[0];

  // this test is not needed for a single device
  vw_get_message(buf, &buflen))      // We check if we have received data
    digitalWrite(13, state);

  // no data to piggyback on the acknowledgement sent back to the Device
   vw_send(device, "OK");
}

Thanks

Regards
Nabeel

Robin2

#1
Mar 09, 2015, 08:41 pm Last Edit: Mar 09, 2015, 08:42 pm by Robin2
I have some problems at programming and I can not fix it.

Using two  Arduino Uno for communicating between cheap and simple RF 433 MHz transceivers.

I need to sort out how fast it can communicate, by sending 32 Byte data from TX and when the RX revived sent back the data to the TX.
You have told us what you want to do but you have not told us what the problem is.
Have you a transmitter and receiver on both Arduinos?

...R

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy