• Mon 2017.01.30

    Attempting to learn the BTN and LED naming conventions for the ESP8266
    What worked on the Pico causes 'Uncaught ReferenceError' errors when deployed to the ESP8266

    Works on the Pico
    if( digitalRead(BTN) == 1 )

    Uncaught ReferenceError: "BTN" is not defined

    Tried BTN0

    Ultimately trying to read and write data to a pin and toggle on and off, the onboard and offboard LED's on ESP8266

    While this tutorial worked on Pico had the same reference error issue with the LED constants on ESP8266 https://www.espruino.com/Control+LED+wit­h+Button

    Uncaught ReferenceError: "LED1" is not defined

    Tried LED and LED0

    Looked over reference page: http://www.espruino.com/Reference#t_Pin

    Pin class This is the built-in class for Pins, such as D0,D1,LED1, or BTN

    Looking over the ESP8266 tutorial, no references appear to be made here either
    http://www.espruino.com/EspruinoESP8266

    Tried searching the Espruino on ESP8266 forum and I attempted the links below, but with no results

    http://forum.espruino.com/microcosms/925­/
    https://github.com/search?utf8=%E2%9C%93­&q=espruino
    https://github.com/espruino/Espruino/tre­e/master/libs

    Can someone point me to a Espruino reference link that spells out the convention please.

  • ESP8266 is a bit resource strapped and thus not allowing for all Espruino modules and definitions... there is a ESP8266_BOARD.py file that provides the infos to the build, doc and mapping for coding.

  • The esp8266 is a chip, and various different modules are available that may on may not have the LED.

    There is a module called nodemcu that maps the PIN numbers on the nodemcu board to gpio numbers, so that might be useful for you. The flash button is always wired to the same gpio in, so you can use that for testing. This is what is checked on power up to put the chip into flashing mode, so when the board is running you can check the button state.

    Here is an example with a button and a led, and also reading a temperature sensor, so just remove that part of the code:

    http://forum.espruino.com/conversations/­282721/#comment12822865

  • Thr 2017.02.02

    Using the constant names located in ESP8266_BOARD.py link provided by @allObjects, and a snippet plucked from the example provided by @Wilberforce, I was able to r/w a GPIO pin and button input on the specific board I have.

    Thank you both.

    Attempting to explore further using pinMode() produced yet another error:

    Uncaught ReferenceError: "input_pullup" is not defined
     at line 1 col 17
    pinMode(pin_pu, input_pullup);
    

    The spec Expresive datasheet p.14 indicates the ability to configure internal pullup or pulldown. The Espruino Reference page also shows the attribute 'input_pullup'

    Even tried adding module var esp8266 = require('ESP8266'); without success. Is there another module I must add to allow the Pin class functionality to be usable on the ESP8266?

    Robin

  • Hi Robin,

    mode is a string, so use 'input_pullup'

    pinMode(D4, 'input_pullup');
    

    or set input_pullup

    input_pullup = 'input_pullup';
    pinMode(D4, input_pullup);
    
  • What on earth would you expect BTN to refer to? The ESP8266 module doesn't have a button on it!

  • Dev boards like NodeMCU and D1 Mini do. They don't respond as BTN but...

  • Thr 2017.02.02

    Good catch. I must have had a senior moment. That saved me a few hours of hair pulling of whats left. Thank you @MaBe

    I knew I had seen the syntax on this site without the quotes, but I must admit I missed this from the Espruino Reference page

    mode - The mode - a string that is either . . .

    mind stuck in 'why doesn't this argument work now' mode and just didn't get back into gear for the basics. It should have dawned on me to create a variable from the literal to become compiler compliant. nasty accuracy checker. ;-)

    Note: digitalRead/digitalWrite/etc set the pin mode automatically unless pinMode has been called first.

    Now with the syntax corrected, this error pops up for the 'input_pulldown' on the ESP8266

    ERROR: Pin state not supported
    

    This only occurs on pulldown but pullup functions as expected.

    Since I haven't seen documentation detail on 'input_pulldown' for the ESP8266, may I AssUMe that the Espruino Reference documentation is for Espruino boards only; the compiler is accurate and that the ESP8266 module doesn't have this feature available?

  • @DrAzzy,

    What on earth would you expect BTN to refer to? The ESP8266 module doesn't have a button on it!

    Is that a polite way of calling me a D.A. ? I'm staring at my ESP8266 board with two buttons on it, and yes, I'm under the legal limit right now . . . .

  • Hi Robin,

    >pinMode(D5,'input_pulldown');
    ERROR: Pin state not supported
    =undefined
    > 
    

    Yes this causes an error because espressif do not allow this for regular pins.

    check http://bbs.espressif.com/viewtopic.php?f­=5&t=481

  • The modules that most people are using are and

    The ESP-12 is commonly used in other development boards (like NodeMCU boards) that provide additional external components (USB serial on-board, buttons, level shifters, etc) - you must be using one of those.

  • Fri 2017.02.03

    Thank you @MaBe

    That doc pretty much spells it out, doesn't it. I just wish I had the wealth of knowledge, right now, that those of you have, working with these modules. Still trying to run before I've learned to walk. It is of great help that there are those that keep up the support of we new arrivals. Thanks again.

  • Keep on going, your knowledge will grow day by day. Compared to other people posting on this forum I am still a beginner.

    As you are using a ESP board, feel free to donate for Gordons amazing product.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

GPIO Pin BTN LED naming conventions specific to ESP8266

Posted by Avatar for Robin @Robin

Actions