ESP8266 serial read UART.ON

Thread Starter

sriniketh

Joined Jul 7, 2015
30
Hello everyone

I am trying to establish communication between avr atmega328p and esp8266 via serial ports. i need to send a char to microcontroller and receive two bytes from the microcontroller. I use nodemcu firmware and using lua programming for esp8266. I tried uart.write() and got the response in terminal software like Hterm. However when i tried to use the uart.on to read the characters sent from the terminal software, it didnt work for me. I did not fully understood what uart.on does and how to read serial data using esp8266 uart.on command. Is there a way to check if the read buffer is non zero and then start the read process. ? kindly guide me in understanding this concept of uart.on

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
 
Top