Nextion Display and Portenta Communication

Hello,

I have very little experience using the Portenta Machine Control and I am currently just trying in to communicate with Nextion Display. I was using a nano before with the code provide below and was able to change the display but since I switched to the portenta I haven't been able to change anything. I have been looking at the forums and saw that a rs485 to ttl converter would fix that but after trying to set it up I am still unable to solve the problem

/*
The following sketch is an example of how to send data to the Nextion display without any library.
 
The data can be text, numbers, or any other atribute of an object.
 
You can also send System Variables to change settings on the display like: brightness, serial baud rate, etc.
 
Connection with Arduino Uno/Nano:
* +5V = 5V
* TX  = none
* RX  = pin 1 (TX)
* GND = GND
 
This sketch was made for my 1st video tutorial shown here: https://www.youtube.com/watch?v=wIWxSLVAAQE
 
Made by InterlinkKnight
Last update: 02/04/2018
*/
#include <Arduino_MachineControl.h>
 
 
 
using namespace machinecontrol;
 
int variable1 = 0;  // This is a simple variable to keep increasing a number to have something dynamic to show on the display.
 
void setup() {  // Put your setup code here, to run once:
    // Start serial comunication at baud=9600. For Arduino mega you would have to add a
                       // number (example: "Serial1.begin(9600);").
  comm_protocols.init();
 
    // RS485/RS232 default config is:
    // - RS485/RS232 system disabled
    // - RS485 mode
    // - Half Duplex
    // - No A/B and Y/Z 120 Ohm termination enabled
 
    // Enable the RS485/RS232 system
    comm_protocols.rs485Enable(true);
 
    comm_protocols.enableCAN();
 
    // Enable the RS232 mode
    comm_protocols.rs485ModeRS232(true);
   
 
    // Specify baudrate for RS232 communication
    comm_protocols.rs485.begin(9600);
    Serial1.begin(9600);
    // Start in receive mode
    comm_protocols.rs485.receive();
 
 
}  // End of setup
 
 
void loop() {  // Put your main code here, to run repeatedly:
 
 
  // We are going to send the variable value to the object called n0:
  // After the name of the object you need to put the dot val because val is the atribute we want to change on that object.
  Serial1.print("n0.val=");
    // This is sent to the nextion display to set what object name (before the dot) and what atribute (after the dot) are you going to change.
  Serial1.print(5);  // This is the value you want to send to that object and atribute mention before.
  Serial1.write(0xff);  // We always have to send this three lines after each command sent to the nextion display.
  Serial1.write(0xff);
  Serial1.write(0xff);
 
 
 
}   // End of loop
 


Hi @gregggggg,

I have been trying to solve this problem as well in an older thread. I hope to begin testing again in the new year and hopefully we can find a solution.

I was able to get the EasyNextionLibrary to work...at least partly, via RS-232 for now through software serial. This is surely a rather messy way of doing things, but info about how to work with the PMC almost doesn't exist, and I'm honestly not the best programmer.

For some reason the myNex.write commands didn't work for me, so I've been using myUART1.print("data to send"); format when sending data from the PMC to the Nextion.

Before sending any data, I issue the following:

  comm_protocols.rs485.noReceive();
  comm_protocols.rs485.beginTransmission();

Then when send data with standard myUART1.print commands, or whatever you named your serial instance.

After any transmission, I terminate with:

  myUART1.write(0xff);
  myUART1.write(0xff);
  myUART1.write(0xff);
  comm_protocols.rs485.endTransmission();
  comm_protocols.rs485.receive();

The myNex.read commands seem to work fine, so that's quite easy.

As for the code to make it happen...

Declare the EasyNex instance with:
UART myUART1(PA_0, PI_9, NC, NC); // This is TXN485 and RXP485 on the PMC
EasyNex myNex(myUART1); // Change myUART1 to whatever name you want.

(This basically sets up a software serial instance for the EasyNextion library, and hijacks the RS-232 port pins to operate with.)

In setup() place this.

 comm_protocols.init();
 comm_protocols.rs485Enable(true);          
 comm_protocols.rs485ModeRS232(true);  // This line changes the RS485 port to RS232 mode.  
 comm_protocols.rs485.begin(115200, 0, 500);
 comm_protocols.rs485.receive();
 myNex.begin(57600);  // The baud rate in the Nextion must match what you set this to. 

In loop() place this line.
myNex.NextionListen(); //(Mandatory)- makes Arduino listen for incomming serial coms from HMI.

could you share your full sketch so i can use it as reference?
Thanks!

I solved the issue with an Arduino Giga R1 Wi-Fi. I communicate via Wi-Fi to the Portenta with the Giga, where I connected my Nextion display, and everything works correctly. It requires one extra piece, but it works. I had tried using a TTL to RS485 signal converter, but the communication wasn't stable; sometimes the correct packet wasn't sent to the display or vice versa.