Tuesday, May 23, 2017

Control GPIOs of NodeMCU (ESP8266) with ESP8266 core for Arduino, to read Buttons and write LEDs

This example show how to read input (D5, D6 & D7) from buttons, and write output (D0, D1 & D2) to LEDs accordingly. For the input, all set INPUT_PULLUP to enable internal pull-up resistor, so no external resistors needed.


NodeMCU IO index vs ESP8266 pin
IO index  ESP8266 pin
    0     [*] GPIO16
    1     GPIO5 
    2     GPIO4 
    3     GPIO0
    4     GPIO2
    5     GPIO14  
    6     GPIO12
    7     GPIO13
    8     GPIO15
    9     GPIO3
    10    GPIO1
    11    GPIO9
    12    GPIO10
[*] D0(GPIO16) can only be used as gpio read/write. 
No support for open-drain/interrupt/pwm/i2c/ow.
void setup() {
  pinMode(D0, OUTPUT);
  pinMode(D1, OUTPUT);
  pinMode(D2, OUTPUT);
  pinMode(D5, INPUT_PULLUP);
  pinMode(D6, INPUT_PULLUP);
  pinMode(D7, INPUT_PULLUP);

// the loop function runs over and over again forever
void loop() {
    digitalWrite(D0, LOW);
    digitalWrite(D0, HIGH);

    digitalWrite(D1, LOW);
    digitalWrite(D1, HIGH);

    digitalWrite(D2, LOW);
    digitalWrite(D2, HIGH);


Usage of GPIO:
At the beginning, I want to use D6, D7 and D8 as input. But D8 always return LOW. After googled and found schematic diagram of NodeMCU DevKit v1.0 here: https://github.com/nodemcu/nodemcu-devkit-v1.0/blob/master/NODEMCU_DEVKIT_V1.0.PDF. It's found that GPIO15 (D8) connect to GND via a resistor, so always return LOW.

And MATTERS NEEDING ATTENTION can be found in the schematic diagram:
On every boot/reset/wakeup, GPIO15 MUST keep LOW, GPIO2 MUST keep HIGH. 
When you need to use the sleep mode, GPIO16 and RST should be connected, and GPIO16 will output LOW to reset the system at the time of wakeup.

So, I change using D5.

Monday, May 15, 2017

Nextion Project

This playlist created by ITEAD Studio, with DEMOs of Nextion Display and Nextion Editor.

Nextion NX3224T024 Generic 2.4" TFT 320 x 240 Intelligent LCD Touch Screen Display

Asiawill Nextion NX3224T024 Generic 2.4" TFT 320 x 240 Resolution Intelligent LCD Touch Screen Display

Nextion is a Seamless Human Machine Interface (HMI) solution that provides a control and visualisation interface between a human and a process, machine, application or appliance. It is the best solution to replace the traditional LCD and LED Nixie tube. Nextion includes hardware part (a series of TFT boards) and software part (the Nextion editor). The Nextion TFT board uses only one serial port to communicate. It lets you avoid the hassle of wiring. We notice that most engineers spend much time in application development but get unsatisfactory results. In this situation, Nextion editor has mass components such as button, text, progress bar, slider, instrument panel etc. to enrich your interface design. And the drag-and-drop function ensures that you spend less time in programming, which will reduce 99% of your development workloads. With the help of this WYSIWYG editor, designing a GUI is a piece of cake. It's easy to adapt Nextion family HMI to existing projects, you just need to provide it a UART.


  • Compatible with Raspberry Pi A+, B+ and Raspberry Pi 2
  • RGB 65K true to life colours
  • TFT Screen with integrated 4-wire Resistive Touch Panel
  • Easy 4 pin interface to any TTL Serial Host
  • 4M Flash memory for User Application Code and Data
  • On board micro-SD card for firmware upgrade
  • Visual Area:36.72mm(L)¡Á48.96mm(W)
  • Adjustable Brightness:0~180 nit, the interval of adjustment is 1%
  • 5V90mA power conusmption
  • Display Resolution: 320 * 240
  • Display Interface: Serial
  • Screen Type: Touch Screen
  • Display Controller: No
  • TFT display interface: N/A
  • Display Size: 2.4¡±
  • Expand:
  • SD Card Socket
  • Touch Screen
  • Package include:
  • 1x Nextion 2.4'' display,
  • 1x Wire,
  • 1x Power supply test board
  • Note: there's a small power supply test board and a wire for you to test if the electricity supply is enough or not.