Code Monkey home page Code Monkey logo

nextion's Introduction

A simple arduino library for the Itead Nextion HMI

Nextion LCD Touchscreen Tutorial for Arduino

http://openhardware.gridshield.net/home/nextion-lcd-getting-started-for-arduino

Nextion LCD Touchscreen Library Functions

http://openhardware.gridshield.net/home/nextion-example-code-functions

NOTE: The examples use Software Serial to communicate with the Nextion.

However, Hardware Serial can be used also:

In the file Nextion.h

Comment out the following code (line 47):

#define USE_SOFTWARE_SERIAL

Remove the lines:

#include <SoftwareSerial.h>

SoftwareSerial nextion(2, 3);// Nextion TX to pin 2 and RX to pin 3 of Arduino

Add the following define to assign a hardware serial port to "nextion":

#define nextion Serial1

Note that you can replace "Serial1" with Serial or Serial2 or whatever Serial ports your particular Arduino has.

If you are using an Arduino with only one hardware serial port (like the Arduino UNO) and want to use hardware serial you will have to use "#define nextion Serial" AND will need to remove all code that uses Serial for debugging. If you leave your Serial.print() commands in this case they will send data to the Nextion.

nextion's People

Contributors

bborncr avatar wifixcort avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nextion's Issues

send value to a component text an other page

hello
it's possible to send a value of componentText on other page ?
this code work on the page where temp1 is but not on other page
myNextion.setComponentText("temp1", String(temp1));
it's possible to send like this
myNextion.setComponentText("page1.temp1", String(temp1));
thanks a lot

Some functions don't work with Hardwareserial

I am using an Arduino Mega and use Serial1 for Nextion.
Nextion.listen() works fine but getComponentValue or paged() return no values or wrong values.
With SoftwareSerial all works fine but i can't use software serial in one special project.

Any ideas?

GetcomponentValue getting num while in Nextion debug

Hi. Having fun with this library. It works great with my Arduino Nano and Uno and the 2.4" Nextion. However when I'm just using the Arduino and the debug mode in the Nextion IDE without the TFT attached. The function getcomponentValue does not return a number. I did however discover that changing the timeout setting from 20 to 200 in the Nextion.cpp file worked.
Is this going to cause any unforeseen problems somewhere else?

Only thing weird I may be doing is continuing to use software serial and changing my RX TX settings to 0 and 1.

not at all as expected in editor

Hi, I'm a complete Nextion Noob trying this tutorial for the first time. I figured my recent Nextion probably was incompatible with the old tft files so I imported the HMI file for my rez into the Nextion Editor: 272x480Example.HMI

What I got was unexpected. The basic image seems to be reversed L/R and there is only 1 page. I expected 3 pages and the image to be right way around. Here's a link to screen snapshot

[img]https://i.imgur.com/5zYxpQ2l.png[/img]

So ummm... is this tute now so out of date that there is no hope for it & I must start from scratch, or is there some simple hack I can do to make the HMI file work...?

Library gives errors. Nextion::ack()

I get the following error when trying to use the library.
Nextion.cpp: In member function 'boolean Nextion::ack()':
Nextion.cpp:119:1: error: control reaches end of non-void function [-Werror=return-type]
119 | }//end
| ^
This only happens when using the latest ESP8266 software

exit status 1 'Nextion' does not name a type; did you mean 'nextion'? solution: install ITEADLIB_Arduino_Nextion-master AND bborncr-nextion-library

I encountered a very strange problem
when using your demo-code the compilation was only successful with having the
ITEADLIB_Arduino_Nextion-master-libary
AND
the https://github.com/bborncr/nextion/tree/master
beeing installed.

Only in case the https://github.com/bborncr/nextion/tree/master is installed

The compiler uses the
VERY STRANGE
ITEADLIB_Arduino_Nextion-master-libary

set the value of en on a timer

hello

it's possible to set the "en" variable of a timer like this
myNextion.setComponentTimer ("tm1", 0);

thanks a lot

RS232 commands

Hi, can I send, only with this display, some digital commands trough rxd txd ?
For example if I make a button ON, when i press him, this send via rs232
$18 $00 and for OFF button $18 $01
thank you in advance !

Arduino Mega

how to use in mega arduino? is not working the buttons: /, no one works perfectly, now the mega no longer works the buttons

puzzled by output of ReceiveMessages

Something is puzzling me about the output from this demo sketch. I have got some push buttons working on my Nextion, and am reading the serial port with a Uno successfully. I see this kind of output in my Monitor:

65 0 8 0 ffff ffff ffff
65 0 8 1 0 0 0 ffff ffff ffff
65 0 8 0 ffff ffff ffff
65 0 8 0 0 0 0 ffff ffff ffff

So far so good -- an on/off button id 8 on page 0 is pressed and released, and on the release event I send its id and also (in user code) package up a data message to send its state (selected); I press it again, and on release I get the release message again and my Nextion user code sends a further message with its state (deselected) and it's all fine. Except for those trailing EOM bytes!

The ITEAD doco says that the EOM marker is three bytes: 0xFF 0xFF 0xFF.

Yet the monitor is showing 6 bytes: FFFF FFFF FFFF.

I did take a look at the "listen" function and I don't see where those FFs are getting duplicated, yet when I print out my messages from the Nextion (user code) ending in FF FF FF, what I see in the log is FFFF FFFF FFFF. It's quite puzzling. I must be missing something obvious...!

getComponentText

Hi,
In the Nextion.cpp lines 184-201 are commented with /*
In this instance the command myNextion.getComponentText() doesn't work.
When descomment these lines everything work perfect on the Mega2560.

Anybody had luck getting this to work with platformio + stm32duino?

Tried various options but get:

Compiling .pioenvs\nucleo_l432kc\lib\nextionsimple\Nextion.o
lib\nextionsimple\Nextion.cpp: In member function 'uint8_t Nextion::pageId()':

lib\nextionsimple\Nextion.cpp:302:7: warning: unused variable 'a' [-Wunused-variable]
int a = -1;
^
lib\nextionsimple\Nextion.cpp: In member function 'void Nextion::flushSerial()':
lib\nextionsimple\Nextion.cpp:334:10: error: request for member 'flush' in '((Nextion*)this)->N
extion::Serial', which is of pointer type 'HardwareSerial*' (maybe you meant to use '->' ?)
Serial.flush();
^
lib\nextionsimple\Nextion.cpp: In member function 'boolean Nextion::ack()':
lib\nextionsimple\Nextion.cpp:119:1: warning: control reaches end of non-void function [-Wretur
n-type]
}//end
^
*** [.pioenvs\nucleo_l432kc\lib\nextionsimple\Nextion.o] Error 1
[ERROR] Took 2.42 seconds

Need help with getComponentText and getComponentValue

Please help me figure it out. The display has n0=0 and t0=text.
I use
`#include <SoftwareSerial.h>
#include <Nextion.h>
SoftwareSerial nextion(17, 16);
Nextion myNextion(nextion, 9600);

int recc;
String id, mess;

void setup()
{
Serial.begin(9600);
myNextion.init();

}
void loop() {

mess = myNextion.getComponentText("t0");
Serial.print("mess: ");
Serial.println(mess);

delay(1000);

recc = myNextion.getComponentValue("n0");
Serial.print("recc: ");
Serial.println(recc);

delay(1000);
}`

And I get
mess: 1a
recc: -1
Tell me what I'm doing wrong. I want to get at least a text. Thank you!

Receive problem

Hello, i'm using Nextion and a Arduino Mega 2560, and my problem is i can't send to nextion with arduino but arduino don't receive from nextion, ReceiveMessages example don't work, but UpdateText example work so the problem is like i said i can't receive from nextion, on nextion, i only put 1 button to try the receive message, send component ID activated on it. And i receive anything on arduino when i touch the button. I tried to plug the nextion TX cable every where but it isnt working, i even setup the library for Serial1 and still not working, so i don't know what to do to fix it :c please help me

Problem with serial

Hi bborncr,
I update all the instructions (readme.md) but the compiler show: expected identifier before numeric constant. I use Nextion 4.3" with Arduino Mega 2560.
This is my code:

include <Nextion.h>

define nextion HardwareSerial

nextion myNextion(nextion, 9600); // error compiler

boolean button1State;
boolean button2State;

// sensor "progress" bar
int x = 56;
int y = 321;
int width = 195;
int height = 8;

int old_sensor_value = 0;

void setup() {
// Serial.begin(9600);
myNextion.init();
}

void loop() {

String message = myNextion.listen();

if (message == "65 0 2 0 ffff ffff ffff") {
myNextion.buttonToggle(button1State, "b0", 0, 2);
}
if (message == "65 0 3 0 ffff ffff ffff") {
myNextion.buttonToggle(button2State, "b1", 0, 2);
}

int sensor = 0;

for (int i = 0; i < 10 ; i ++) { // get average
sensor += analogRead(A0);
}
sensor = sensor / 10;

if (abs(sensor - old_sensor_value) > 20) {
old_sensor_value = sensor;

int scaled_value = map(sensor, 0, 1023, 0, 100); // always map value from 0 to 100

myNextion.updateProgressBar(x, y, width, height, scaled_value, 0, 2); // update the progress bar
myNextion.setComponentText("t0", String(sensor));  // update text using original sensor value

}
}

Hardware Serial gets annoying values

Hello, I was using Nextion Display with Software Serial in my Arduino MEGA, then I changed to Hardware Serial... Everything works ok, when I press a button the Arduino recognizes it and make the right thing...

The only problem is after pressing any button which sends information to arduino, this information keeps repeating every 4-5 seconds, but it repeats only a part of the original sent variable.

Take a look in the log:

sem titulo123

I'm using Nextion Display (normal edition) with Arduino MEGA 2560 in Hardware Serial port number 2

My display code is correct, when I use the debug option in Nextion HMI, there is no sending of values ​​from time to time. (And I checked all the code)

Need help with "sendCommand".

Hello. Love this library, because of it`s simplicity.
My problem: I can do nex.getComponentValue("page0.n" + String (variable));
also nex.setComponentValue("page0.n" + String (variable)); works.
How can i achieve nex.sendCommand("page0.n" + String (variable) + "bco=65533"); ?
Thank you.

Отправка команды с Arduino Nano в Nextion

Подскажите пожалуйста , как отправить команду с Arduino Nano на дисплей Nextion
click n0,1// Вызов события нажатия
delay=300
click n0,0// Вызов события отжатия
Данная команда проходит , если ее запускать в Nextion Editor.

Read from Nextion Screen

Hi,

I noticed that these Libraries doesn't have the features to read inputs from Nextion to Arduino.
i.e. read the Text Component Value to Arduino or the Number Component value to Arduino.
Does anyone has such a code to do it?

Thanks.

Error in receiving values larger than 65536

The library is excellent and fast. Thank you.

I have one issue: some of my settings data which I enter in Nextion display are above 2^16 (65536); for example (66000), I only received the rest after 65536, which was 464. So, any number above 65536 can't be received correctly. I tried with different values; all were correct except the numbers above 65536. Please advise.

Issue uploading to arduino board

Arduino: 1.6.6 (Windows 7), Board: "Arduino Pro or Pro Mini, ATmega328 (5V, 16 MHz)"

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SoftwareSerial\SoftwareSerial.cpp:375:6: warning: always_inline function might not be inlinable [-Wattributes]

void SoftwareSerial::setRxIntMsk(bool enable)

  ^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SoftwareSerial\SoftwareSerial.cpp:121:6: warning: always_inline function might not be inlinable [-Wattributes]

void SoftwareSerial::recv()

  ^

C:\Users\Owner\Documents\Arduino\libraries\nextion-master\Nextion.cpp:235:9: error: exponent has no digits

4ecc8e6

     ^

C:\Users\Owner\Documents\Arduino\libraries\nextion-master\Nextion.cpp: In member function 'unsigned int Nextion::getComponentValue(String)':

C:\Users\Owner\Documents\Arduino\libraries\nextion-master\Nextion.cpp:131:25: warning: left shift count >= width of type [enabled by default]

 value = (temp[4] << 24) | (temp[3] << 16) | (temp[2] << 8) | (temp[1]);//Little-endian convertion

                     ^

C:\Users\Owner\Documents\Arduino\libraries\nextion-master\Nextion.cpp:131:43: warning: left shift count >= width of type [enabled by default]

 value = (temp[4] << 24) | (temp[3] << 16) | (temp[2] << 8) | (temp[1]);//Little-endian convertion

                                       ^

C:\Users\Owner\Documents\Arduino\libraries\nextion-master\Nextion.cpp: In member function 'String Nextion::listen(long unsigned int)':

C:\Users\Owner\Documents\Arduino\libraries\nextion-master\Nextion.cpp:226:1: error: expected primary-expression before '<<' token

"<<<<<<< HEAD"

^

C:\Users\Owner\Documents\Arduino\libraries\nextion-master\Nextion.cpp:226:3: error: expected primary-expression before '<<' token

<<<<<<< HEAD

^

C:\Users\Owner\Documents\Arduino\libraries\nextion-master\Nextion.cpp:226:5: error: expected primary-expression before '<<' token

"<<<<<<< HEAD"

 ^

C:\Users\Owner\Documents\Arduino\libraries\nextion-master\Nextion.cpp:226:7: error: expected primary-expression before '<' token

" <<<<<<< HEAD"

   ^

C:\Users\Owner\Documents\Arduino\libraries\nextion-master\Nextion.cpp:226:9: error: 'HEAD' was not declared in this scope

"<<<<<<< HEAD"

     ^

C:\Users\Owner\Documents\Arduino\libraries\nextion-master\Nextion.cpp:234:3: error: expected primary-expression before '==' token

=======

^

C:\Users\Owner\Documents\Arduino\libraries\nextion-master\Nextion.cpp:234:5: error: expected primary-expression before '==' token

=======

 ^

C:\Users\Owner\Documents\Arduino\libraries\nextion-master\Nextion.cpp:234:7: error: expected primary-expression before '=' token

=======

   ^

C:\Users\Owner\Documents\Arduino\libraries\nextion-master\Nextion.cpp:235:1: error: expected primary-expression before '>>' token

">>>>>>> 4ecc8e6"

^

C:\Users\Owner\Documents\Arduino\libraries\nextion-master\Nextion.cpp:235:3: error: expected primary-expression before '>>' token

">>>>>>> 4ecc8e6"

^

C:\Users\Owner\Documents\Arduino\libraries\nextion-master\Nextion.cpp:235:5: error: expected primary-expression before '>>' token

">>>>>>> 4ecc8e6"

 ^

C:\Users\Owner\Documents\Arduino\libraries\nextion-master\Nextion.cpp:235:7: error: expected primary-expression before '>' token

">>>>>>> 4ecc8e6"

   ^

C:\Users\Owner\Documents\Arduino\libraries\nextion-master\Nextion.cpp:236:3: error: expected ';' before 'String'

String temp = "";

^

C:\Users\Owner\Documents\Arduino\libraries\nextion-master\Nextion.cpp:242:4: error: 'temp' was not declared in this scope

temp += String(cmd[i], HEX);//add hexadecimal value

^

exit status 1
Error compiling.

how to change orientation of display from arduino.

Hi there, I want to have multiple screens. one screen will be in portrait mode and the other one in landscape mode. can we do this with nexition? it only let me select one orienctation either landscape or potrait. can anyone help?

Weired output on getComponentValue

Hi there,

hopefully this lib is still supported by the community.
I´ve got some issues with the getComponentValue function.
I´m using the following code on my ESP32 using Hardware Serial2.
As soon as I toogle my button it should output the toogle button val on my serial monitor,
but I get this weired output. What did I wrong?

65 0 2 1 ff ff ff Toogle Button -1 q�???

`
#include <Nextion.h>

Nextion myNextion(nextion, 9600);

void NextionInit() {
if (myNextion.init()) {
Serial.println("Nextion Ready...");
} else {
Serial.println("Nextion not responding...");
}
}

void NextionListen() {
String message = myNextion.listen();
if (message != "") {
Serial.println(message);
if (message == "65 0 2 1 ff ff ff") {
Serial.println("Toogle Button");
int value = myNextion.getComponentValue("bt0");
Serial.println(value);
} else if (message == "65 0 3 1 ff ff ff") {
Serial.println("Simple Button");
myNextion.setComponentValue("bt0", 1);
}
}
}
`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.