Society of Robots - Robot Forum
Software => Software => Topic started 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.
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?
-
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.
-
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.
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.