teensy 3.2 nextion

Status
Not open for further replies.

vlelectroniclab

Active member
Hello,
I use a teensy 3.2 and a uart nextion display, now to update the display I have to connect it with a ttl usb converter.
I have two possibilities
N1) that the teensy acts as usb ttl when I have to program the dislpay
N2) I have to put some diodes on the rx and tx line so that when I have to update I leave both the teensy and the display connected and I add the ttl usb converter.
What do you recommend? are there other solutions?
 
Normally, once the firmware for the Nextion written, compiled, tested, validated and uploaded, there shouldn’t be the need to update it, if the HMI design was made thoughtful and purposeful. I’ve a project with Teensy and Nextion which can take 5 variants. I packed everything on different pages in the HMI, so that the application running on the Teensy can decide which pages are used and which not. Thus, I preload the Nextions once with the firmware before they are connected to the respective Teensy and then, this package goes out to the customer.
If, in a few years or so, a Nextion firmware upgrade would really be required, but I really can’t imagine not having anticipated everything, I’d tell the customers to download the new tft file, copy it on a SD card and put the latter directly into the Nextion’s SD slot, so that the Nextion will update itself at the next power up.
 
Hi, the problem is that to put the sd I have to disassemble the display due to the limited space.
However I make a connector and I carry the wires of the serial to a diverter where I decide whether to program I have normal use.
Hello and thanks
 
Hi vlelectroniclab, I was about to open the same kind of topic, so I'll take the opportunity to use yours since my problem is related to your request.

I've been struggling for a long time now trying to program a 3.2" Nextion screen using the Teensy 3.2 as a serial bridge, without success so far.
For the application I'm working on (screen embedded in a steering wheel using SimHub), being able to update the Nextion often is mandatory because I want to support many types of cars, and try different features.
I've tried with several baud rates (19200, 38400, 115200), with and differents CPU clocks, with Serial1 and Serial3, none of them work (upload proceeds until the end, but I get a CRC check error at the end).

It works with a Teensy LC and with a Teensy 3.6 at 115200 bauds, without a problem (I'm using the USBToSerial example, with the 57600 baud rate hack and the DTR code removed).
The file I'm trying to upload is quite big (1.14 Mbytes), so I can't look at all the bytes sent with a logic analyser. I think it may be a problem of clock precision, but it shouldn't as the Teensy LC is supposed to have 0.16% error at 115200 compared to the -0.2% error of the Teensy 3.2 at this baudrate.

I've asked on the Nextion forum but got not answer, which I understand as the problem doesn't seem to come from the Nextion itself nor from the upload program of the Nextion Editor.

I don't know what to try now, does anyone have a suggestion ?
 
Last edited:
I think I just found the solution ! : I increased the serial tx buffer size to 4096 (serial1.c, line 40).
Weird, as the Teensy LC doesn't have a FIFO on Serial1, It shouldn't have worked with it.
 
I know this is an old thread, but I'm trying to do the same thing and having the exact same problem - hoping Etienne or anyone else familiar with this might chime in.

I've got a Teensy 3.2 hooked up via Serial2 to a Nextion NX4024T032 3.2" display. Sending serial commands from the Teensy to control the display works great, and programming the display either via its SD card or via the Nextion editor uploader over USB through a FTDI breakout works well. However, in order to make my life easier while I fine tune the display layout in situ, being able to use the Teensy as a USB pass through from my computer would be awesome.

I'm currently using a baud rate of 115200 (though I've tried several others with less success), and can get some code to upload to the Nextion through the Teensy when I make a minor change to it, but if it does a full upload (say after changing an image file in the display configuration) it goes through the whole transfer process to 100% and then shows a 'check error'.

I tried changing line 40 in my Serial2.c (similar to what Etienne suggested in their previous post), but it did not solve the problem. I don't believe there's any difference between serial1 and serial2. It's so close to working, there's just something happening with the longer upload...

Here's the code I'm using to transfer USB serial to Serial2 (connected to the Nextion):

Code:
#define HWSERIAL Serial2  //set to Serial2 for first Nextion display

void setup() {
	Serial.begin(115200); //setting teensy's serial to the same baudrate as the Nextion display
	HWSERIAL.begin(115200);//display has been set to a baudrate of 115200 previously using the Nextion editor
}

void loop() {
        byte incomingByte;
        
	if (Serial.available() > 0) {
		incomingByte = Serial.read();
    HWSERIAL.write(incomingByte);
	}
	if (HWSERIAL.available() > 0) {
		incomingByte = HWSERIAL.read();
    Serial.write(incomingByte);
	}
}
 
Below is basically the code that I've used for some time. Works on Serial1/Serial2/Serial3 without issues. Automatically sets the max baud rate which makes for quick uploads. If you're using the Nextion Uploader then it will see the connected Teensy as a Nextion device and automatically find the correct COM port. Just hit upload and both the Nextion and Teensy will restart once the update has completed.

Remember to close the serial monitor beforehand.


Code:
#define CPU_RESTART_ADDR (uint32_t *)0xE000ED0C
#define CPU_RESTART_VAL 0x5FA0004
#define CPU_RESTART (*CPU_RESTART_ADDR = CPU_RESTART_VAL);
#define tft Serial3

void TFT_serial_update() {
  byte s1;
  long bytecount=0;
  tft.print("page tftupdate\xFF\xFF\xFF");  //page on the Nextion that prompts to begin sending TFT file 
  tft.print("baud=921600\xFF\xFF\xFF");   //temporarily set the Nextion to the highest possible baud ratte 
  delay(300);
  tft.begin(921600); 
  Serial.begin(921600); 
  delay(700);
  elapsedMillis ms;
  tft.clear();
while(bytecount<30 || ms<2000)  { 
  if(Serial.available()) { 
    tft.write(Serial.read());
    bytecount++;
    ms=0;
  }
  if(tft.available()) { 
    Serial.write(tft.read());
    ms=0;
  }
}
  delay(1000);
  CPU_RESTART    // Update completed. Restart Teensy
}
 
Thank you so much for replying ratnin! I wound up going with a hardware based approach to switch to a "screen programming" mode with a DPDT switch on the serial signal, but this will still be very useful if that switch won't package neatly, or for anyone else trying to do something similar.
 
Status
Not open for further replies.
Back
Top