Subhankar Majumder
Subhankar Majumder

Reputation: 33

How to make multiple serial communication using Nodemcu (Lua)

____________
|          |
|   N      |
|   O   Rx2|<------Tx EnergyMeter(Returns value based on command)
|   D   Tx2|------>Rx EnergyMeter(Receive command)   
|   E      |
|          |
|   M   Rx1|<------Tx Gsm(For MQTT)
|   C   Tx1|------>Rx Gsm(For MQTT)
|   U      |
|          |
-----------

I am trying to connect Gsm module and energy meter with my Nodemcu as shown in the diagram. Although it is possible by Arduino coding but I want to do it using lua only.

In case of lua scripting, if I use "uart.alt()" this function, and click on "Save to Esp", then at the line of "uart.alt()", saving process jumps to different usart and code doesnot completely save in to ESP.

Soo what is the efficient way of usinng multiple usart in nodemcu (something similar to software serial in arduino)?

I am using
Nodemcu model : ESP8266
Nodemcu Version : 3
& NodeMCU custom build by frightanic.com branch: 1.5.4.1-fina

I am not getting any perfect example which matching to my requirement. So, please give me a perfect documentation or example on this issue.

Thank You.

Upvotes: 2

Views: 2527

Answers (1)

Codebreaker007
Codebreaker007

Reputation: 2989

You did not give the make of your NodeMCU but as there is no uart.alt on ESP32 I guess 8266
So if your NodeMCU is an ESP8266 there is a problem with your setup:
From the ESP8266 documenation:
Although there are two UARTs(0 and 1) available to NodeMCU, UART 1 is not capable of receiving data and is therefore transmit only. I am not an expert in LUA but I guess thats what the compiler wants to tell you.
Yes there is a ESP32 version of NodeMCU the OP just states he uses NodeMCU and gave no further info.

uart.alt()  Change UART pin assignment. 

-means you can assign the pins of UART 0

 uart.alt(on)
Parameters

on

0 for standard pins
1 to use alternate pins GPIO13 and GPIO15

So this only works for one uart (UART 0) on NodeMCU ESP8266.

If you use an ESP32 based NodeMCU
Enabling UART 1 causes the ESP32 to crash! The reason is that by default, UART 1 uses the same pins as the ESP32 flash memory.

See official documentation of the NodeMCU ESP32 dev board.
So always give version of NodeMCU and board type when asking questions.

Upvotes: 5

Related Questions