Page 1

ESP8266 AND MICROPYTHON D. & A. Ibrahim Prof Dr Dogan Ibrahim has a BSc in electronic engineering, an MSc in automatic control engineering, and a PhD in digital signal processing. Prof Ibrahim is the author of over 60 technical books and over 200 technical articles on microcontrollers, microprocessors, and related fields. Ahmet Ibrahim obtained his BSc degree from the Greenwich University in London. He then completed an MSc course at the same university. Ahmet has worked at many industrial organizations at various levels and is currently working in a large organization in the field of IT.

ESP8266 and MicroPython – Coding Cool Stuff is an introduction to the ESP8266 chip and describes the features of this chip and shows how various firmware and programming languages such as the MicroPython can be uploaded to the chip. The main aim of the book is to teach the readers how to use the MicroPython programming language on ESP8266 based hardware, especially on the NodeMCU. Several interesting and useful projects are given in the book to show how to use the MicroPython in NodeMCU type ESP8266 hardware: •

Project “What shall I wear today?”: You will be developing a weather information system using a NodeMCU development board together with a Text-to-Speech processor module.

Project “The Temperature and Humidity on the Cloud”: You will be developing a system that will get the ambient temperature and humidity using a sensor and then store this data on the cloud so that it can be accessed from anywhere.

Project “Remote Web Based Control”: You will be developing a system that will remotely control two LEDs connected to a NodeMCU development board using an HTTP Web Server application.

ESP8266 AND MICROPYTHON ● D. & A. IBRAHIM

CODING COOL STUFF

CODING COOL STUFF

ESP8266 AND MICROPYTHON

ISBN 978-1-907920-62-2

www.elektor.com

LEARN DESIGN

Elektor International Media BV

Dogan Ibrahim & Ahmet Ibrahim LEARN DESIGN SHARE

SHARE

LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIG ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● S GN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DES ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● S


Content About the Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 PREFACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 CHAPTER 1 • ESP8266 PROCESSORS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 1.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 1.2 The ESP-01 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 1.3 The ESP-02 to ESP-14 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 1.4 Using The ESP-01 in Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 1.5 Other Boards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 1.5.1 The NodeMCU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 1.5.2 SparkFun ESP8266 Thing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 1.5.3 Olimex ESP8266-EVB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 1.5.4 Adafruit Huzzah ESP8266 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 1.5.5 HiLetgo D1 Mini NodeMCU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 1.5.6 In-Circuit ESP-ADC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 1.5.7 mikroElektronika WiFi ESP Click . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 1.6 Which Board ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 1.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 CHAPTER 2 • ESP8266 SOFTWARE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 2.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 2.2 The ESP8266 with AT Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 2.2.1 The Hardware Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 2.2.2 The Software Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 2.2.3 The AT Command Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 2.3 Upgrading the AT Command Processor Firmware . . . . . . . . . . . . . . . . . . . . . . . . 36 2.4 Loading the NodeMCU Firmware – The NodeMCU Flasher . . . . . . . . . . . . . . . . . . 41 2.5 NodeMCU Custom Build . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 2.6 The ESPlorer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 2.7 Loading MicroPython to ESP8266 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 2.8 Using the REPL in MicroPython . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 2.9 ESP8266 Project Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 2.9.1 ESP8266 As a Wi-Fi Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

●5

ESP8266 UK 170601.indd 5

09-06-17 12:04


ESP8266 and Micropython - Coding cool stuff 2.9.2 ESP8266 As a Standalone Microcontroller . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 2.10 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 CHAPTER 3 • USING THE MicroPython ON NodeMCU . . . . . . . . . . . . . . . . . . . . . . . 61 3.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 3.2 Variable Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 3.3 Reserved Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 3.3 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 3.4 Indentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 3.5 Line Continuation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 3.6 Blank Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 3.7 Multiple Statements on a Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 3.8 MicroPython Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 3.8.1 Numeric Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 3.8.2 String Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 3.8.3 List Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 3.8.4 Tuple Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 3.8.5 Dictionary Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 3.9 MicroPython Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 3.9.1 Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 3.9.2 Comparison Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 3.9.3 Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 3.9.4 Assignment Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 3.9.5 Bitwise Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 3.10 Control of Program Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 3.10.1 if, if..else, elif . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 3.10.2 for Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 3.10.3 while Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 3.10.4 continue Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 3.10.5 break Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 3.11 Trigonometric Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 3.12 Number Type Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

â—?6

ESP8266 UK 170601.indd 6

09-06-17 12:04


Inhalt 3.13 Mathematical Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 3.14 Using Non-printable ASCII Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 3.15 Print Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 3.16 String Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 3.17 List Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 3.18 Dictionary Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 3.19 Date and Time Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 3.20 User Defined Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 3.21 Keyboard Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 3.22 Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 3.23 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 3.24 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 CHAPTER 4 • Creating Programs and Uploading to the NodeMCU . . . . . . . . . . . . . 87 4.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 4.2 Using the ampy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 4.2.1 Using ampy - Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 4.2.2 Creating and Running a Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 4.2.3 Running the Program at Boot Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 4.3 Program Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 4.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 CHAPTER 5 • MicroPython HARDWARE LIBRARIES . . . . . . . . . . . . . . . . . . . . . . . 100 5.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 5.2 machine Library Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 5.3 machine Library Module Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 5.3.1 Pin Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 5.3.2 ADC Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 5.3.3 PWM Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 5.3.4 Timer Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 5.3.5 RTC Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 5.3.6 UART Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 5.3.7 DH11 Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123

●7

ESP8266 UK 170601.indd 7

09-06-17 12:04


ESP8266 and Micropython - Coding cool stuff 5.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 CHAPTER 6 • MicroPython Wi-Fi PROGRAMMING ON ESP8266 . . . . . . . . . . . . . . 128 6.1 Overviews . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 6.2 Connecting to a Wi-Fi Router – The network Library . . . . . . . . . . . . . . . . . . . . . 128 6.3 Using the Socket Library – UDP and TCP/IP Packets . . . . . . . . . . . . . . . . . . . . . 129 6.3.1 UDP Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 6.3.2 TCP/IP Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 6.4 Connecting to the Internet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 6.5 Using the WebREPL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 6.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 CHAPTER 7 • PROJECT – WHAT SHALL I WEAR TODAY ? . . . . . . . . . . . . . . . . . . . 140 7.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 7.2 The Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 7.2.1 The NodeMCU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 7.2.2 The EMIC2 Text-to-Speech Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 7.2.3 The Power Supply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 7.2.4 The Circuit Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 7.3 Testing the Hardware Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 7.4 The MicroPython Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 7.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 CHAPTER 8 • PROJECT – THE TEMPERATURE AND HUMIDITY ON THE CLOUD . . . 157 8.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 8.2 The Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 8.3 Reading the Temperature and Humidity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 8.4 The Cloud . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 8.5 Micropython Program Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 8.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 CHAPTER 9 • PROJECT – REMOTE WEB BASED CONTROL . . . . . . . . . . . . . . . . . . . 164 9.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 9.2 The Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 9.3 HTTP Web Server/Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165

●8

ESP8266 UK 170601.indd 8

09-06-17 12:04


9.4 MicroPython Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 9.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 APPENDIX A • THE SPI BUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 A.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 A.2 THE SPI BUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 A.3 MicroPython SPI BUS COMMANDS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 A.3.1 Software Implemented SPI Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 A.3.2 Hardware Implemented SPI Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 A.4 EXAMPLE PROJECT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 A.4.1 Controlling the BarGraph Click Board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 A.4.2 The Temperature Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 A.4.3 The MicroPython Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 APPENDIX B • THE I2C BUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 B.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 B.2 THE I2C BUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 B.3 MicroPython I2C BUS COMMANDS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 B.4 EXAMPLE PROJECT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 B.4.1 The Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 B.4.2 MicroPython Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 APPENDIX C • THE Node-RED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193

●9

ESP8266 UK 170601.indd 9

09-06-17 12:04


PREFACE

PREFACE Wi-Fi (or WiFi) is a local area network technology based on the IEEE 802.11 standards that enables various devices to be interconnected wirelessly to each other. Devices that commonly use the Wi-Fi technology include personal computers, smart mobile phones, tablet computers, modern printers, digital cameras, video-game consoles, etc. Devices on a Wi-Fi network are connected to each other using an Access Point (AP). Most homes, work places, government offices, train stations, restaurants and many other public places in developed countries are equipped with Wi-Fi APs, enabling the general public to connect to and use for the Internet, or check their mails while they are on the move. A home AP has a typical range of 20 metres indoors, but repeaters can be used to extend this range if desired. Wi-Fi commonly uses the 2.4 GHz UHF frequency band and may be subject to interference from some home appliances such as microwave ovens. To connect a device to a Wi-Fi AP, a processor is required with a wireless network interface controller (NIC) hardware. Laptop computers and smartphones are usually equipped with NICs and they can easily be connected to a local Wi-Fi. All that is required is the knowledge of the Wi-Fi name (SSID name) and the Wi-Fi password. The connected devices can access all resources of the Internet including sending and receiving mail, using Facebook and Twitter, and so on. Desktop computers do not usually have built-in NICs, but external NICs are available in the form of flash devices that can be connected to the USB port of a PC and can communicate with the local APs. Microcontrollers are usually used in domestic, commercial, and industrial monitoring and control applications. There are many applications where one might want to connect a microcontroller based system to a local Wi-Fi so that a plant, a piece of equipment, or a switch can be monitored or controlled remotely. In general, external hardware in the form of NICs can be connected to microcontrollers so that they can communicate with APs. In the past, such NIC hardware used to be bulky and expensive and used to consume high currents, requiring large power supplies. Recently, the development of a tiny chip called the ESP8266 has made it possible to interface any type of microcontroller to a Wi-Fi AP. The ESP8266 is a low-cost tiny Wi-Fi chip having fully built-in TCP/IP stack and a 32-bit microcontroller unit. This chip, produced by Shanghai based Chinese manufacturer Espressif System, is IEEE 802.11 b/g/n Wi-Fi compatible with on-chip program and data memory, and general purpose input-output ports. Several manufacturers have incorporated the ESP8266 chip in their hardware products (e.g. ESP-xx, NodeMCU etc) and offer these products as a means of connecting a microcontroller system such as the Android, PIC microcontroller or others to a Wi-Fi. The ESP8266 is a low-power chip and costs only a few Dollars. This book is an introduction to the ESP8266 chip and describes the features of this chip and shows how various firmware and programming languages such as the MicroPython can be uploaded to the chip. The main aim of the book is to teach the reader how to use the MicroPython programming language on ESP8266 based hardware, especially on the

â—? 11

ESP8266 UK 170601.indd 11

09-06-17 12:04


CHAPTER 1 • ESP8266 PROCESSORS

CHAPTER 1 • ESP8266 PROCESSORS 1.1 Overview

The ESP8266 is a low-cost Wi-Fi chip that can be used with or without a microcontroller to access a Wi-Fi network. The chip has been developed by Shanghai based Chinese manufacturer Espressif Systems and incorporates full TCP/IP stack. It can be used as a small microcontroller on its own, or it can be interfaced to a bigger microcontroller development system such as the Arduino where it can be used to provide Wi-Fi capability to the host system. There are many versions of the ESP8266 chip, available as modules on small boards with different functionalities and different input/output capacities. The basic specifications of the ESP8266 chip are summarized below: • 32-bit RISC CPU: Tensilica Xtensa LX106 • Operation speed 80 to 160 MHz (by overclocking) • 3.3V operation (+2.5V min to +3.6V max) • 64 Kbytes program memory, 96 Kbytes data memory • External QSPI flash memory (up to 16 Mbytes) • IEEE 802.11 b/g/n Wi-Fi support • WEP or WPA/WPA2 authentication (or, open network) • 1 x 10-bit analog-to-digital (ADC) converter • Up to 16 GPIOs (not +5V tolerant) • Shared SDIO, SPI, I2C, I2S interface pins • Integrated TCP/IP protocol stack • UART on dedicated pins (additional TX only UART on GPIO2 pin) • Standby power < 10 mW The hardware details of some of the popular ESP8266 modules are described in this chapter. 1.2 The ESP-01

The first version of the chip was manufactured by AI-Thinker and it was supplied on a small board as a module and was named the ESP-01. As shown in Figure 1.1, this is a small module measuring 14.3mm x 24.8mm, proving a 2xDIL connector with 8 pins (6 active pins, power pin, and ground pin), and an on-board PCB trace antenna, with LEDs to indicate voltage and data transfer.

● 13

ESP8266 UK 170601.indd 13

09-06-17 12:04


ESP8266 and Micropython - Coding cool stuff

Figure 1.1 The ESP-01 module Figure 1.2 shows the pin configuration of the ESP-01 module, having the following pin definitions: Vcc: GND: RX: TX: GPIO0: GPIO2: Reset: CE:

+3.3 V power supply Ground pin UART receive pin UART transmit pin I/O pin 0 I/O pin 2 Reset pin Chip enable pin

Figure 1.2 Pin configuration of ESP-01 It is important to notice that the chip operates with +3.3V external power supply and all its inputs and outputs are compatible with +3.3V. Care must be taken not to connect +5V supply to the chip as the chip can easily be damaged voltages higher than +3.3V. +5V power supplies are usually available in most applications. If 3.3V power supply is not readily available it is possible to use a +5V to +3.3V voltage regulator module, or to use a voltage regulator chip, or a resistor divider network to generate +3.3V from +5V, or using series diodes, or a pair of AA batteries. All these options are described below.

â&#x2014;? 14

ESP8266 UK 170601.indd 14

09-06-17 12:04


ESP8266 and Micropython - Coding cool stuff

CHAPTER 2 • ESP8266 SOFTWARE 2.1 Overview

The ESP8266 chip can be loaded with the firmware so that it can be programmed using one of the following programming languages: • AT commands • Lua (Using the NodeMCU firmware) • C++ (via Arduino IDE) • microPython AT commands were developed to send commands to modems and similar communications equipment to configure them, and to send and receive data. Firmware can be uploaded to the ESP8266 chip so that it can accept AT commands. Lua is a powerful, efficient, lightweight, embeddable high-level free scripting language which supports object-oriented, procedural, as well as data-driven programming. Lua is an interpretive language, making it ideal for rapid learning and prototyping. C++ is an object-oriented powerful high-level language used mainly in large applications on laptops and desktop computers. Programming using the C++ is beyond the scope of this book and there are many books, tutorials, and notes on the Internet on this topic. Interested readers are recommended to search the Internet for information. microPython is a subset of the powerful high-level language Python. It is used in almost all universities around the wold in introductory programming courses and it is available on most microcontroller based systems. Using microPython with the ESP8266 board is the main aim of this book. In this Chapter we will be briefly looking at how to load the firmware so that we can use our ESP8266 board to program using AT commands, Lua, and microPython. The details of microPython will be given in the next Chapter with examples. 2.2 The ESP8266 with AT Commands

The ESP-01 is by default loaded with a firmware that can recognize AT commands for Wi-Fi based operations. The firmware in your device may be out of date and may need upgrading. The uploading process is normally done using a PC. In this section we shall look at the steps to upload new firmware to our ESP-01. 2.2.1 The Hardware Setup

Before using the ESP-01 for normal operation or for uploading a new firmware, we need to connect the device to the USB port of our PC using a USB-to-TTL adapter as shown in the previous Chapter in Figure 1.10. Figure 2.1 shows the required circuit diagram again but this time in pictorial format. Push-button RESET is used to reset the device. Similarly, push-button UPLOAD/NORMAL is used to select normal operation or to upload new software to the device. Notice that you may need to connect external +3.3V power supply (e.g. 2 x

● 26

ESP8266 UK 170601.indd 26

09-06-17 12:04


CHAPTER 2 â&#x20AC;˘ ESP8266 SOFTWARE

AA batteries) to power the ESP-01 especially while using the Wi-Fi.

Figure 2.1 Minimum setup to use the ESP-01 Perhaps the easiest setup is to build the circuit on a standard breadboard. Note that the ESP-01 is not breadboard compatible since its pins are very close to each other and you will need an adapter to connect the ESP-01 to a breadboard. A suitable adapter for the ESP-01 can be purchased from the following site:

www.diymalls.com

Figure 2.2 and Figure 2.3 show the top and side views of the circuit built on a breadboard. Note that the USB-to-TTL adapter is mounted vertically. The circuit is powered from 2 x AA type alkaline batteries.

Figure 2.2 Top view of the circuit

â&#x2014;? 27

ESP8266 UK 170601.indd 27

09-06-17 12:04


ESP8266 and Micropython - Coding cool stuff

Figure 2.14 Section download of the readme file • Connect your ESP-01 as in Figure 2.1 and start the Flash Download Tool and select the ESP8266 processor. Set the COM port parameters as before in this example, COM36 with baud rate 115200). • Press and hold the RESET button and then press and hold the UPLOAD/NORMAL button on the ESP-01. Release the RESET button, and Click the START button on the ESP Flash Download tool on the PC. You should see a screen similar to the one shown in Figure 2.15 which detects and shows the specifications of the board. Note the flash memory size listed in the DETECTED INFO window. In this example the flash memory size is 8Mbit, and the crystal speed is 26MHz.

Figure 2-15 Start the Flash Download Tool

● 38

ESP8266 UK 170601.indd 38

09-06-17 12:04


CHAPTER 2 • ESP8266 SOFTWARE

• The firmware is broken down into several files (3 normally) and these files need to be provided to the ESP Flash Download tool, together with the corresponding addresses found in the readme file. The files are listed in the NON-BOOT section of the file and they are (the folder and sub-folder names may be different on your PC): eagle.flash.bin  in sub-folder ESP8266-AT-Upgrade\ESP8266_NONOS_ SDK\bin\at\noboot eagle.irom0text.bin  in sub-folder ESP8266-AT-Upgrade\ESP8266_NONOS_ SDK\bin\at\noboot blank.bin  in sub-folder ESP8266-AT-Upgrade\ESP8266_NONOS_ SDK\bin • Fill in the file paths and addresses (offsets). Notice that file blank.bin appears twice with 2 different offsets. After filling in the paths and addresses you should have a screen similar to the one shown in Figure 2.16. The paths and addresses are shown in detail in Figure 2.17.

Figure 2.16 Form filled with paths and addresses

● 39

ESP8266 UK 170601.indd 39

09-06-17 12:04


CHAPTER 2 • ESP8266 SOFTWARE

• Save the file in a sub-folder. In this example it is saved in sub-folder called ESP8266-MicroPython and the file name is ESP8266-20170108-v1.8.7.bin (see Figure 2.45)

Figure 2.45 Latest firmware file saved in a sub-folder • Now we will load the esptool which is a software tool used to download firmware to ESP8266 processors. Continue with the following steps: • While your command line is open, go to the root directory by entering CD\ • Enter the following command to install the esptool on your PC (see Figure 2.46). You should see the message Successfully installed esptool at the end of the installation.

C:> pip install esptool

Figure 2.46 Installing the esptool • It is recommended to erase the entire flash memory of the ESP8266 before uploading new firmware. To do this, connect the NodeMCU to the PC using the mini USB cable. Find out the serial port number where the NodeMCU is connected to (see Figure 2.4) and enter the following command. In this example it is assumed that the NodeMCU is connected to serial port COM2. Figure 2.47 shows the command being executed to erase the flash memory. The erasure processes should take about 10 seconds. C:> esptool.py --port COM2 erase_flash or, C:> python c:\python27\lib\site-packages\esptool.py --port COM2 erase_ flash

Figure 2.47 Erase the entire flash memory of the ESP8266

● 55

ESP8266 UK 170601.indd 55

09-06-17 12:04


ESP8266 and Micropython - Coding cool stuff

• We are now ready to upload the MicroPython firmware to our NodeMCU development board. Make sure that the NodeMCU is still connected to the USB port and enter the following command (see Figure 2.48). The flash memory size will be detected automatically (32Mbit = 4MByte in this example) and the MicroPython firmware will be uploaded to the NodeMCU: C:> esptool.py --port COM2 --baud 460800 write_flash --flash_size=detect 0 c:\ESP8266-MicroPython\ESP8266-20170108-v1.8.7.bin or, C:> python c:\python27\lib\site-packages\esptool.py --port COM2 --baud  460800 write_flash –flash_size=detect 0 C:\ESP8266-MicroPython\ ESP8266-20170108-v1.8.7.bin

Figure 2.48 Uploading the MicroPython firmware • Once the uploading is finished, press the RESET button and the NodeMCU is now ready to be used for MicroPython applications. 2.8 Using the REPL in MicroPython

The REPL (Read-Evaluate-Print-Loop) enables interactive commands (statements) to be entered on a terminal emulator window to send commands to MicroPython. REPL is useful especially while learning MicroPython as the user can experiment and learn the MicroPython statements. REPL is used over a terminal emulator window such as the PUTTY or HyperTerm. Before using the REPL you should connect the NodeMCU module to the PC and find the assigned serial port number (see Figure 2.4). In this section, the HyperTerm is used as the terminal emulator. The steps to use the REPL are given below: • Connect the NodeMCU to the PC and find the assigned serial port number (COM45 in this example) • Start the HyperTerm terminal emulator and give a name to the connection (e.g. MicroPython). Select the serial port as shown in Figure 2.49

● 56

ESP8266 UK 170601.indd 56

09-06-17 12:04


CHAPTER 3 • USING THE MicroPython ON NodeMCU

CHAPTER 3 • USING THE MicroPython ON NodeMCU 3.1 Overview

Python is an interpreted, interactive and object oriented high-level programming language, first developed by Guido Rossum in the 1980s at the National Research Institute for Mathematics and Computer Science in the Netherlands. Python is derived from many other languages, including C, C++, Modula-3, SmallTalk, and Unix shell. The language is now maintained by a team of people at the Institute. MicroPython is a subset of Python and has been developed mainly for the embedded processors such as the PIC, Arduino, ARM and others. MicroPython includes most of the features of its big brother Python, including many of its built-in libraries. The features described in this section apply to both Python and to MicroPython. Python has become one of the most popular languages and is used at most colleges and universities as the first programming language since it is easy to learn and easy to maintain. Python is interactive which means that you can issue a command and see the result immediately without having to compile or upload the command to the Python processor. This feature of Python is extremely useful while teaching this programming language. Python is also an interpreted language, thus requiring no pre-compilation before it is run. Python supports a large library of functions which is perhaps one of its biggest advantages that differentiates it from the other programming languages. MicroPython supports many library functions, making it easier to develop embedded programs for various interface devices. In this Chapter we shall be looking at the details of the MicroPython programming language and shall see how we can write programs using this language. We shall be using the interactive interface (REPL) to MicroPython so that we can see the results of various programming statements immediately. We shall be using the NodeMCU development board which has been loaded with the MicroPython firmware in Chapter 2. This Chapter is organized like a tutorial and is aimed at beginners of the MicroPython programming language. It is assumed that the readers have some practical knowledge of a high-level programming language. You should connect the NodeMCU to your PC and run a terminal emulation software to communicate with the MicroPython firmware. The HyperTerm terminal emulator (see Chapter 2.8) is used in this Chapter 3.2 Variable Names

Like most other programming languages, MicroPython variable names are case sensitive and can begin with a letter A to Z or a to z, or an underscore character “_”, followed by letters or numbers 0 to 9. However, it is not permissible to start a variable name with a number. Examples of some valid and invalid variable names are given below: Count - valid Total - valid

● 61

ESP8266 UK 170601.indd 61

09-06-17 12:04


ESP8266 and Micropython - Coding cool stuff

_sum 9Cnt ÂŁ100 %total Count1 My_Name @loop -

valid invalid invalid invalid valid valid invalid

Note that because MicroPython is case sensitive, variables such as COUNT, COUNt, COUnt, Count, and count are all different. 3.3 Reserved Words

Some names are reserved for use by MicroPython and must not be used as variable names in our programs. A list of reserved names is given below. Notice that all the reserved names consist of lower case letters. and for raise assert from return break global try class if while continue import with def in yield del is elif lambda else not except or exec pass finally print 3.3 Comments

Comment lines in MicroPython start with the # character. All the characters after the # character are ignored by the MicroPython interpreter. Comments can either be at the beginning of a line or after a statement. Some example comment lines are shown below:

# This is a MicroPython comment line cnt = 10 # Initialize variable cnt to 10

3.4 Indentation

In most programming languages blocks of code are identified by using braces at the beginning and end of the block, or by identifying the end of a block with keywords such as END, WEND, or ENDIF. In the MicroPython language there are no braces or statements to indicate the beginning or end of a block of code. Instead, blocks of code are identified by indentation. All the statements in a block of code must be indented by the same amount. The actual number of spaces used for the indentation is not important as long as all the statements that belong to the same block are indented by the same amount. Some examples are given below:

â&#x2014;? 62

ESP8266 UK 170601.indd 62

09-06-17 12:04


CHAPTER 4 • Creating Programs and Uploading to the NodeMCU

CHAPTER 4 • Creating Programs and Uploading to the NodeMCU 4.1 Overview

In the last Chapters we have seen the details of the MicroPython programming language and have also seen how to use the MicroPython interpreter interactively. Interactive programming is useful when we want to test parts of a program code or a statement. In this Chapter we shall look at how to write complete MicroPython programs and upload them to our NodeMCU development board. Simple programming examples will be given in the Chapter. 4.2 Using the ampy

ampy (Adafruit MicroPython Tool) is a software utility that can be used to serially interact with an ESP8266 board loaded with the MicroPython. Ampy is a simple command line based tool that can be used to perform the following operations on our MicroPython board (the NodeMCU board): • List contents of a directory on the MicroPython board (command: ls) • Create a folder on the MicroPython board (command: mkdir) • Retrieve a file from the MicroPython board (command: get) • Send a file from the PC to the MicroPython board (command: put) • Remove a folder and its contents from the MicroPython board • Run a script on the PC and print its output (command: run) • Perform reset of the board (command: reset) Ampy should be installed on the PC before it can be used. This requires Python 2.7.x or 3.x to be already installed on our PC. In this section we are assuming that Python 2.7 has already been installed on our PC (see section 2.7). To install ampy, enter the following command from the command line on your PC (see Figure 4.1):

C:\> cd python27\scripts

C:\ Python27\Scripts> pip install adafruit-ampy

Figure 4.1 Installing ampy

● 87

ESP8266 UK 170601.indd 87

09-06-17 12:05


ESP8266 and Micropython - Coding cool stuff

You can whether or not ampy has been installed successfully by entering the following command (see Figure 4.2):

C:\Python27\Scripts> ampy --help

Figure 4.2 ampy help command 4.2.1 Using ampy - Example

An example of using ampy is given below. Before using these commands you should connect your NodeMCU development board to the PC and find out the serial port number assigned to your board. An example is given in Figure 4.3 which lists the files on the MicroPython board:

C:\Python27\Scripts> ampy --port COM2 ls

Figure 4.3 Listing files on the board 4.2.2 Creating and Running a Program

Using ampy we can run a MicroPython program on our MicroPython board. The program can be created using our favourite text editor such as the Notepad (or even ESPlorer). An example program created using the Notepad is shown in Figure 4.4. The program is named sinetable.py and is saved in sub-folder C:\Python\Scripts folder. This program displays the trigonometric sines of angles from 0 degrees to 90 degrees in steps of 5 degrees.

â&#x2014;? 88

ESP8266 UK 170601.indd 88

09-06-17 12:05


ESP8266 and Micropython - Coding cool stuff

CHAPTER 5 â&#x20AC;˘ MicroPython HARDWARE LIBRARIES 5.1 Overview

In the last Chapters we have seen how to write a MicroPython program and then how to run this program on the NodeMCU development board which was uploaded with the MicroPython firmware. In addition, several MicroPython programming examples were given to show how various features of MicroPython can be used in programs In this Chapter we shall be looking at the modules of hardware specific MicroPython libraries that can be used in our MicroPython projects. 5.2 machine Library Module

The machine library module contains hardware related MicroPython functions. Some of the commonly used functions in this module are: machine.reset(): resets the device as if the RESET button is pressed machine.reset.cause(): returns the cause of the reset. The following constants are available: machine.PWRON.RESET machine.HARD_RESET machine.WDT_RESET machine.DEEPSLEEP_RESET machine.SOFT_RESET machine.enable_irq(state): Re-enable interrupt requests. State is the value returned from the last call to disable_irq. machine.disable_irq(): Disable interrupt requests machine.freq(): returns the CPU frequency (in Hz) machine.sleep(): Stops the CPU and disables all peripherals except for WLAN. Wake sources must be configured for wake up. machine.unique_id(): returns a byte string with a unique identifier of the board in use. 5.3 machine Library Module Classes

Some of the commonly used classes supported by the machine library are: Pin: ADC: PWM: I2C:

input-output pins class analog to Digital converter class pulse-width-modulated output I2C protocol class

â&#x2014;? 100

ESP8266 UK 170601.indd 100

09-06-17 12:05


CHAPTER 5 â&#x20AC;˘ MicroPython HARDWARE LIBRARIES

RTC: SD: SPI: Timer: UART: WDT: DH11:

real time clock class secure digital card class SPI protocol class internal timers class serial UART class watchdog timer class DHT11 temperature and humidity class

We will now look at the details of some of the important classes. 5.3.1 Pin Class

The pin object is used to control the general purpose I/O pins (or GPIOs). The pin class has the general format (only the first two parameters are mandatory, the others are optional):

machine.Pin(id, mode, pull, value, drive, alt)

id: can be an integer pin number or a string pin name mode: specifies the pin mode. Commonly used modes are:

Pin.IN: Pin.OUT:

pin is configured for input pin is configured for output

pull: specifies if the pin should have a pull-up resistor. Available options are:

Pin.None: Pin.PULL_UP: Pin.PULL_DOWN:

no pull up or down resistor Pull up resistor enables Pull down resistor enables

value: valid for Pin.OUT and specifies the initial pin state drive: specifies the output power (current driving capability) of the pin. Available options are: Pin.LOW_POWER Pin.MED_POWER Pin.HIGH_POWER alt: specifies an alternate function for the pin. The following commonly used methods are available: Pin.value([x]): allows to set and get the value of the pin. If the pin is configured as an input pin (argument x is omitted) then this method gets the digital value of

â&#x2014;? 101

ESP8266 UK 170601.indd 101

09-06-17 12:05


CHAPTER 5 â&#x20AC;˘ MicroPython HARDWARE LIBRARIES

5.3.3 PWM Class

PWM waveforms are used in various control applications where it is required to change the level of the analog voltage applied to an external device. Figure 5.18 shows a typical PWM waveform which is basically a positive square wave with ON and OFF times. The ON and OFF times are also called MARK and SPACE respectively. The period of the waveform is the sum of the ON and OFF times. The duty of a PWM waveform is an important parameter and it is defined as the ratio of the ON time to the period. i.e.

duty cycle = ON time / (ON time + OFF time)

The duty cycle si usually quoted as a percentage. Thus, 0% corresponds to no ON time, and 100% corresponds to no OFF time.

Figure 5.18 Typical PWM waveform The PWM waveform can be enabled on all pins except Pin 16. The PWM frequency can be set to anything in the range 1 to 1000Hz, and the duty cycle can be set from 0 (0%) to 1023 (100%). The following methods are supported by the PWM class; PWM(Pin(n)): create PWM object on pin n pwm.freq(): get the current PWM frequency pwm.freq(n): set the PWM frequency to n pwm.duty(): get the current PWM duty cycle pwm.duty(n): set the PWM duty cycle pwm.deinit(): disable PWM An example is given below to show how the PWM class can be used in programs. Example 5.5 Write a program to generate a PWM waveform on pin GPIO0 (D3) of the NodeMCU board. The frequency and duty cycle of the waveform should be 500Hz and 50% respectively. Show the generated waveform on an oscilloscope. Solution 5.5 The required program is shown in Figure 5.19 (program pwm.py). The program generates a PWM waveform with frequency 500Hz and 50% duty cycle on pin GPIO0.

â&#x2014;? 115

ESP8266 UK 170601.indd 115

09-06-17 12:05


ESP8266 and Micropython - Coding cool stuff

#-------------------------------------------------------------# # #

PWM WAVEFORM ============

# # This program generates a PWM waveform on pin GPIO0 of the # NodeMCU development board. The freuquency and duty cycle of # the generated waveform is 500Hz and 50% respctively. # # # # Program :

PWM.py

# Date

April, 2017

:

# Programmer: Dogan Ibrahim #--------------------------------------------------------------from machine import Pin, PWM duty_cycle = 50 duty = int(duty_cycle * 1023 / 100) pwm0 = PWM(Pin(0)) pwm0.freq(500) pwm0.duty(duty)

Figure 5.19 Program listing for the Example 5.5 Figure 5.20 shows the program run interactively using a terminal emulator software.

Figure 5.20 Running the program interactively The generated PWM waveform is shown on an oscilloscope in Figure 5.21 using the PCSGU250 Velleman PC based oscilloscope. As shown in the Figure, the frequency is 500Hz and the duty cycle is 50%.

â&#x2014;? 116

ESP8266 UK 170601.indd 116

09-06-17 12:05


CHAPTER 5 • MicroPython HARDWARE LIBRARIES

Figure 5.29 The circuit on a breadboard and the LCD display 5.3.7 DH11 Class

The DH11 class is used with the DHT11/22 temperature and humidity sensor chips. In this project a DHT11 chip is used to measure and display the ambient temperature and humidity. The DHT11 is less accurate than the DHT22 and works in a smaller range, but is cheaper. The following methods are available with the DH11 class: temperature(): returns the temperature in ºC humidity(): returns the humidity as a percentage DHT11 is a 4-pin digital output device (only 3 pins are used) as shown in Figure 5.30, having pins +V, GND, and Data. The Data pin must be pulled-up to +V through a 10K resistor. The chip uses capacitive humidity sensor and a thermistor to measure the ambient temperature. Data output is available from the chip around every second. The basic features of DHT11 are: • 3 to 5V operation • 2.5mA current consumption (during a conversion) • Temperature reading in the range 0-50ºC with an accuracy of ±2ºC • Humidity reading in the range 20-80% with 5% accuracy • Breadboard compatible with 0.1 inch pin spacings

● 123

ESP8266 UK 170601.indd 123

09-06-17 12:05


ESP8266 and Micropython - Coding cool stuff

Figure 5.30 The standard DHT11 sensor chip An example is given below to show how the DHT11 can be used in a project. Example 5.9 In this example the DHT11 module with built-in 10K pull-up resistor, available from Elektor, is used. This is a 3-pin device with the pin layout as shown in Figure 5.31.

Figure 5.31 Elektor DHT11 module Figure 5.32 shows the circuit diagram of the project. Here, the Data output of the DHT11 is connected to pin GPIO0 (D3) of the NodeMCU. The circuit, built on a breadboard is shown in Figure 5.33.

â&#x2014;? 124

ESP8266 UK 170601.indd 124

09-06-17 12:05


ESP8266 and Micropython - Coding cool stuff

CHAPTER 6 • MicroPython Wi-Fi PROGRAMMING ON ESP8266 6.1 Overviews

In the last Chapter we had a look at the MicroPython hardware related functions and have seen how to use some of these functions in controlling the ESP8266 chip based processors. In this Chapter we shall be looking at how to configure the NodeMCU development board using the MicroPython programming language so that we can do network programming and communicate with other nodes on a network via the TCP/IP or the UDP protocols. 6.2 Connecting to a Wi-Fi Router – The network Library

Before communicating with other nodes on a network we first have to establish ourselves as a node on the network and have an IP address assigned to us. The MicroPython library called network provides network related functions such as connecting to a network, finding the IP address and so on. This library must be imported into our MicroPython programs before we can use the network functions. The network library has a class called WLAN. Some of the commonly used methods of this class are: network.WLAN(network.STA_IF): c reates a WLAN network object to connect to a Wi-Fi network.WLAN(network.AP_IF): creates a WLAN network object to connect to an AP, allowing other Wi-Fi clients to connect active(True): activates the network interface active(False): deactivates the network interface connect(“ssid”, “password”): connects to the specified Wi-Fi network disconnect(): disconnect from the currently connected network isconnected(): used to find out if we are connected to a Wi-Fi ifconfig(): returns the IP address assigned to our connection An example is shown in Figure 6.1 using interactive command mode which establishes connection to a Wi-Fi network by specifying the ssid (in this example BTHub5-6SPN) and password (in this example af4b5e6243), and then displays the assigned IP address which happens to be 192.168.1.145.

Figure 6.1 Connecting to a Wi-Fi network

● 128

ESP8266 UK 170601.indd 128

09-06-17 12:05


CHAPTER 6 • MicroPython Wi-Fi PROGRAMMING ON ESP8266

The following MicroPython function can be used to connect to a Wi-Fi network automatically, for example during the boot time. The assigned IP address is displayed at the end of the function: def Connect_WiFi(): import network net = network.WLAN(network.STA_IF) if not net.isconnected(): net.active(True) net.connect(“ssid”, “password”) print (net.ifconfig()) 6.3 Using the Socket Library – UDP and TCP/IP Packets

UDP and TCP/IP are two of the most commonly used protocols to send and receive data over the network. TCP/IP is a reliable protocol which includes handshaking and guarantees the delivery of packets to the required destination. UDP on the other hand is not so reliable but it is a fast protocol. Table 6.1 shows a comparison of the UDP and TCP/IP type communications. TCP/IP

UDP

Connection oriented protocol

Connectionless protocol

Slow

Fast

Highly reliable data transmission

Not so reliable

Packets arranged in order

No ordering of packets

20 byte header size

8 byte header size

Error checking and re-transmission

No error checking

Data received acknowledgement

No acknowledgement

Used in HTTP, HTTPS, FTP etc

Used in DNS, DHCP, TFTP etc

Table 6.1 Comparison of UDP and TCP/IP UDP and TCP/IP protocol based programs are server-client based where one node sends data and the other node receives it and vice-versa. Data is transferred through ports where the server and the clients must use the same port numbers. We shall now be looking at how UDP and TCP/IP protocol based programs can be written using the MicroPython programming language. The socket library is used for developing UDP and TCP/IP protocol based programs. 6.3.1 UDP Programs

UDP is a connectionless protocol and thus there is no need to make a connection to the destination node before a packet can be sent to it. The communication between a server and a client are basically as follows:

● 129

ESP8266 UK 170601.indd 129

09-06-17 12:05


CHAPTER 6 â&#x20AC;˘ MicroPython Wi-Fi PROGRAMMING ON ESP8266

Figure 6.6 The screen of the AGG software 6.3.2 TCP/IP Programs

TCP/IP is a connection based reliable protocol. An example is given in this section to show how this protocol can be used for data exchange over the network. Example 6.2 Write a TCP/IP program to receive a message from a TCP/IP client and display the message. Then, send the message Hello From the Server to the client. Assume the following IP addresses and port numbers:

Server (NodeMCU) IP address: 192.168.1.145 port: 2000 Destination (PC) IP address: 192.168.1.132 port: 2000

Make your NodeMCU development board to be the server node, and your PC to be the client node. Display the received message on the screen. Solution 6.2 The test system setup is as in Figure 6.2. Here again the AGG software is used, but this time in TCP/IP client mode. The MicroPython TCP/IP program for the NodeMCU is shown in Figure 6.7 (program: tcpip. py). At the beginning of the program the socket library is imported to the program, a TCP/ IP type socket is defines (SOCK_STREAM), the server address is defined and bind function is used to bind to the address and port. Then the listen function is used to listen for a connection from a client. The connection is accepted by the accept function. Function recv receives the client data. The data is displayed and then a message is sent back to the client using function sendall.

â&#x2014;? 133

ESP8266 UK 170601.indd 133

09-06-17 12:05


ESP8266 and Micropython - Coding cool stuff

#-------------------------------------------------------------------#

TCP/IP PROGRAM

#

==============

# # This is a MicroPython TCP/IP program. The program sends the message # “Hello From the Server” to a client. The IP addresses and ports # of the server and client are: # #

Server IP address: 192.168.1.145

POrt: 2000

#

Client IP address: 192.168.1.132

Port: 2000

# # The cleint sends the message “Hello From Client” # # # Program :

tcpip.py

# Date

April, 2017

:

# Programmer: Dogan Ibrahim #-----------------------------------------------------------------import socket Message = “Hello From the Server” sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_address = (“192.168.1.145”, 10000) sock.bind(server_address) sock.listen(1) conn,cient_address = sock.accept() # # Receive data from the client and display it # data = conn.recv(1024) print (data) # # Send data to the client # conn.sendall(Message) # # Close the socket # conn.close()

Figure 6.7 Program listing for the Example 6.2 The data received and displayed by the client (AGG software) is shown in Figure 6.8.

● 134

ESP8266 UK 170601.indd 134

09-06-17 12:05


ESP8266 and Micropython - Coding cool stuff

CHAPTER 7 • PROJECT – WHAT SHALL I WEAR TODAY ? 7.1 Overview

We all want to know what the weather will be like before getting dressed in the morning. If the weather is going to be rainy we may need to wear a raincoat and carry an umbrella, if the weather is cold we may want to wear thicker clothes, if its going to be warm or hot we may want to wear light summer clothes. We usually check the weather forecast first thing in the morning or look at the sky and then decide what to wear. In this project we shall be developing a project using a NodeMCU development board together with a Text-to-Speech processor module. For convenience we will assume that the system will activate automatically whenever we open the door(s) of our wardrobe, before deciding what to wear for the day. The actual operation of the system will be as follows: When the wardrobe is opened a switch will close which will power-up the system. When activated, the system will get the local weather forecast using an HTTP request through our home Wi-Fi router. Then, based upon the weather forecast the system will tell through a speaker the various weather parameters such as the temperature, humidity, wind, pressure, and the general weather forecast. The system will also make a decision and tell you by suggesting what to wear for the day according to the local weather condition. 7.2 The Block Diagram

The block diagram of the developed system is shown in Figure 7.1. The development system was built on a breadboard and is shown in Figure 7.2. The system basically consists of the following: • A NodeMCU development board • An EMIC2 Text-to-Speech processor • A speaker • +5V and +3.3V power supplies

● 140

ESP8266 UK 170601.indd 140

09-06-17 12:05


CHAPTER 7 • PROJECT – WHAT SHALL I WEAR TODAY ?

Figure 7.1 Block diagram of the developed system

Figure 7.2 System built on a breadboard

● 141

ESP8266 UK 170601.indd 141

09-06-17 12:05


CHAPTER 8 • PROJECT – THE TEMPERATURE AND HUMIDITY ON THE CLOUD

CHAPTER 8 • PROJECT – THE TEMPERATURE AND HUMIDITY ON THE CLOUD 8.1 Overview

In the last Chapter we saw the design and development of an interesting MicroPython based Wi-Fi application using a NodeMCU development board together with a Text-toSpeech processor module. The system was activated automatically whenever we opened the door of a wardrobe. In this Chapter we will be developing another interesting application. Here, the system will get the ambient temperature and humidity using a sensor and then store this data on the cloud so that it can be accessed from anywhere. 8.2 The Block Diagram

The block diagram of the system is shown in Figure 8.1. In this project a DHT11 temperature and humidity sensor chip is used (see Chapter 5). This chip normally requires a pull-up resistor but as shown in Figure 5.31 Elektor sells one with a built-in 10K pull-up resistor.

Figure 8.1 Block diagram of the project The circuit diagram of the project is as in Figure 5.32. The data output of DHT11 is connected to pin GPIO0 (D3) of the NodeMCU. The circuit is built on a breadboard as shown in Figure 5.33. 8.3 Reading the Temperature and Humidity

The program code that reads the temperature and humidity is written as a function and is shown in Figure 8.2. The function, called TempHum returns the temperature and the humidity to the main program.

● 157

ESP8266 UK 170601.indd 157

09-06-17 12:05


ESP8266 and Micropython - Coding cool stuff

Figure 8.2 Function to read and return the temperature and humidity 8.4 The Cloud

There are several free cloud services that can be used to store data (for example SparkFun, Thingspeak etc). In this project the Thingspeak is used. This is a free cloud service where sensor data can be stored and retrieved using simple HTTP requests. Before using the Thingspeak we have to create an account from their web site and then log in to this account. Create a new account by giving your email address and choose a password by opening the following link:

https://thingspeak.com/users/sign_up

You should get an email to verify and activate your account. After this, click Continue and you should get a successful sign-up notice as shown in Figure 8.3 and you should agree to the conditions.

Figure 8.3 Successful sign-up to Thingspeak Then, you should create a New Channel by clicking on New Channel. Fill in the form as shown in Figure 8.4. Give the name MyWeather to the application and create two channels called Temperature and Humidity, tick to make the channels public.

â&#x2014;? 158

ESP8266 UK 170601.indd 158

09-06-17 12:05


ESP8266 and Micropython - Coding cool stuff

CHAPTER 9 • PROJECT – REMOTE WEB BASED CONTROL 9.1 Overview

In the last Chapter we saw the design and development of an interesting MicroPython based Wi-Fi application which gets the ambient temperature and humidity and stores it on the cloud. In this Chapter we will be developing another interesting application. Here, the system will remotely control two LEDs connected to a NodeMCU development board using an HTTP Web Server application. Although in this example two LEDs are used, in general relays can be connected to the NodeMCU and any type of electrical equipment can be controlled remotely. 9.2 The Block Diagram

The block diagram of the system is shown in Figure 9.1. Figure 9.2 shows the circuit diagram of the project. LED0 and LED2 are connected to NodeMCU port pins 0 (labelled D3) and 2 (labelled D4) respectively through 330 ohm current limiting resistors. The LEDs are turned ON when the port output is at logic 1 (high). And turned OFF when the port output is at logic 0 (low).

Figure 9.1 Block diagram of the system

● 164

ESP8266 UK 170601.indd 164

09-06-17 12:05


CHAPTER 9 • PROJECT – REMOTE WEB BASED CONTROL

Figure 9.2 Circuit diagram of the system 9.3 HTTP Web Server/Client

A web server is a program that uses HTTP (Hypertext Transfer Protocol) to serve web pages to users in response of their requests. These requests are forwarded by HTTP clients. By using the HTTP server/client pair we can control any device connected to a web server processor over the web. Figure 9.3 shows the structure of a web server/client setup. In this figure, the NodeMCU is the web server and the PC (or a laptop, tablet or a mobile phone) is the web client. The device to be controlled is connected to the web server processor. In this example we have two LEDs connected to the NodeMCU development board. The operation of the system is as follows: • The web server is in the listen mode, listening for requests from the web client • The web client makes a request to the web server by sending an HTTP request • In response, the web server sends an HTTP code to the web client which is activated by the web browser by the user on the web client and is shown as a form on the web client screen. • The user sends a command (e.g. ticks a button on the web client form to turn ON an LED) and this sends a code to the web server so that the web server can carry out the required operation.

● 165

ESP8266 UK 170601.indd 165

09-06-17 12:05


ESP8266 and Micropython - Coding cool stuff

APPENDIX A • THE SPI BUS A.1 Overview

The SPI bus is commonly used in microcontroller based projects. In this Appendix we shall be looking at the use of this bus with a simple example using MicroPython. The aim is to make the reader familiar with the MicroPython SPI bus library functions and to show how they can be used in a real project. A.2 THE SPI BUS

SPI (Serial Peripheral Interface) bus is one of the most commonly used microcontroller communication protocols for communicating with external devices such as sensors and actuators. The SPI bus is a master-slave type bus where there is one master but there can be multiple slaves. The SPI bus consists of 4 wires: Master: • MISO – Master In Slave Out • MOSI – Master Out Slave In • SCLK – Serial Clock • SS – Slave Select Slave: • SDI – Slave Data In (or MOSI) • SDO – Slave Data Out (or MISO) • SCK – Serial Clock (or SCLK) • CS – Chip Select Figure A.1 shows the connection of a master and a slave on the SPI bus. The communication is controlled by the master clock, which is typically a few MHz. The master selects a slave device and sends its data in serial from where a bit is sent out with each clock. The master sends a bit on its MOSI line and the slave reads this bit. Also, the slave sends a bit on its MISO line and the master reads it. The data transmission on the SPI bus is done by using two shift registers, usually 8 bits wide, and one in the master, one in the slave. Data is shifted out with the most-significant-bit (MSB) first. After shifting out all the bits the data exchange takes place. If it is required to send more data, the sender’s shift register is loaded with data and this data is shifted out. The data exchange stops when the master removes its clock.

Figure A.1 Connection of a master and slave on the SPI bus

● 172

ESP8266 UK 170601.indd 172

09-06-17 12:05


ESP8266 and Micropython - Coding cool stuff

APPENDIX B â&#x20AC;˘ THE I2C BUS B.1 Overview

The I2C (or I2C) bus is commonly used in microcontroller based projects. In this Appendix we shall be looking at the use of this bus with a simple example using MicroPython. The aim is to make the reader familiar with the MicroPython I2C bus library functions and to show how they can be used in a real project. B.2 THE I2C BUS

I2C bus is one of the most commonly used microcontroller communication protocols for communicating with external devices such as sensors and actuators. The I2C bus is a single master, multiple slave bus and it can operate at up 50 5MHz. The bus consists of two opendrain wires, pulled-up with resistors: SDA: data line SCL: clock line Figure B.1 shows the structure of an I2C bus with one master and three slaves.

Figure B.1 I2C bus with one master and three slaves Communication is initiated by the master which sends a START bit. This alerts all the slaves that some data is coming on the bus and all the slaves listen on the bus. After the start bit, 7 bits of unique slave address is sent. Each slave device on the bus has its own address and this ensures that only the addressed slave communicates on the bus at any time to avoid any collisions. The last sent bit is read/write bit such that if this bit is 0, it means that the master wishes to write to the bus (e.g. to a register of a slave), if this bit is a 1, it means that the master wishes to read from the bus (e.g. from the register of a slave). The data is sent on the bus with the MSB bit first. B.3 MicroPython I2C BUS COMMANDS

The I2C functions for the ESP8266 MicroPython language are implemented in software and the following functions are commonly used:

â&#x2014;? 182

ESP8266 UK 170601.indd 182

09-06-17 12:05


ESP8266 and Micropython - Coding cool stuff

APPENDIX C • THE Node-RED This Appendix provides a very brief introduction to Node-RED. Detailed use and description of the Node-RED is beyond the scope of this book and only an introduction is given here to make the readers aware of this tool. Interested readers can find detailed information on Node-RED at the following web site and at many other sites on the Internet: noderedguide.com Node-RED is a visual flow based programming tool where the developers connect predefined code blocks (or nodes) together to perform a given task. The nodes connected together make up a flow and a flow can consist of input nodes, processing nodes, and output nodes. The idea with Node-RED is that various hardware can be connected without having to do any programming. Node-RED was originally developed by IBM for building Internet of Things (IoT) applications with the idea of simplifying the task of interconnecting various hardware together to perform a task. Although originally it was developed for IoT applications, Node-RED is nowadays used in a wide variety of control and monitoring based tasks. In a Node-RED application there are basically 3 types of nodes: input nodes, output nodes, and processing nodes. With the input nodes we can inject data to the flow. These nodes have at least one output represented by a small grey square on their right side. Input nodes can be used to get data from other services such as from Google, Twitter, TCP nodes and so on. Some input nodes have buttons where we can activate the node using these buttons. Some typical input nodes are: • inject • mqtt • http • serial • tcp • udp Output nodes allow us to send data out of a Node-RED flow. These nodes have one input on their left hand sides and they can send data to other services, such as to Google, Twitter, and so on. Some output nodes have buttons where we can enable or disable the node using these buttons. Some typical output nodes are: • debug • http response • serial • tcp • udp Processing nodes are used to process data. These nodes have one input point and one or more output points. A processing node can transform the input data, it can convert it to another format, it can trigger a message and so on. Some typical processing nodes are:

● 190

ESP8266 UK 170601.indd 190

09-06-17 12:05


Index A Adafruit 23 ADC 111 Addition 69 ampy 87 analog-to-digital converter (ADC) 111 ASCII Characters 77 Assignment Operator 70 AT Command Programming 30 AT Commands 26 B BarGraph Click board Bitwise Operator Blank Line

177 70 63

C C++ 26 Comments 62 Comparison Operator 70 Constant 86 D Date DH11 Class Division

80 123 69

E EMIC2 142 ESP-01 13 ESP8266 13 ESP8266 Thing 21 ESPlorer 46 ESP-xx module 16 Exponent 69 F Files flow based programming H HiLetgo D1 Mini NodeMCU HTTP Huzzah ESP8266

84 190

23 34 23

I I2C 182 Indentation 62 K keyboard 84 L LED LM3940 15 Logical Operator Lolin Lua

50 70 51 26

M machine library 100 MCP23017 185 microPython 26 MicroPython 50 mikroElektronika 15 mikroelektronika WiFi ESP 25 Modulus 69 Multiple Statements 63 Multiplication 69 N network 128 network Library 128 NodeMCU 19 NodeMCU Flasher 41 Node-RED 190 Number Type Conversion 76 P Pin Class Print Statement PuTTY PWM Class Python 50, 51, 61 R REPL (Read-Evaluate-Print-Loop) Reserved Words RTC Class

101 77 28 115

56 62 118

â&#x2014;? 193

ESP8266 UK 170601.indd 193

09-06-17 12:05


ESP8266 and Micropython - Coding cool stuff

Index

S semiconductor diode 16 Socket Library 129 SparkFun 22 SPI bus 172 Standalone 59 String 78 Subtraction 69 T TCP/IP 133 TCP/UDP 35 terminal emulator 29 Text-to-Speech processor 142 Time 80 Timer Class 117 Transmission Control Protocol (TCP) 35 Trigonometric Function 75 Tuple 68 U UART Class UDP USB-to-TTL adapter User Datagram Protocol (UDP)

119 129 18 35

V variables 64 W WebREPL 136

â&#x2014;? 194

ESP8266 UK 170601.indd 194

09-06-17 12:05


ESP8266 AND MICROPYTHON D. & A. Ibrahim Prof Dr Dogan Ibrahim has a BSc in electronic engineering, an MSc in automatic control engineering, and a PhD in digital signal processing. Prof Ibrahim is the author of over 60 technical books and over 200 technical articles on microcontrollers, microprocessors, and related fields. Ahmet Ibrahim obtained his BSc degree from the Greenwich University in London. He then completed an MSc course at the same university. Ahmet has worked at many industrial organizations at various levels and is currently working in a large organization in the field of IT.

ESP8266 and MicroPython – Coding Cool Stuff is an introduction to the ESP8266 chip and describes the features of this chip and shows how various firmware and programming languages such as the MicroPython can be uploaded to the chip. The main aim of the book is to teach the readers how to use the MicroPython programming language on ESP8266 based hardware, especially on the NodeMCU. Several interesting and useful projects are given in the book to show how to use the MicroPython in NodeMCU type ESP8266 hardware: •

Project “What shall I wear today?”: You will be developing a weather information system using a NodeMCU development board together with a Text-to-Speech processor module.

Project “The Temperature and Humidity on the Cloud”: You will be developing a system that will get the ambient temperature and humidity using a sensor and then store this data on the cloud so that it can be accessed from anywhere.

Project “Remote Web Based Control”: You will be developing a system that will remotely control two LEDs connected to a NodeMCU development board using an HTTP Web Server application.

ESP8266 AND MICROPYTHON ● D. & A. IBRAHIM

CODING COOL STUFF

CODING COOL STUFF

ESP8266 AND MICROPYTHON

ISBN 978-1-907920-62-2

www.elektor.com

LEARN DESIGN

Elektor International Media BV

Dogan Ibrahim & Ahmet Ibrahim LEARN DESIGN SHARE

SHARE

LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIG ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● S GN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DES ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● S

ESP8266 and MicroPython  

Look inside Elektor's ESP8266 and MicroPython book. The main aim of the book is to teach the readers how to use the MicroPython programming...

ESP8266 and MicroPython  

Look inside Elektor's ESP8266 and MicroPython book. The main aim of the book is to teach the readers how to use the MicroPython programming...