Arduino connecting to Strato Flights (UART protocol)

Hello Arduino Forum,

we have near to zero experience with the Arduino platform, but want to read out data obtained from the stratoflights project. They have a sensor platform called STRAT04 which is connected to a board provided by the project. They do not give a lot of information about connection or how to exactly get data from the logger.
We only know that with the line "{to:'Log',from:'Mst',reci:'headerValsCsv',dir:'g',rc:''}" we can get data from the head of the logging file and with "{to:'Log',from:'Mst',reci:'dataValsCsv',dir:'g',rc:''}" we can get data from the body of the logger.
They communicated between the board and the Arduino works over the UART protocol.
The baud rate of the of the stratoflight board is 115200, 8N1 and the desired voltage is 3.3 V. During our endeavour, the startoflight board was powered by an Varta 9V battery.

We connected the ground, pin16, pin17 of the Arduino to the ground, Rx1, Tx1 of the stratoflights board, respectively.

This is the code we have come up so far:

String sendMessage;
String receivedMessage, receivedMessage2;
String input;

void setup() {
  Serial.begin(9600);    // Initialize the Serial monitor for debugging
  Serial2.begin(115200);   // Initialize Serial2 for sending data

  Serial.println("Start");
  delay(2000);

}


void loop() {
  // print to monitor on computer, self check if data was received from computer
  while (Serial.available() > 0) {
    char receivedChar = Serial.read();
    if (receivedChar == '\n') {
      Serial.println(receivedMessage);  // Print the received message in the Serial monitor
      receivedMessage = "";  // Reset the received message
    } else {
      receivedMessage += receivedChar;  // Append characters to the received message
    }
  }
  
  const char* headerCommand = "{to:'Log',from:'Mst',reci:'headerValsCsv',dir:'g',rc:''}"; //get logger head
  Serial2.write(headerCommand);

  while (Serial2.available() >0) {
    char receivedChar2 = Serial2.read();
    if (receivedChar2 == 125) {
      receivedMessage2 += receivedChar2;
      Serial.println(receivedMessage2);  // Print the received message in the Serial monitor
      receivedMessage2 = "";  // Reset the received message
    } else {
      receivedMessage2 += receivedChar2;  // Append characters to the received message
    }
  }
}

But instead of giving us the data/head from the logger, we just get the input line as output. Neither to we understand why this is the case, nor how to receive the data from the logger properly. Additionally, sometimes the output is rather cryptic, sometimes it yields the full input.

We do net need a complete solution, but concrete tipps should already be sufficient.
Thanks in advance!

Setup:

Before I try to read your code and figure out what you want please spend the time to read the forum guidelines. Since I cannot see what you have also post links to technical information on the hardware items and your preliminary schematic be sure to show all power, ground and power sources. Useful links - check here for reference posts / tutorials Frizzing diagrams are not considered schematics here. Your pictures are nice but I cannot follow them.

Tx goes to Rx. Also check your grounds they should all be connected.

you mean it's serial that can an Universal Asynchronous Receiver Transmitter.

presumably the protocol is that when you send that "header" command, it starts transmitting it's log

what about this. set both serial interfaces to the same speed


const char* headerCommand =
    "{to:'Log',from:'Mst',reci:'headerValsCsv',dir:'g',rc:''}";

// -----------------------------------------------------------------------------
void setup() {
    Serial.begin  (115200);  // Arduino IDE serial monitor
    Serial2.begin (115200);  // STRATO4

    Serial.println ("Start");
    delay (2000);

    Serial2.println (headerCommand);
}

// -----------------------------------------------------------------------------
void loop()
{
    if (Serial.available() > 0)
        Serial2.write (Serial.read());

    if (Serial2.available() > 0)
        Serial.write (Serial2.read());
}

@gilshultz
Actually we have wired it correctly, I just did a mistake in my initial description. I have edited it accordingly. However, here you will find a drawing of our wiring, I hope this is better now. Note that we switched the UART output from UART1 (bottom of the board, see first posted image) to UART2 since UART1 seems to not work. We found that out with the help of the code snipped provided by @gcjr
wiring
Unfortunately, I can't provide much information about the sensor or the board, since we did not obtain any more information from the manufacturer/project. They are not exactly talkative when it comes to provide instructions or informations...

@gcjr
Thank you so much! Your code was super helpful! While it was not the full solution, it provided enough to find the working code after some tinkering! The problem with your provided code was, that it did not printed the body fully, but only like 10% of it before printing an update.
This is now the working code:

const char* headerCommand =
    "{to:'Log',from:'Mst',reci:'headerValsCsv',dir:'g',rc:''}";

const char* bodyCommand = 
    "{to:'Log',from:'Mst',reci:'dataValsCsv',dir:'g',rc:''}";

// -----------------------------------------------------------------------------
void setup() {
    Serial.begin  (115200);  // Arduino IDE serial monitor
    Serial2.begin (115200);  // STRATO4

    Serial.println ("Start");
    delay (1000);

    // print header one time
    Serial2.println (headerCommand);
    if (Serial.available() > 0){
        Serial2.write (Serial.read());
    }
    if (Serial2.available() > 0){
        Serial.write (Serial2.read());
    }
    delay(1000);  // somehow necessary to print body, without it stops after printing the header
}

// -----------------------------------------------------------------------------
void loop()
{
    // print body every now and then
    Serial2.println (bodyCommand);
    if (Serial.available() > 0){
        Serial2.write (Serial.read());
    }

    while (Serial2.available() > 0){
      char receivedChar = Serial2.read();
      Serial.write (receivedChar);
    }
}

This is the output the code generates:

So thank you again! I feel a bit embarrassed since the working code and your provided solution are so much simpler and straight forward compared to our initial tries....
Though there are some things I don't understand:

  • Why is the 2nd delay necessary? without it, the body does not get printed
  • The log on the board should update itself any 10 seconds. Does anyone have a guess why the output in the IDE is so inconsistent time wise?
  • if I exchange the while with if statement, the code again produces only 10% of the full output. I'm a bit more familiar with python programming and can't explain this behaviour.. Especially since the if in void setup() seems to work perfectly fine.

These questions are not critical for the project, its just my curiosity :wink:

Thank you all for our time and efforts :slight_smile:

Sorry I cannot read it, post it the same as code.

A logic level converter is required when connecting 5V outputs (like Mega TX) to 3.3V inputs (like Stratoflight RX). By connecting them directly, you cannot expect communications to work properly and you may even have damaged the 3.3V controller.

The 3.3V TX to 5V RX connection is not damaging, but may not work properly either. It is best to use a bidirectional logic level shifter like this one.

@gilshultz
Here is the result from the last test run:

12:54:57.574 -> Start
12:54:59.584 -> {to:'Mst',from:'Log',reci:'headerValsCsv',pl:{headerCsv:'Uptime{to:'Mst',from:'Log',reci:'dataValsCsv',pl:{tstamp:33991,valsCsv:'33.990;0.000;2015-10-22T10:55:00.0Z;0;Inval.;Inval.;Inval.;Inval.;Inval.;0;Inval.;28.9;25.9;25.3;963.5;58.87;0.00;7.18;3.29;5.06;0.311;0.303;0.296;1;0.000;1;0.000;0;0.002;0;0.002',},rc:'',fnv32:0x986675f6}
12:55:09.247 -> {to:'Mst',from:'Log',reci:'dataValsCsv',pl:{tstamp:43623,valsCsv:'43.622;0.000;2015-10-22T10:55:10.0Z;0;Inval.;Inval.;Inval.;Inval.;Inval.;0;Inval.;28.9;25.8;25.3;963.5;58.84;0.00;7.24;3.29;5.07;0.312;0.306;0.297;1;0.000;1;0.000;0;0.002;0;0.002',},rc:'',fnv32:0xc69bfbd8}
12:55:13.263 -> {to:'Mst',from:'Log',reci:'dataValsCsv',pl:{tstamp:47623,valsCsv:'47.622;0.000;2015-10-22T10:55:14.0Z;0;Inval.;Inval.;Inval.;Inval.;Inval.;0;Inval.;28.9;25.9;25.3;963.5;58.84;0.00;7.26;3.29;5.06;0.315;0.308;0.298;1;0.000;1;0.000;0;0.002;0;0.002',},rc:'',fnv32:0x29bcffda}
12:56:02.490 -> {to:'Mst',from:'Log',reci:'dataValsCsv',pl:{tstamp:96722,valsCsv:'96.721;0.000;2024-08-29T10:56:03.0Z;0;Inval.;Inval.;Inval.;Inval.;Inval.;0;Inval.;29.0;25.9;25.2;963.5;58.83;0.00;7.30;3.29;5.06;0.325;0.315;0.302;1;0.000;1;0.000;0;0.002;0;0.002',},rc:'',fnv32:0x6d7d002d}

The invalid values comes from the sensor not being connected to the GPS satellite. This is o.k. for now.

@jremington
Thank you! I did not know that the Tx and Rx outputs desire a specific voltage. We have ordered an appropriate converter which should arrive at the beginning of next week. I will post an update as the converter is integrated :slight_smile:

1 Like