Go Down

Topic: wireless communication  (Read 158 times) previous topic - next topic

QAlhawari

Hello Dears...
I tried to use 2 HC-11 modules to achieve a wireless transmission between two channels, but the results were not as I expect, sometimes its work fine but most the time there is no data transferred in between them, that is happening in a random way, can you advice me with a solution for this problem I suffer from.

Robin2

can you advice me with a solution for this problem I suffer from.
As you have not posted the programs that you are having a problem with ...

...R

PS ... Please post your program using the code button </>
Code: [Select]
so it looks like this. See How to use the Forum.  It makes it much easier for people to help you
Two or three hours spent thinking and reading documentation solves most programming problems.

QAlhawari

I used the same simple code for the two parts.

Robin2

This is not going to work very well
Code: [Select]
Serial.write(HC12.read());      // Send the data to Serial monitor
    if(HC12.read()=='a')

because if the first line reads the 'a' it won't be available for the second line.

Try changing those two lines to this
Code: [Select]
   char newData = HC12.read();
   Serial.write(newData);
   if (newData == 'a')


Better still, have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

QAlhawari

Sorry, please ignore the if sentence or take a look for the updated code again, it's as simple as the recommended code.

Robin2

And what happens when you try the shorter program?

By the way I would replace both WHILEs with IFs and allow loop() to do the repetition.

Code: [Select]
#include <SoftwareSerial.h>
SoftwareSerial HC12(10, 11); // HC-12 TX Pin, HC-12 RX Pin
void setup() {
  Serial.begin(9600);             // Serial port to computer
  HC12.begin(9600); // Serial port to HC12
}
void loop() {
  if (HC12.available()) {        // If HC-12 has data
    Serial.write(HC12.read());      // Send the data to Serial monitor
  }
  if (Serial.available()) {      // If Serial monitor has data
    HC12.write(Serial.read());      // Send that data to HC-12
  }
}


...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up