Shop OBEX P1 Docs P2 Docs Learn Events
serial communication with the ESP8266 using the nodeMCU-firmware (script-languageLua) — Parallax Forums

serial communication with the ESP8266 using the nodeMCU-firmware (script-languageLua)

StefanL38StefanL38 Posts: 2,292
edited 2015-03-22 06:31 in Propeller 1
Hi everybody who is interested in using the ESP8266 WiFi-SoC with the nodeMCU-Firmware

I posted the links in another thread but for completenes I will post it here too:

first of all visit this website to read how to flash the nodeMCU-firmware into a ESP8266-module:
http://benlo.com/esp8266/esp8266QuickStart.html

or use these links for downloading
32bit: https://github.com/nodemcu/nodemcu-flasher/blob/master/Win32/Release/ESP8266Flasher.exe?raw=true
64bit: https://github.com/nodemcu/nodemcu-flasher/blob/master/Win64/Release/ESP8266Flasher.exe?raw=true

then download the LuaLoader http://benlo.com/esp8266/LuaLoader.zip

next post is to show how serial data can be exchanged between ESP8266 and any other serial device

best regards

Stefan

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2015-03-21 12:21
    OK so here comes the code that I have tested:

    This is the Lua-script that you save as a plain textfile for uploading into the ESP8266's flash-rom
    -- simple example for receiving serial commands 
    -- this is a small testcode for using with LuaLoader or any other
    -- serial terminal software to show how sending serial data to the ESP826 under the nodeMCU-firmware works:
    
    
    -- setup UART for receiving data
    -- parameters uart.setup( UART-id, baud, databits, parity, stopbits, echo )
    uart.setup(0,9600,8,0,1)
    
    print ("uart.setup(0,9600,8,0,1) finished")
    print ("waiting for serial data....")
    
    -- My opinion: Lua is crazy flexible
    -- You just send the NAME of a function with parameters and Lua knows what do to
    -- Execute the defined function with parameters
    -- example: sending the following string to the ESP makes the code execute function 'cmd_2' 
    -- with parameter '78'    string to send towards ESP "cmd_2(78)"
    
    function cmd_1(value)
      print("cmd_1("..value..") received")
    end
    
    function cmd_2(value)
      print("cmd_2("..value..") received")
    end
    

    So it's up to you to expand this code for better usability and more functionality.
    As I'm a newbee to Lua and also a newbee to the deeper concepts of object-oriented programming
    there may exist better ways to do this serial communication but it is a start.

    You are welcome to improve this serial Lua-example-code or demontrate other ways how to realise serial communication.
    I'm still very impressed by the power of Lua and how compact code can be written in Lua.

    best regards

    Stefan
  • MJBMJB Posts: 1,235
    edited 2015-03-21 13:20
    StefanL38 wrote: »
    I'm still very impressed by the power of Lua and how compact code can be written in Lua.
    Thanks,
    to play with LUA you can download the PC version und experiment in the interactive prompt,
    load little scripts and have fun.

    Being able to install helper scripts in LUA and then sending commands from the Prop (I from Tachyon ;-) - you from SPIN)
    could be a nice boost in functionality.
    -- My opinion: Lua is crazy flexible
    -- You just send the NAME of a function with parameters and Lua knows what do to
    -- Execute the defined function with parameters
    like the interactive FORTH prompt in Tachyon ;-)

    you can even send new function definitions over before you execute them ... like Tachyon ;-)

    That's why I like them both :-)

    but even eLUA is to big for the Propeller - Forth is just right
  • StefanL38StefanL38 Posts: 2,292
    edited 2015-03-21 14:45
    Hi MJB,

    hm this makes me think about learning forth.....

    So could you provide a very basic introduction about the concepts of forth?
    but even eLUA is to big for the Propeller - Forth is just right

    I have asked about how much memory eLua needs. 17kB and a stripped down version 6kB.
    Lua is fast. A lot of microcontroller-tasks are not critical about microsecond-latency.
    So with a XMM-Version you can extend to Megabytes.

    I don't know anything about the c-coding on the propeller. Does there exist a C-variant for the propeller-chip that uses XMM or LMM?
    Lua is written in C. So it should be a limited effort to port Lua on a propellerchip with external memory.

    best regards

    Stefan
  • mindrobotsmindrobots Posts: 6,506
    edited 2015-03-21 16:58
    Stefan,

    Very cool! It looks like you are making progress very quickly.

    I've been looking for my ESP8266 boards today so I can try this at some point. It looks like a lot of fun.

    There is the eLua Project which provides support for a lot of microcontroller boards. It would be interesting to try and fit this on a propeller. Lua and Espruino (Javascript) both have the capability of being able to send a function definition to a remote board and then execute it which makes a very nice way to create "smart" peripherals that can be reprogrammed from a central location. Forth folks have always been able to do this.

    Keep up the great work and keep us posted so we can follow along.
  • MJBMJB Posts: 1,235
    edited 2015-03-21 17:05
    StefanL38 wrote: »
    Hi MJB,

    hm this makes me think about learning forth.....

    So could you provide a very basic introduction about the concepts of forth?
    I actully started with reading the PropForth manual.
    But at that ime Peter started Tachyon so I immediately was in his camp.
    Peter's footer contains a lot of links.
    The OLD forth books are there as well and I did learn a lot reading them.
    Not only about forth.
    Leo Brody: Thinking Forth etc.
    Forth & Zen ;-)
    I have asked about how much memory eLua needs. 17kB and a stripped down version 6kB.
    Lua is fast. A lot of microcontroller-tasks are not critical about microsecond-latency.
    So with a XMM-Version you can extend to Megabytes.

    I don't know anything about the c-coding on the propeller. Does there exist a C-variant for the propeller-chip that uses XMM or LMM?
    Lua is written in C. So it should be a limited effort to port Lua on a propellerchip with external memory.

    best regards

    Stefan
    I am not in C (can read it more or less) so can not help here.
    LUA needs a significant STACK and HEAP and is dynamic with Garbage Collection.
    Sounds quite some overhead.
    But if it would be available I'd give it a try :-)

    Another thing I like about Tachyon is, that I can understand it completely (if I spent the time ;-) and can read the PASM source).
    And there is no additional layer in between like compilers/linkers etc.
    And - runs on the simplest HW - even 32k EEPROM
    (or even without) - just loaded the EXPLORER image onto a DIP Prop without EEPROM
    to do some experiments.
  • Cluso99Cluso99 Posts: 18,069
    edited 2015-03-21 19:00
    Stefan,
    Nice start. Yesterday had some time and read about the various quick starts.

    For those who would rather use Python & Lua there is this link (uses esptool.py and Python 2.7)
    www.taylorcoffelt.com/article/1

    Hoping to try NodeMCU (your benlo.com reference) this afternoon with my PropPlug. Will post results soon ;)
  • Heater.Heater. Posts: 21,230
    edited 2015-03-22 06:31
    StefanL38,
    Does there exist a C-variant for the propeller-chip that uses XMM or LMM?
    Indeed there are a few:

    propgcc - The GCC compiler targeted at the Prop supports LMM, XMM and in COG native code.

    Catalina - From RossH http://forums.parallax.com/showthread.php/116370-Catalina-2.6-a-FREE-C-compiler-for-the-Propeller-The-Final-Frontier! Does not support C++.

    ImageCraft - A commercial C compiler for the Prop. No longer available I think.
    Lua is written in C. So it should be a limited effort to port Lua on a propellerchip with external memory.
    RossH already did this with the Catalina compiler. Lua is featured on that page I linked to above. I'm guessing that code compiles under propgcc as well.
Sign In or Register to comment.