Post your best Lua script examples here

User avatar
By jclmdt
#61339 Hi,

I have a lolin nodemcu v3 and I am running the nodemcu firmware on it with Lua. I want to send data from my Arduino Mega to the lolin chip. I followed the following website http://randomnerdtutorials.com/sending- ... ia-serial/ accordingly but failed to get the intended output.

I uploaded the same Arduino code as provided in the above stated website to my Arduino Mega, and connect the GND to be with lolin nodemcu GND, and also from arduino's tx0 (pin1) to lolin's pin RX (via voltage divider).

Next, I uploaded the provided script onto my lolin nodemcu board. As it is not the ESP8266 chip by itself, I did not need to use FTDI. Instead I just plug in a usb cable to it and the code is uploaded in it. I set it to be 9600 baudrate in the ESPlorer IDE. However, the LED connected to the lolin chip did not light up at all (It is suppose to turn on and off according to the code). In addition, instead of printing out 'Received from Arduino: HI!' followed by 'LED ON (or Off)', the lolin seems to be outputting the code uploaded into it (see the picture attached).

And now when i try to upload new lua script to lolin, it does not work as the ESPlorer IDE says 'Waiting answer from ESP - Timeout reached. Command aborted'. Any idea how to solve this issue too?

It seems that the lolin is not receiving anything from Arduino Mega. Arduino is indeed transmitting as the LED of tx is flashing and the words can be seen on the Arduino serial monitor as well. What can solve this issue? Thank you in advance.
Attachments
ESPlorer IDE screenshot.jpg
Screenshot of ESPlorer IDE
User avatar
By devsaurus
#61353 You're facing the issue that the USB-to-serial convertor on the nodemcu board hooks up to ESP's RXD0 and TXD0 lines. So when you connect the Arduino's tx0 (pin1) to lolin's pin RX the Arduino collides with the TX of the on-board convertor. The voltage divider protects the two chips but the Arduino is probably not able to overdrive the convertor.

A solution could be to route the ESP UART to the alternate pins (http://nodemcu.readthedocs.io/en/dev/en ... t/#uartalt) and connect as follows:
  • Pin 6 / GPIO13 to Arduino TX0
  • Pin 5 / GPIO15 to Pin 3 / GPIO1 via a 470 Ohm resistor
Ref. https://github.com/nodemcu/nodemcu-devk ... _ESP12.PDF

You need to add this uart.alt(1) statement at the beginning of your script. But be aware that this is init.lua and you can't send any commands from ESPlorer to the ESP afterwards!
Add a timer with maybe 5 sec delay before uart.alt(1) and uart.on() to have enough time to delete init.lua from ESPlorer directly after reset (while UART is still in default configuration).
User avatar
By jclmdt
#61362 Thank you for the reply. I tried to do the connection as what you said, so this is my new connection.
Arduino > Lolin
TX0 (pin 1) > D7 (GPIO13)
GND > GND

Lolin has D4 connected to LED, which is pin 4 as stated in the code.

I have also included uart.alt(1) in the code with a delay after it. (Not too sure how to use timer, so i used tmr.delay(2000000))

Despite these changes, it is still not working as expected. The LED did light up but in a weird way. When i reset the module, it flashes quickly once and light up for 1 full second before it turn off completely. The ESPlorer IDE also returns the statement 'In script1 (new line) lua: script1.lua:7: attempt to call field 'alt' (a nil value)' which seems to be an error as it did not print any other statements i included in the code for debugging purpose. It seems to be stuck at the uart.alt(1) line. What's even confusing to me is the lighting up of the LED, once a flash and the second time a full light up for 1 second before it off completely.

Attached is the new code I loaded into lolin. Many thanks.
Attachments
SS2.jpg