Teensy 3.2 and Nextion Display

Status
Not open for further replies.

Raymond_B

Well-known member
Hi all, I just received a Nextion 3.2" display. I have it connected up to my Teensy 3.2 to pins 0 and 1. Nextion Tx --> Teensy Rx pin 0 and Nextion Rx --> Teensy Tx pin 1.

I get no communication between the two. I have even unplugged the USB from Windows and used a simple USB wall adapter for the devices. This did nothing. Do I need to define the Serial port in the sketch?

Below is the Nextion sample;

Code:
/**
 * @example CompButton.ino
 * 
 * @par How to Use
 * Show how to use API of class NexButton.  
 *
 * @author  Wu Pengfei (email:<pengfei.wu@itead.cc>)
 * @date    2015/7/10
 * @copyright 
 * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 */

#include "Nextion.h"

NexButton b0 = NexButton(0, 1, "b0");

char buffer[100] = {0};

NexTouch *nex_listen_list[] = 
{
    &b0,
    NULL
};

void b0PopCallback(void *ptr)
{
    uint16_t len;
    uint16_t number;
    NexButton *btn = (NexButton *)ptr;
    dbSerialPrintln("b0PopCallback");
    dbSerialPrint("ptr=");
    dbSerialPrintln((uint32_t)ptr); 
    memset(buffer, 0, sizeof(buffer));
    btn->getText(buffer, sizeof(buffer));
    
    number = atoi(buffer);
    number += 1;

    memset(buffer, 0, sizeof(buffer));
    itoa(number, buffer, 10);
    
    btn->setText(buffer);
}

void setup(void)
{    
    nexInit();
    b0.attachPop(b0PopCallback, &b0);
    dbSerialPrintln("setup done"); 
}

void loop(void)
{   
    nexLoop(nex_listen_list);
}

I tried making some changes like so with no joy;

Code:
/**
 * @example CompButton.ino
 * 
 * @par How to Use
 * Show how to use API of class NexButton.  
 *
 * @author  Wu Pengfei (email:<pengfei.wu@itead.cc>)
 * @date    2015/7/10
 * @copyright 
 * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 */

#include "Nextion.h"

NexButton b0 = NexButton(0, 1, "b0");

char buffer[100] = {0};

NexTouch *nex_listen_list[] = 
{
    &b0,
    NULL
};

void b0PopCallback(void *ptr)
{
    uint16_t len;
    uint16_t number;
    NexButton *btn = (NexButton *)ptr;
    Serial.println("b0PopCallback");
    Serial.print("ptr=");
    Serial.println((uint32_t)ptr); 
    memset(buffer, 0, sizeof(buffer));
    btn->getText(buffer, sizeof(buffer));
    
    number = atoi(buffer);
    number += 1;

    memset(buffer, 0, sizeof(buffer));
    itoa(number, buffer, 10);
    
    btn->setText(buffer);
}

void setup(void)
{    
  Serial.begin(9600);
    nexInit();
    b0.attachPop(b0PopCallback, &b0);
    Serial.println("setup done"); 
}

void loop(void)
{   
    nexLoop(nex_listen_list);
}

Looking through some of the Nextion info it appears they say to define your serial port in the NexSerialConfig.h, but I was thinking that's only to turn off debugging.
 
Looks like it uses Serial2.

Try connecting your signals to RX2 & TX2 (pins 9 & 10).

Haha that was too easy, I must have had my wires crossed when I tried Serial2 :) Anyway thank you so much! Also Paul I'd be willing to send you a Nextion display if you have any interest in them working with the Teensy.
 
Ha, woulda taken you up on that offer *before* it was working. Really, if it works fine, no need for one here. It'll just take space away from the many other things that actually do need testing!
 
OK, well if one ever piques your interest I'd be more than happy to order one and ship it to you. Part a token of appreciation and part my own selfish interests :)
 
Good news that you got it working:) I have been using the 4dSystems displays and looking for something with similar functionality but a better price point would love to hear how you get along with the Nextion displays.
 
Good news that you got it working:) I have been using the 4dSystems displays and looking for something with similar functionality but a better price point would love to hear how you get along with the Nextion displays.

Thanks! I'll keep you posted. I am going to stream CAN data to it from a Megasquirt fuel injection system. I had the little TFT from Paul working (with help from great folk's here), but it is a bit challenged when trying to update data quickly. I also want to enable several pages of data that can be accessed via touch. I believe Nextion has updated their code to support some pretty high baud rates which is nice. Eventually I'd like to use their 7" display as a digital dash.

Also, it's a small victory, but those are the best :)

https://youtu.be/WJYs_RW1J84

View attachment power_button.ino
 
Last edited:
Status
Not open for further replies.
Back
Top