hy guys
I am working on an university project, and I'm looking for some guidance on a problem I am encountering. Basically, I am trying to read data via a receiver radio connected to an Arduino Mega. The data is being transmitted via a transmitter radio connected to my laptop.
The telemetry are synced (solid green light and same baud rate of 9600) and I know there is some communication. I used lcd to see what receiver get.
The setup is as follows: The transmitter radio is connected to my laptop via USB cable. There, I can use any serial port emulator to write data for transmitting. This works without any issue. On the other side, I have the receiver radio connected to my Arduino board. Radio RX and TX goes to Arduino RX and TX, respectively. However, as I transmit data via the transmitter, the receiver does not respond. Thus, the output from the Arduino is always -1.
This is what is confusing me: I've programmed both radios to be communicating at the same channel. I know they are talking to each other because both have solid green LEDs, which mean they are hooked up. If I connect both to my laptop, or both to different laptops via USB cable, I can transmit and receive data no problem. Red and orange LEDs flash when transmitting and receiving. The problem occurs when I connect the receiver radio to my Arduino board and try to read its values through the RX and TX pins. I get nothing. Although the green LED remains solid, the red and orange LEDs don't flash on the receiver. This means that the receiver isn't receiving.
Also confusing me is: I can successfully write values to the transmitter via Arduino. I've connected the transmitter RX and TX to Arduino TX and RX, respectively, and have the Arduino write different numbers for it to transmit. I can also read the values from the receiver, plugged into my laptop via USB cable.
I'm taking a guess here, but the problem seems to be with the RX pin and the micro USB on the radio. For some reason i cannot read received values via the RX pin. And the receiver radio doesn't seem to respond if I don't plug it into my laptop via USB. I've swapped the RX and TX pins around, swapped the radios around, and changed Arduino boards, all to no avail.
I'm wondering, with the same connections, how come I can so easily use an Arduino to write values to the radio to transmit, but cannot use an Arduino to read these values?
Here is the code I'm using or the receiver radio:
#include <SoftwareSerial.h>
SoftwareSerial ss(1, 0);
String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete
String commandString = "";
boolean isConnected = false;
void setup() {
Serial.begin(9600);
Serial.print("Selamat Mencoba");
}
void loop() {
if(stringComplete)
{
stringComplete = false;
getCommand();
if(commandString.equals("STAR"))
{
Serial.println("Lanjut");
}
if (commandString.equals("STOP"))
{
Serial.println("Ready to connect");
}
else(commandString.equals("TEXT"));
{
String text = getTextToPrint();
printText(text);
}
inputString = "";
}
}
void getCommand()
{
if(inputString.length()>0)
{
commandString = inputString.substring(1,5);
}
}
String getTextToPrint()
{
String value = inputString.substring(5,inputString.length()-2);
return value;
}
void printText(String text)
{
if(text.length()<16)
{
Serial.print(text);
}else
{
Serial.print("kepanjangan");
}
}
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}
i use module telemetry for transfer data, that make i use serial1 , not serial