2
____________
|          |
|   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.

1 Answers1

5

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.

Codebreaker007
  • 2,911
  • 1
  • 10
  • 22
  • Great answer! Please take note that there are no ESP32 _NodeMCU_ hardware modules. Whatever the fake/clone producers might claim on their websites the NodeMCU brand is strictly for two (now outdated) ESP8266 modules: http://frightanic.com/iot/comparison-of-esp8266-nodemcu-development-boards/ – Marcel Stör Mar 30 '20 at 07:01
  • NodeMCU is the name of a lua OS and later was used by Amica for their "preloaded boards" So my answer is as it is, because these two SW and HW versions exist and can be used. My link is from the original source. And yes I know your vita;-) If you want to buy one [NodeMCU-ESP32 (see chip its original ESP32)] (https://www.amazon.de/AZDelivery-ESP32-NodeMCU-Module-Parent/dp/B07Z6CSD9K) – Codebreaker007 Mar 30 '20 at 08:13
  • 1
    "NodeMCU" as a term is for both hardware and firmware, that's correct. I'm a committer with the firmware project. The firmware works with _any_ ESP8266, ESP8285 and ESP32. However, NodeMCU only every designed 2 ESP8266 dev boards: 0.9/V2 and 1.0/V2. No V3 and nothing for ESP32. Many copy-cats seem to seem to label anything that has a ESP8266/ESP32 on a PCB "NodeMCU". – Marcel Stör Mar 30 '20 at 21:31
  • Thats right Marcel, as I wrote I know your vita ;-) but for others its hard to differentiate, thats why I mentioned this issue. Thanks for your work – Codebreaker007 Mar 30 '20 at 21:43