EasyNextion writeStr to nextion screen

Hey all,

I am working on a scanner which will save barcodes and the amount of products scanned.
So far I got the code working that it writes the 2 variables on the sd card from my nextion display and my barcode scanner is working on my serial monitor.

The only problem is I want to write the barcode when it scans to a text (t2.txt) on my nextion so it will show you on screen what barcode you have scanned.

the bit of code that isnt working is in the void loop, since I want the scanner to always pick up on new codes that are scanned:

void loop() {
  myNex.NextionListen(); // WARNING: This function must be called repeatedly to response touch events
                         // from Nextion touch panel. Actually, you should place it in your loop function.
{
  if (Barcode.available()) // Check if there is Incoming Data in the Serial Buffer.
  {
    while (Barcode.available()) // Keep reading Byte by Byte from the Buffer till the Buffer is empty
    {
      char input = Barcode.read(); // Read 1 Byte of data and store it in a character variable
      Serial.print(input); // Print the Byte
      delay(5); // A small delay
    }
    myNex.writeStr("t2.txt");
  }
}
}

According to the easynextion github the syntax should work, yet it does not.

Does anyone know what I am doing wrong?

If you need more info I am happy to give that ofcourse.

Greets,

wigets

You have to pass a second parameter which is the actual data
myNex.writeStr("t2.txt", "hello");

so in your case, you will need to put all your barcode data into an array and then pass that along.

    char myBarcode[80];  // large enough for the biggest barcode you will read
    int idx = 0;
    while (Barcode.available()) // Keep reading Byte by Byte from the Buffer till the Buffer is empty
    {
      char input = Barcode.read(); // Read 1 Byte of data and store it in a character variable
      Serial.print(input); // Print the Byte
      myBarcode[idx++] = input;  // save data
      delay(5); // A small delay
    }
     myBarcode[idx] = '\0';  // terminate string
    myNex.writeStr("t2.txt", myBarcode);

Works like a charm.

Thank you so much for helping a newbie out!

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