How to use UART ?
Posted: Thu Nov 05, 2015 9:54 am
Hi,
My first post here
I didn't find the answer on the forum or anywhere else, hope someone can help.
So I have an NodeMCU with an ultrasonic sensor that can communicate through UART (TTL).
Now, my problem is twofolds:
1) should I connect the UART from my sensor to GPIO 1&3 (TXD0, RXD0) or GPIO 13-15 (TXD2, RXD2) ?
2) I actually tried both, but I don't get anything on my NodeMCU: uart.on() is never called. I know that I should get something, because a) it works with an Arduino, and b) if I connect the sensor to another GPIO, I do see signal changes (0-1- etc). I was thinking that maybe the USB-TTL converter of the NodeMCU is prevailing, but in this case I don't understand those samples:
uart.on("data", 4,
function(data)
print("receive from uart:", data)
if data=="quit" then
uart.on("data")
end
end, 0)
ie how can print and uart.on work together
Finally, if I write on UART, the output comes on my ESPLORER IDE, hence my suspicion of the USB-TTL prevailing.
My first post here
I didn't find the answer on the forum or anywhere else, hope someone can help.
So I have an NodeMCU with an ultrasonic sensor that can communicate through UART (TTL).
Now, my problem is twofolds:
1) should I connect the UART from my sensor to GPIO 1&3 (TXD0, RXD0) or GPIO 13-15 (TXD2, RXD2) ?
2) I actually tried both, but I don't get anything on my NodeMCU: uart.on() is never called. I know that I should get something, because a) it works with an Arduino, and b) if I connect the sensor to another GPIO, I do see signal changes (0-1- etc). I was thinking that maybe the USB-TTL converter of the NodeMCU is prevailing, but in this case I don't understand those samples:
uart.on("data", 4,
function(data)
print("receive from uart:", data)
if data=="quit" then
uart.on("data")
end
end, 0)
ie how can print and uart.on work together
Finally, if I write on UART, the output comes on my ESPLORER IDE, hence my suspicion of the USB-TTL prevailing.