I am new to uart programming with nodemcu and lua scripts. I am trying to do serial communication between esp8266 and avr microcontroller. For this i am using UART functions in nodemcu. I used uart.write command and got the response in terminal window. However when i tried to read the data sent from terminal software like Hterm, i was not able to make it work. I dont understand about the basics of the uart.on function. i could not see much of example codes for the same. It would be of great help to me if someone can explain how to do serial read using esp8266. I have attached the small code i am working on. I am writing a serial data to microcontroller and in turn need to read two bytes of incoming serial data and display it. Is there any command to check if there is data available at read buffer ?. kindly help
device = 5
uart.setup(0,9600,8,0,1,0)
tmr.alarm(1, 2000,1, function()
A= adcintech0()
print(A)
end)
function adcintech0()
D=0
uart.write(0,2)
uart.on("data", 1,
function(data)
print("receive from uart:", data)
intech0low=data
print("intech0low", intech0low)
end, 0)
uart.on("data", 1,
function(data)
print("receive from uart:", data)
intech0hi=data
print("intech0high", intech0hi)
end, 0)
intech0=(intech0hi*255)+intech0low
return intech0
end