Go Down

Topic: RF modules (Read 2399 times) previous topic - next topic


Hello everybody, I'm trying to send soem data via the tx and rx pins of the arduino. I used a rf 433.92 tx module connected to the arduino tx and a rf 433.92 rx module connected to the arduino rx. I tried to write and print with the tx, and in the rx tried to read, but I get nothing...

I already used the virtualWire library and worked well, that means I didn't do nothing wrong with the connections. Maybe the problem is the code.

Here's the tx code:

void setup () {
pinMode(3, OUTPUT);
void loop () {
Serial.write("ok"); // Already tried print and got nothing


And here's the rx code:

String text = String("  ");
     void setup(){
     void loop(){
       int pos = 0;
         char c = char(Serial.read());
         text = String("  ");



Serial data transmission is relatively slow, especially at 4800 baud.

The loop function is called in an endless loop, hundreds of thousands of times per second. The serial data dribbles in, byte by byte.

On every pass through loop, you start over reading data from the serial port.
On one pass, you'll find that there is a character to read, 'o'. You read that, but the 'k' hasn't arrived yet.

So, text does not equal "ok", so the LED does not get lit.

On the next few hundred passes, you set pos back to 0, but there is nothing to read.

Finally, the 'k' arrives. So, it's put in position 0. The string text does not contain "ok", so the LED does not get lit.

You need to include start-of-packet and end-of-packet markers in the sent data (<ok>), and, in the receiver, initialize (not create a new) the String object when the start-of-packet marker ('<') arrives, add characters to it (using concat or +=, not setCharAt) until the end-of-packet marker ('>') arrives.

Only when the end-of-packet marker arrives should you care about the contents of the packet.
The art of getting good answers lies in asking good questions.


Well, so I have to verify if the received char is < and then make a for to finish the text? Gonna try it


Yes, more than likely it is your code :-)
You said virtualwire worked, and now you have a totally simplified sketch that ignores all the things that virtualwire does, running at a speed that is likely at least 2 times too fast.

Serial.begin, serial.write, serial.read, etc use pins 0 & 1.
You appear to be doing somethin with pin 3 on the TX side, I don't know what.

virtualwire would have used 11 & 12 by default. Had you changed them to use 0 & 1?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.


The virtualWire worked, but I don't wanna use this lib, I want to make my own serial communication, and connected the transmitter on the tx of the arduino that sends the signal and the receiver on the rx pin of the arduino that receives the signal.
Even if I'm receiving something but not the entire text, the arduino should tell me, because I tried a code like this:
if (Serial.available) { Serial.print(Serial.read())} Anything that are received by the arduino should appears on the serial monitor
This should output any value, in case, I tried to send the "o" char, but nothing appears on the serial monitor.


The virtualwire library is written at least in part to overcome the severe limitations of these primitive devices, overwise why bother if plain old serial worked ?


Ok, so, how to send numbers via virtualWire? I tried but always tell me about wrong conversion from const char to int, something like this


I do it like this. I am reading key presses from a keypad and sending them via virtualwire:

send side in loop:
Code: [Select]

  // go read the keypad
 char key = keypad.getKey();                 // reading the keypad
 if(key)                                     // same as if(key != NO_KEY)- did something change?
   msg[0]=key;                               // load the array with the key character
   // msg[1]=NULL;                           // Rx side seems to work without this

   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

receive side in loop
Code: [Select]

uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;

if (vw_get_message(buf, &buflen)) // Non-blocking
 int i;

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

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

 switch ( buf[0] )
 {    // switch on the first byte in the array for now
// bunch of case:'0', case:'1' statements follow ...

I think you just need to load up the msg[] array the numbers you want.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up