arduino to visual studio wireless communication telemtry

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

The Arduino Mega has multiple hardware UARTs. Try using them instead of Software Serial.

The pins are called TX1/RX1, TX2/RX2, ...

And you just use Serial1, Serial2, ...

Curious, can you provide a link to the radio transceivers? Also, like Klaus_K mentioned, you should always try to use Arduinos with multiple hardware UART ports over using SoftwareSerial.h.

In terms of the software portion, you can use SerialTransfer.h to automatically packetize and parse your data for inter-Arduino communication without the headace. The library is installable through the Arduino IDE and includes many examples.

Here are the library’s features:

This library:

  • can be downloaded via the Arduino IDE’s Libraries Manager (search “SerialTransfer.h”)
  • works with “software-serial” libraries
  • is non blocking
  • uses packet delimiters
  • uses consistent overhead byte stuffing
  • uses CRC-8 (Polynomial 0x9B with lookup table)
  • allows the use of dynamically sized packets (packets can have payload lengths anywhere from 1 to 254 bytes)
  • can transfer bytes, ints, floats, and even structs!!

Example TX Arduino Sketch:

#include "SerialTransfer.h"

SerialTransfer myTransfer;

void setup()
{
  Serial.begin(115200);
  Serial1.begin(115200);
  myTransfer.begin(Serial1);
}

void loop()
{
  char buff[] = "hi";

  myTransfer.txObj(buff, sizeof(buff));
  myTransfer.sendData(sizeof(buff));
  delay(100);
}

Example RX Arduino Sketch:

#include "SerialTransfer.h"

SerialTransfer myTransfer;

void setup()
{
  Serial.begin(115200);
  Serial1.begin(115200);
  myTransfer.begin(Serial1);
}

void loop()
{
  if(myTransfer.available())
  {
    char buff[40];
    
    myTransfer.rxObj(buff, sizeof(buff));
    
    Serial.println("New Data: ");
    Serial.write(buff, sizeof(buff));
    Serial.println();
  }
  else if(myTransfer.status < 0)
  {
    Serial.print("ERROR: ");

    if(myTransfer.status == -1)
      Serial.println(F("CRC_ERROR"));
    else if(myTransfer.status == -2)
      Serial.println(F("PAYLOAD_ERROR"));
    else if(myTransfer.status == -3)
      Serial.println(F("STOP_BYTE_ERROR"));
  }
}

For theory behind robust serial communication, check out the tutorials Serial Input Basics and Serial Input Advanced.

In your setup (connected to the arduino for receiving) is the resting voltage on the receiver tx and rx pins the normally expected TTL 5v?

Klaus_K:
The Arduino Mega has multiple hardware UARTs. Try using them instead of Software Serial.

The pins are called TX1/RX1, TX2/RX2, …

And you just use Serial1, Serial2, …

thanks for the answer but i have try to use serial 1, it not work, what i have to do ?

farhanashegaf:
thanks for the answer but i have try to use serial 1, it not work, what i have to do ?

What do you mean? Are you now testing on a Mega? What's wrong with your project at this point ("it will not work" isn't very descriptive)?

Power_Broker:
What do you mean? Are you now testing on a Mega? What’s wrong with your project at this point (“it will not work” isn’t very descriptive)?

I mean, I tried as you suggest, but it didn’t work, what was wrong about the coding?

#include <LiquidCrystal.h>




String inputString = "";         // a string to hold incoming data
boolean stringComplete = false;  // whether the string is complete
String commandString = "";

int led1Pin = 19;
int led2Pin = 20;
int led3Pin = 21;

boolean isConnected = false;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 


void setup() {
  
  Serial.begin(9600);
  Serial1.begin(57600);
  pinMode(led1Pin,OUTPUT);
  pinMode(led2Pin,OUTPUT);
  pinMode(led3Pin,OUTPUT);
  initDisplay();
}

void loop() {



if(stringComplete)
{
  stringComplete = false;
  getCommand();
  
  if(commandString.equals("STAR"))
  {
    lcd.clear();
  }
  if(commandString.equals("STOP"))
  {
    turnLedOff(led1Pin);
    turnLedOff(led2Pin);
    turnLedOff(led3Pin);
    lcd.clear();
    lcd.print("Ready to connect");    
  }
  else if(commandString.equals("TEXT"))
  {
    String text = getTextToPrint();
    printText(text);
  }
  else if(commandString.equals("LED1"))
  {
    boolean LedState = getLedState();
    if(LedState == true)
    {
      turnLedOn(led1Pin);
    }else
    {
      turnLedOff(led1Pin);
    }   
  }
    else if(commandString.equals("LED2"))
  {
    boolean LedState = getLedState();
    if(LedState == true)
    {
      turnLedOn(led2Pin);
    }else
    {
      turnLedOff(led2Pin);
    }   
  }
    else if(commandString.equals("LED3"))
  {
    boolean LedState = getLedState();
    if(LedState == true)
    {
      turnLedOn(led3Pin);
    }else
    {
      turnLedOff(led3Pin);
    }   
  }
  
  inputString = "";
}

}

void initDisplay()
{
  lcd.begin(16, 2);
  lcd.print("Ready to connect");
}

boolean getLedState()
{
  boolean state = false;
  if(inputString.substring(5,7).equals("ON"))
  {
    state = true;
  }else
  {
    state = false;
  }
  return state;
}

void getCommand()
{
  if(inputString.length()>0)
  {
     commandString = inputString.substring(1,5);
  }
}

void turnLedOn(int pin)
{
  digitalWrite(pin,HIGH);
}

void turnLedOff(int pin)
{
  digitalWrite(pin,LOW);
}


String getTextToPrint()
{
  String value = inputString.substring(5,inputString.length()-2);
  return value;
}

void printText(String text)
{
  lcd.clear();
  lcd.setCursor(0,0);
    if(text.length()<16)
    {
      lcd.print(text);
    }else
    {
      lcd.print(text.substring(0,16));
      lcd.setCursor(0,1);
      lcd.print(text.substring(16,32));
      
    }
}

void serialEvent() {
  while (Serial1.available()) {
    // get the new byte:
    char inChar = (char)Serial1.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;
    }
  }
}

farhanashegaf:
I mean, I tried as you suggest, but it didn't work, what was wrong about the coding?

Apparently not. I suggested you use SerialTransfer.h but the code in reply #6 doesn't use the library.

Kind of hard to visualize your receiving hardware, but if you have your wireless receiver attached to your arduino at the primary rx/tx pins, and the arduino connected to a computer, then you might load the below echo code on the arduino. Then open the serial monitor and see if any received serial communication (from the wireless rx receiver) is displayed in the serial monitor.

//zoomkat 6-29-14 Simple serial echo test
//type or paste text in serial monitor and send

String readString;

void setup() {
  Serial.begin(9600);
  Serial.println("Simple serial echo test"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the String readString
    delay(3);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() > 0) {
    Serial.println(readString);  //so you can see the captured String
    readString = "";
  }
}

zoomkat:
Kind of hard to visualize your receiving hardware, but if you have your wireless receiver attached to your arduino at the primary rx/tx pins, and the arduino connected to a computer, then you might load the below echo code on the arduino. Then open the serial monitor and see if any received serial communication (from the wireless rx receiver) is displayed in the serial monitor.

//zoomkat 6-29-14 Simple serial echo test

//type or paste text in serial monitor and send

String readString;

void setup() {
 Serial.begin(9600);
 Serial.println("Simple serial echo test"); // so I can keep track of what is loaded
}

void loop() {

while (Serial.available()) {
   char c = Serial.read();  //gets one byte from serial buffer
   readString += c; //makes the String readString
   delay(3);  //slow looping to allow buffer to fill with next character
 }

if (readString.length() > 0) {
   Serial.println(readString);  //so you can see the captured String
   readString = "";
 }
}

I've tried it and it worked, but there was a problem when using serial1 with tx1 and rx1, it didn't work

Power_Broker:
Apparently not. I suggested you use SerialTransfer.h but the code in reply #6 doesn't use the library.

I was a little confused when using it in my code,
I'm a beginner in the program

"I've tried it and it worked, but there was a problem when using serial1 with tx1 and rx1, it didn't work"

Well, that shows the wireless tx and rx modules are functioning. I don't think the tx1 and rx1 pins are physically connected to the board serial module, so I would not expect it to work under those conditions.

farhanashegaf:
I was a little confused when using it in my code,
I'm a beginner in the program

There are many examples that come with the library that show how to use it. What questions do you have?