I have 2 Arduino Mega and 2 3DR v2 Radio. I want to sent a char from one Radio to the other radio wirelessly. I connected the 3DR radio 5V to 5V, GND to GND and Radio Receiver(pin 2) to my first Arduino Mega Pin 1(TX0) and the Radio Transmitter(pin 3) to my first Arduino Mega Pin 2(RX0). I connect both Radio the same way on different Arduino Mega. I connect a Push Button one end to 5V the other to Transmitter Side Arduino pin 22. I connect another Push Button to pin 24;
One of the hardware serial ports (Serial, TX0, RX0) communicates with the PC. Why would you disable that ability by connecting the radios to that port? Use one of the other 3 hardware serial ports to talk to the radio.
All I get was 255 which is null.
255 is NOT NULL. 255 is what you get when you read data that isn't there. Your outer while loop checks that there is data. Your inner one does not.
Serial.being(57600); //same bard rate as my radio
Are you certain that the radios are communicating at that "bard" rate (usually called a baud rate)?
PaulS:
One of the hardware serial ports (Serial, TX0, RX0) communicates with the PC. Why would you disable that ability by connecting the radios to that port? Use one of the other 3 hardware serial ports to talk to the radio.
I did try to use Serial1 which is pin 19 and pin 18. I gave up when I didn't receive the value I intend to receive. And I have to send
void start()
{
Serial.being(57600); //same bard rate as my radio
Serial1.being(57600); //same bard rate as my radio
pinMode(22, INPUT)
pinMode(24, INPUT)
}
void loop()
{
if(digitalRead(22) == HIGH)
{
Serial.print("L");
Serial1.print("L");
}
if(digitalRead(24) == HIGH)
{
Serial.print("R");
Serial1.print("R");
}
{
I keep getting stuck in that while loop and it never came out. I check its value and its forever 255.
255 is NOT NULL. 255 is what you get when you read data that isn't there. Your outer while loop checks that there is data. Your inner one does not.
What should I do?
Serial.being(57600); //same bard rate as my radio[/code]
Are you certain that the radios are communicating at that "bard" rate (usually called a baud rate)?
Yes, by default 3DR radio uses 57600 Bard Rate, anyway I reconfig them to be 57600 for both the radio.
If there is nothing to read, of course this will keep printing 255.
You make some sense, So I connected the Radio's Clear To Send Pin to a Button, and now it works. Thanks =D
But I have another Problem, The Button is connected to A0, I have two buttons, when I press 1 button both A0 and A1 will have a voltage output HIGH around 4V. I try to analogRead A8 and A8 is also 4V. Why?
The Button is connected to A0, I have two buttons, when I press 1 button both A0 and A1 will have a voltage output HIGH around 4V. I try to analogRead A8 and A8 is also 4V. Why?
Possibly because there is something wrong with your wiring. Perhaps there is something wrong with your code.
The obvious question is why you are reading a digital state using an analog function. You aren't really expecting to find that a switch is a little bit pressed, are you?