Society of Robots - Robot Forum

Software => Software => Topic started by: Mr. Ninja on August 14, 2012, 05:15:28 PM

Title: RF code on Arduino won't work (properly) anyone know why?
Post by: Mr. Ninja on August 14, 2012, 05:15:28 PM
SO,      I've started a small project that uses RF (@434 Mhz) to transmit a small amount of data (1 byte), and it doesn't seem to be sending the correct data.

Code: [Select]
byte toSend; // this is what will be sent: sample code = simple name
byte sent; // the sent by
void setup(){
//2400 baud for the 434 model
Serial.begin(2400);
toSend = 00000011;// initializing the variables...
sent = 00000000;
}
void loop(){
Serial.println (toSend);// sending the first byte
sent = Serial.read(); //reads the incoming byte
Serial.println (sent); //displays incoming byte
delay(5000);
}


After the program uploads, I reconnect Rx and Tx, and open the COM viewer.

it just prints out (repeatedly):

9
255

That's all it prints out, shouldn't it print:

3
3
?

Could someone help me with this?
Title: Re: RF code on Arduino won't work (properly) anyone know why?
Post by: Gertlex on August 14, 2012, 05:44:37 PM
It's not clear, at least to me, what your hardware setup is.

The 255 from the receive byte (presumably) means the buffer is empty, I think.
Title: Re: RF code on Arduino won't work (properly) anyone know why?
Post by: Mr. Ninja on August 14, 2012, 06:18:36 PM
It's just an Arduino Uno ( Atmega 328P-PU, UNO bootloader), an RF reciever (http://content.solarbotics.com/products/datasheets/receiver_module_data_sheet.pdf (http://content.solarbotics.com/products/datasheets/receiver_module_data_sheet.pdf)), and an RF transmitter (http://content.solarbotics.com/products/datasheets/rf_transmitter_module_data_sheet.pdf (http://content.solarbotics.com/products/datasheets/rf_transmitter_module_data_sheet.pdf)).

I also tried to add an if statement, to encapsulate the byte, and make sure it's the same size. The COM reads:
6
255
(repeat forever)

Then I changed the toSend and sent bytes to regular numbers (6 and 0, respectively). I also changed the if statement to check if sent is 6 (mimics what the project will eventually do anyways). It also delays a second (or should) and resets sent.

Code: [Select]
byte toSend; // this is what will be sent: sample code = simple name
byte sent; // the sent byte
void setup(){
//2400 baud for the 434 model
Serial.begin(2400);
toSend = 6;// initializing the variables...
sent = 0;
}// end setup
void loop(){
Serial.println (toSend);// sending the first byte
sent = Serial.read(); //reads the incoming byte
if (sent == 6) // checks if sent is the desired result
{
Serial.println (sent); //displays incoming byte
delay(1000);// delays a second
sent = 0; // resets sent
} //end if
}// end loop
 

it prints (COM):
6
6
6

(random stuff that generally includes a six, it changes randomly)

 then it just repeats 6 forever, no delay.