Issue receiving string via COM Port from LabVIEW and printing to OLED Display

Hi all,

I am running some testing with National Instruments hardware that is all being controlled from a VI on LabVIEW. To update an observer, I want to print out the current Trial Number and Displacement to a display.

I figured the easiest way to achieve this would be to build a string with these values and send it to an Arduino over the COM port using the VISA Write command in LabVIEW, and have the Arduino to pick up this string and print it to an OLED display.

I have successfully tested sending the desired string from the Serial Monitor in the Arduino IDE, which then prints out the desired message on the OLED display. I have written the script so that it receives data in the form ", mm", and prints to the OLED "Trial: \n \n Displacement : \n \n mm". I have attached images of this working and the code is below.

If I write "47, -1.23 mm" into the Arduino's Serial Monitor, I see "Trial: 47 \n \n Displacement: \n \n -1.23 mm" on the OLED display. However, if I send the exact same string to the Arduino using the VISA Write command, the screen flashes white but I don't see anything else. I have ensured that I have selected the correct COM port and also the correct baud rate (115200) in LabVIEW. I have attached screenshots of the VI that is the segment of code in LabVIEW that I have used, unfortunately I am unable to attach the VI file type to this thread.

I also tried accessing the Arduino's COM port using Tera Term. Once I select the correct baud rate, if I send something like "47, -1.23 mm", the OLED displays the message as desired.

Can anyone identify what might be wrong? Suggestions of improvements/things I should try are very welcome. Thank you

#include <TFT.h>
#include <SPI.h>


#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
    #define SERIAL SerialUSB
#else
    #define SERIAL Serial
#endif


// pin definition for Arduino UNO
#define cs   10
#define dc   9
#define rst  8



// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);

void setup() {

  TFTscreen.begin();                  //initialize the library

  TFTscreen.background(0, 0, 0);      // clear the screen with a black background
  
  TFTscreen.setTextSize(2);           //set the text size
  
  TFTscreen.stroke(255, 0, 0);        // Set text to a blue colour
  
  Serial.begin(115200);               // Begin serial
}

void loop() {


 if (Serial.available())                                           
    {

      String trialNo;                                              // initialise strings to hold values for display
      String strDisplacement;
      
       while (Serial.available() > 0) {                            // Check if data is available at serial port

          trialNo = Serial.readStringUntil(',');                   // Writes the Trial Nr to a string until a comma
          Serial.read(); 
          strDisplacement = Serial.readStringUntil(',');           // Writes the displacement to a string until a comma
          Serial.read(); 
        
       }

      TFTscreen.background(255,255,255);                          // Background is set to White

      String strDisplay = "Trial: " + trialNo + "\n" + "\n" + "Displacement:" + "\n" + "\n" + "   " + strDisplacement;  // Display text is made
      int len = strDisplay.length();                              // Length of display text is calculated
      char txt[len];                                              // Character array is created with the same length as display text string
      strDisplay.toCharArray(txt,len);                            // Display text string is converted to a character array
      
      
      TFTscreen.text(txt, 22, 20);                                // The LED displays the character aray
      delay(2000);                                                // 2 second pause to ensure display can be read
      txt[0] = 0;                                                 // Character array is cleared
    }

delay(200);                                                       // Small delay on the loop
}

LabVIEW Front Panel.JPG