coolwolf / 10/08/2019

NodeMCU serial Communication with Nextion using LUA

  1. Never forget to set a fuse in init.lua
gpio.mode(6, gpio.INPUT)

if EnableBoot==0 then dofile("main.lua") 
else print("Device will not continue booting...")

Consider we have a text with id t0 on Nextion.
To test two way communication, we put a button on Nextion, which send “Hello from Nextion” over serial.
This incoming data is also printed to the debug screen.
The last component on Nextion is a gauge with id z0.

Below you can found main.lua file wihch does two way communication with Nextion. It sends the Pot value to the Nextion on input trigger. And at at every second it sends Pot value to Nextion’s gauge as integer value.

print("Normal Boot")

local MyInput=5
local Threshold=1000
local LastTrig=0
local PotValue=0


local mytimer = tmr.create()

local function SendToNextion(Object,Property,Value,IsInt)
    if IsInt then
        uart.write(0,Object.."."..Property.."="..Value..(string.char (255))..(string.char (255))..(string.char (255)))
        uart.write(0,Object.."."..Property.."=\""..Value.."\""..(string.char (255))..(string.char (255))..(string.char (255)))

local function InputTrigger(State, Time)
    local diff=ms-LastTrig
    if diff

I hope this helps.