• More play with nodemcu

    Androiders03/02/2015 at 15:51 0 comments

    Got some time today to play more with nodemcu. I thought i would try the gpio module to, you know, turn on a led :)

    I hooked up a led directly to gpio2 pin. And issued the commands (in a connected terminal)



    Nothing happened. This is supposed to set gpio2 to output and set it to a high evel, turning the led on. Or so i thought. I tried with gpio0 as well but to no avail. I didnt really believe my gpio pins were broken so I looked a little bit more at the documentation. And lo and behold, there was a gpio mapping table there :) It turns out gpio2 is mapped to index 4. So:



    did the trick :)

    With nodemcu there is an example .lua script called webap_toggle_pin.lua. It starts a webserver and lets you toggle the logic level of a pin. Awesome!

    A few tweeks of the code:

    pin = 4;
    gpio.mode(pin, gpio.OUTPUT)
        conn:on("receive", function(client,request)
            local buf = "";
            local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP");
            if(method == nil)then 
                _, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP"); 
            local _GET = {}
            if (vars ~= nil)then 
                for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do 
                    _GET[k] = v 
            buf = buf.."<h1> Hello, NodeMcu.</h1><form src=\"/\">Turn PIN <select name=\"pin\" onchange=\"form.submit()\">";
            local _on,_off = "",""
            if(_GET.pin == "ON")then
                  _on = " selected=true";
                  gpio.write(pin, gpio.HIGH);
            elseif(_GET.pin == "OFF")then
                  _off = " selected=\"true\"";
                  gpio.write(pin, gpio.LOW);
            buf = buf.."<option".._on..">ON</opton><option".._off..">OFF</option></select></form>";
    Upload this to the esp and issue restart and dofile. I had som problems at first with running it. It seems that you cant update the same file that is running. So if you want to upload this to main.lua make sure it is not currently running that script. Now, this information might not be 100% correct but making sure of this works for me.

    Now you can get the ip by typing print(wifi.sta.getip()). Then you can just take that ip and put in your browser and control your led :)

  • Trending project :)

    Androiders02/26/2015 at 13:39 0 comments

    I saw this project as a "trending project" on the HAD site. Yay! :)

  • Uploading a .lua file to the esp (nodemcu)

    Androiders02/25/2015 at 12:10 0 comments

    nodemcu is a great firmware, but i need to add programs to it. And I want to make these programs locally and upload them. Lets do that.

    First i wrote a simple program (or actually, someone else wrote the program. I stole it and put it in a file on my computer).

    This is the program

       if string.find(payload,"?myarg=") then
        m="<br/>Value= " .. string.sub(payload,string.find(payload,"?myarg=")+7,string.find(payload,"HTTP")-2)
     conn:send("<h1> Hello, this is Androiders's web page.</h1>How are you today.<br/> Count=" .. mycounter .. m .. "Heap="
    .. node.heap()) 
    conn:on("sent",function(conn) conn:close() end) 
    I saved it to a file called main.lua

    Then i downloaded luatool from here https://github.com/4refr0nt/luatool

    Luatool is a tool to put files on the esp where nodemcu can find them and execute them.

    The script takes a file (defaults to main.lua) and uploads it and stores it with the same name. So simply executeing ./luatool puts a file named main.lua (in the same dir) on the esp.

    After it was done i connected to the serial port again and exectuted node.restart().

    Then, the magic comman, dofile("main.lua") executes the file.

    Since the program was a small webserver it was easy to verify. First i got the ip adress from the esp using print(wifi.sta.getip()), then i entered that ip in the browser. Voila!

    The restart and dofile commands can be set as arguments to the luatool. I will check it out later.

  • Burning nodemcu

    Androiders02/25/2015 at 11:55 0 comments

    I uploaded the nodemcu-firmware bu following this tutorial:


    It was pretty straightforward i must say. git-cloned the repo and burned the pre built binaries using the esptool from espressif package (see here: https://nurdspace.nl/ESP8266/First_setup).

    Then i used cutecom on /dev/ttyUSB0 (9600 baud) and tried it out. Nodemcu has some nice documentation for what modules are installed and can be used.

  • Small update on pin connections...

    Androiders02/23/2015 at 07:28 0 comments

    In my last post i wrote that i had some pins "floating" when i uploaded the new firmware. When i tried to upload nodemcu today that didn't work. So, following the isntructions on this page: http://www.electrodragon.com/w/ESP8266#Pin_Wiring_.28V090.29, I connected GPIO0 to GND and GPIO2 to VCC when booting! Then, after boot, i disconnected GPIO2 (to floating) and uploaded firmware. I dont know if this is something with the blinky example that i hade burned or if i missed something i did the last time i wrote.

    Anyways, it seems to work and it is time to test nodemcu :)

  • Buring firmware

    Androiders02/19/2015 at 07:31 0 comments

    The next step was to burn some custom firmware. I followed the instruction on this site: http://www.esp8266.com/wiki/doku.php?id=toolchain

    After downloading and compiling it (it was automatic and worked great) i tried to burn the blinky example. I connected CH_PD to VCC and GPIO2 and GPIO0 ended up floating. This was the way that worked for me to have the esptool program connect to the esp.

    Next step is to burn the node-mcu firmware and test som Lua action!


    NOTE: se my next log if updating firmware does not work!

  • Starting up

    Androiders02/19/2015 at 07:22 0 comments

    So, I got the esp connected to a usb-serial adapter (pl2303) and used cutecom to send AT commands. It works :)

    At fist i had trouble. I was getting a lot of "noise" on the line. The device was spitting "0x00" all the time. With the correct baud setting i was able to see some clear text messages in between.

    A note on the interwebs led me to the solution: since i am using a sepparate PSU to power the esp i needed to have common ground between the psu and the serial-adapter. A bit of cable connected between them and everything worked lika a charm! :)