All of the Digital I/O support PWM and interrupts except pin 16 which does not support interrupts. In addition they can be configured to have pull-up or pull-down resistors. Though there are 11 digital I/O pins, 2 are typically reserved for use as the TX/RX lines if serial communications are used which leaves 9 digital I/O for other uses. Some of these 9 pins are connected to the on-board LEDs, but can also be used for other purposes if needed.
PWM range by default is 0-1023 rather than the typical 0-255 found on Arduino. The range can be modified using the command analogWriteRange (255) which sets the range between 0-255.
The PWM frequency is 1kHz by default. Similarly it can be modified using the analogWriteFreq(500) to set the frequency to 500 Hz as one example.
The pins are labeled GPIOx. When using with Arduino IDE, the digital pin number is the samethe pin number, so GPIO2 is referenced as just ‘2’.
The small blue on-board LED is connected to pin 2 (GPIO2).
The on-board general purpose pushbutton on the top board is connected to pin 4 (GPIO4).
The RGB LED is common cathode and so lights when driven HIGH. It is connected to the following pins:
- Pin 15 (GPIO15) = RGB Red LED
- Pin 12 (GPIO12) = RGB Green LED
- Pin13 (GPIO13) = RGB Blue LED
Per spec, the digital I/O is limited to 3.3V, but the mfr has made statements that the digital pins are in fact 5V tolerant and there are many installations using the module directly connected to the logic lines of 5V MCUs, so use your own judgment.
Analog I/O
The analog input A0 (ADC) is a single 10-bit ADC input which is connected to the LDR (Light Dependent Resistor).
The LDR has a dark resistance of about 2.5K and is in series with a 470 ohm resistor to form a voltage divider that feeds the ADC input. The LDR is connected to the Vcc side of the voltage divider and the 470 ohm resistor connects to ground. As the light intensity increases, the LDR resistance decreases and therefore the voltage on the ADC input increases.
By measuring the voltage, the relative brightness of the light falling on the sensor can be determined.
Powering the Module
The module can be powered via the USB port on either the top or bottom board or by using an external 5V power supply connected to the Vcc pin. The top module includes a 3.3V regulator which regulates the 5V down to the 3.3V required by the ESP8266.
The board uses the CH340 chip on the bottom board for USB communications, so the bottom USB must be used for programming or communicating with the module. If you have any issues with connecting to the board, you may need to download a driver for the CH340. Just search for Arduino CH340 driver and you will find a number of sources for drivers depending on what Windows or Mac operating system you are using. The module comes preloaded with the NodeMCU software that accepts the standard AT command set.
It also can be programmed in C using the Arduino IDE and is how the modules are most often used. An example program is shown down below. If a program is download via the IDE, it will overwrite the NodeMCU software or whatever else was loaded before. If that is a problem for what you want to do, the NodeMCU software can always be reloaded. There are many instructions for installing and using ESP8266 based boards with the Arduino IDE, but here is a short-hand version. Note that once the ESP8266 board type is added to the IDE, there will be many more items added to the Tools drop down menu.
- Open Preferences window and enter the following into the ‘Additional Board Manager URLs’ field: “http://arduino.esp8266.com/stable/package_esp8266com_index.json“.
- Under Boards Manager, install ESP8266 by ESP8266 Community.
- Under Tools/Boards select “Adafruit Feather HUZZAH ESP8266“.
- Set Upload Speed to “115200“.
- Select the port that the board is attached to. In my case it happened to be COM3
- In the Serial Monitor window, set comm rate to 115200 and line ending to Both NL & CR
-
LDR Light Sensor on board WS2812 Led on board 3x tactile buttons (1x in the Witty board and 2x in theCH340 board)
-
Supports 3 modes: AP,STA,AP+STA
-
Dimensions: 24mm x 16mm Micro USB connection for power and/or programming