Can I use UART0?

Hello, everyone!
The board I'm using is mega2560 pro.
The distance data of the UWB sensor is received using the tx0 rx0 pin (0, 1) pin in mega2560.
The distance data of the UWB sensor received here is transmitted to another board through Bluetooth, and the data is not outputted when I try to check the data in real time through the serial monitor.

The reason for transmitting data through Bluetooth is that I heard that communication with the computer including debugging is not possible when using UART0.
So I'd really appreciate it if you could let me know if I can't use UART0 or if I'm not using it properly!

As far as I see, you are using three UART connections - one for the UWB sensor, another for the BT, and a third for the Serial monitor. For all this to work successfully, you need three uart ports.
You only mention RX0 TX0. Where are the others connected?

First of all, thank you for your response.

The UART currently in use is
UART0 : UWB sensor1
UART1: UART for STM communication
UART2 : UWB sensor2
UART3 : UWB sensor3
SoftwareSerial (52pin, 53pin): BTModule

I'm using it as above.

The sensors of UART2 and UART3 are receiving data in real time via Bluetooth, but only UART0's data is not. If you know anything about this, please reply. Thank you.

The UART0 is connected to USB interface. So, you can use it either for your sensor, or for Serial Monitor, but not to both.
If you have a Serial.begin() line somewhere in the code, you probably will have troubles to read the sensor on Rx0 TX0

Serial0 is currently only being used to get data from the sensor.
I sent the data from Serial0 to another arduino board via Bluetooth.
I am checking the data of the sensor through the Serial monitor on the board.
Is there a problem with Serial.begin() Rx0 Tx0 in this process as well?

Are you understand, that your first phrase is contradict with the second? The Serial Monitor is on the UART0 too, using of Serial monitor it means that you use UART0 for two things at the time - for Monitor and for the sensor.
It can't works such way.

Why don't you to monitor the first sensor via Bluetooth, the same way as sensor on UART2 and UART3 ?

Thank you for your kind response.
I'm sorry that there was an error while translating.

Serial0, Serial2, Serial3 : Send UWB sensor data via Bluetooth.

=> Receive the transmitted data from another Arduino board and check the sensor data using Serial monitor.

In the above process, only the data in Serial0 is missing.

Could you show a code for both boards - transmitter and receiver?

transmitter code

#include <SoftwareSerial.h>

SoftwareSerial BTmodule(52, 53);

void setup() {
  //Serial set
  BTmodule.begin(57600);
  Serial.begin(115200);
  Serial1.begin(115200);  // STM
  Serial2.begin(115200);  // R_rf
  Serial3.begin(115200);  // L_rf

  Request_sensor_distance_data();
}

void loop() {
  Rf_Sensor(&B_distance, &L_distance, &R_distance);

  BTmodule.print("L_d ");
  BTmodule.print(L_distance);
  BTmodule.print(",R_d ");
  BTmodule.print(R_distance);
  BTmodule.print(",B_d ");
  BTmodule.print(B_distance);

}

void Request_sensor_distance_data(){
  Serial.print("reset\r");
  Serial2.print("reset\r");
  Serial3.print("reset\r");
  delay(500);

  Serial.write(0x0d);
  Serial2.write(0x0d);
  Serial3.write(0x0d);
  Serial.write(0x0d);
  Serial2.write(0x0d);
  Serial3.write(0x0d);

  delay(500);

  Serial.flush();
  Serial2.flush();
  Serial3.flush();

  delay(500);

  Serial.print("lec");
  Serial.write(0x0d);
  Serial2.print("lec");
  Serial2.write(0x0d);
  Serial3.print("lec");
  Serial3.write(0x0d);
}

void Rf_Sensor(float* B_distance, float* L_distance, float* R_distance)
{
  B_String = Serial.readStringUntil('\n');
  R_String = Serial2.readStringUntil('\n');
  L_String = Serial3.readStringUntil('\n');

  if(B_String.indexOf("DIST") >= 0)
    {
      *B_distance = B_String.substring(B_String.lastIndexOf(',') + 1).toFloat();
      if (firstB = true)
      {
        median_Blist[median_R_count] = *B_distance;
        median_B_count+=1;
        if (median_B_count>N-1)
        {
          firstB = false;
          median_B_count = 0;
        }
      }
      else
      {
        memmove(median_Blist+1,median_Blist,sizeof(float)*(N-1));
        median_Blist[0] = *B_distance;
      }
      Range[2] = *B_distance;
      Kalman_Range[2] = Kalman(Kalman_Range, Range[2], Predict, 2)[2];


      *B_distance = Kalman_Range[2];
    }

  if(R_String.indexOf("DIST") >= 0)
    {
      *R_distance = R_String.substring(R_String.lastIndexOf(',') + 1).toFloat();
      if (firstR = true)
      {
        median_Rlist[median_R_count] = *R_distance;
        median_R_count+=1;
        if (median_R_count>N-1)
        {
          firstR = false;
          median_R_count = 0;
        }
      }
      else
      {
        memmove(median_Rlist+1,median_Rlist,sizeof(float)*(N-1));
        median_Rlist[0] = *R_distance;
      }
      Range[0] = *R_distance;
      Kalman_Range[0] = Kalman(Kalman_Range, Range[0], Predict, 0)[0];

      if (raw_data_use_Rcount >= 0 && raw_data_use_Rcount < 6){
        Range[0] = *R_distance;
        raw_data_use_Rcount++;
      }
      else{
        *R_distance = Kalman_Range[0];
      }
    }

  if(L_String.indexOf("DIST") >= 0)
    {
      *L_distance = L_String.substring(L_String.lastIndexOf(',') + 1).toFloat();
      if (firstL = true)
      {
        median_Llist[median_L_count] = *L_distance;
        median_L_count+=1;
        if (median_L_count>N-1) 
        {
          firstL = false;
          median_L_count = 0;
        }
      }
      else
      {
        memmove(median_Llist+1, median_Llist,sizeof(float)*(N-1));
        median_Llist[0] = *L_distance;
      }
      Range[1] = *L_distance;
      Kalman_Range[1] = Kalman(Kalman_Range, Range[1], Predict, 1)[1];

      if (raw_data_use_Lcount >= 0 && raw_data_use_Lcount < 6){
        Range[1] = *L_distance;
        raw_data_use_Lcount++;
      }
      else{
        *L_distance = Kalman_Range[1];
      }
    }
}
Receiver Code

#include <SoftwareSerial.h>

SoftwareSerial mySerial(9, 10); // RX, TX
void setup()
{

  Serial.begin(115200);
  mySerial.begin(57600);

}

void loop()
{ // run over and over
  if (mySerial.available()) 
  {
    Serial.write(mySerial.read());
  }
  if (Serial.available())
  {
    mySerial.write(Serial.read());
  }
  delay(500);
}


What is the "STM" ? Could you (for testing purposes) swap the "STM" and first sensor such way so the sensor will connected to UART1 ?
Perhaps the commands that you send to sensor, somehow interfere with USB UART bridge chip.

The STM is an STM32 board.

Current Board Status:

  1. main arduino board (transmission board, using 3 sensors)

  2. Sub Arduino board (receiving board, for sensor data verification)

  3. STM32 board (in communication with main board by Uart1)

Currently, Serial1 is fixed to 3.3v on the PCB board, so it cannot be used for testing. (Sensor is 5v)
At first, I tried connecting the first sensor to Serial2 and Serial3 to see if there was an error in the sensor, but there was no problem with the sensor.
Only the data corresponding to Serial0 is not output.

Did you tried to swap RX0 and TX0 pins? There are Mega boards with incorrect labels on pins.

I haven't tried this before.
However, the rx, tx pins of the first sensor have been separated and cannot be tested at this time.
And the Arduino board is fixed, and the rx and tx parts of the sensor are fixed with connectors, making it difficult to try :frowning:
I'll try it once I buy additional connectors and repair the sensors.

If you have any other opinions, please let me know.
Thank you for the advice!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.