1. Schematic diagram
2. GPIO definition
3. Case 1: Light up the LED
(1) GPIO-related APIs, see the official documentation
(2) API--gpio.mode()
(3) API--gpio.write()
(4) Light up the LED on the module
pin = 4
gpio.mode(pin, gpio.OUTPUT)
gpio.write(pin, gpio.LOW)
4. Case 2: Implement LED flashing
pin=4 -- 4 is D4, GPIO2
flag=1
timer1 = tmr.create()
gpio.mode(pin, gpio.OUTPUT)
gpio.write(pin, gpio.HIGH)
function run_led()
if flag == 1 then
gpio.write(pin, gpio.LOW)
flag = 0
else
gpio.write(pin, gpio.HIGH)
flag = 1
end
end
timer1:alarm(1000, tmr.ALARM_AUTO, run_led)
5. Notes
(1) NodeMCU modules are produced by multiple manufacturers, and the schematics of different manufacturers may be different, so before writing code, you must carefully read the schematic corresponding to the module you have, and do not search online; (I made this mistake, which resulted in the effect not being achieved, and then I was depressed for several hours because of whether there was a problem with the code);
(2) In the GPIO API function, the pin uses the serial number value corresponding to the GPIO. For example, the serial number corresponding to GPIO16 is 0, and the serial number corresponding to GPIO2 is 4.
(3) The API functions in the Chinese documentation of the NodeMCU API obtained online are very different from the API actually used now. It is recommended to check the API directly on the official website;
Previous article:NodeMCU Learning (V)--Timer
Next article:NodeMCU Learning (Part 3)--Working Mode
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Ranking of installed capacity of smart driving suppliers from January to September 2024: Rise of independent manufacturers and strong growth of LiDAR market
- Industry first! Xiaopeng announces P7 car chip crowdfunding is completed: upgraded to Snapdragon 8295, fluency doubled
- P22-009_Butterfly E3106 Cord Board Solution
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- CircuitPython in Space
- Schematic diagram of KeyStone DSP synchronous buck converter with VID function
- Experience sharing on porting ardupilot to ti platform
- "Playing with the Board" + Replaying MicroPython on the STM32F7DISC (2)
- FPGA implementation of sliding average filtering algorithm and LZW compression algorithm
- STM32F407VGTx FSMC and UART5 conflict issue?
- Qorvo has acquired Decawave and Custom MMIC, so powerful!
- EEWORLD University Hall----Statistical Machine Learning
- HMI chip solutions are coming soon
- Forum users' resumption of work survey, friends please help fill out the form~