0% found this document useful (0 votes)
35 views79 pages

Micropython For Microcontrollers 1st Edition Gnter Spanner PDF Download

Ebook access

Uploaded by

efdlillen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views79 pages

Micropython For Microcontrollers 1st Edition Gnter Spanner PDF Download

Ebook access

Uploaded by

efdlillen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 79

Micropython For Microcontrollers 1st Edition

Gnter Spanner download

https://ebookbell.com/product/micropython-for-
microcontrollers-1st-edition-gnter-spanner-50751504

Explore and download more ebooks at ebookbell.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Python For Microcontrollers Getting Started With Micropython Donald


Norris

https://ebookbell.com/product/python-for-microcontrollers-getting-
started-with-micropython-donald-norris-42922654

Micropython For The Internet Of Things A Beginners Guide To


Programming With Python On Microcontrollers Charles Bell

https://ebookbell.com/product/micropython-for-the-internet-of-things-
a-beginners-guide-to-programming-with-python-on-microcontrollers-
charles-bell-38548020

Micropython For The Internet Of Things A Beginners Guide To


Programming With Python On Microcontrollers Charles Bell

https://ebookbell.com/product/micropython-for-the-internet-of-things-
a-beginners-guide-to-programming-with-python-on-microcontrollers-
charles-bell-58183410

Micropython Cookbook Over 110 Practical Recipes For Programming


Embedded Systems And Microcontrollers With Python Alsabbagh

https://ebookbell.com/product/micropython-cookbook-over-110-practical-
recipes-for-programming-embedded-systems-and-microcontrollers-with-
python-alsabbagh-22965632
Micropython For The Internet Of Things 2nd Edition 2nd Charles Bell

https://ebookbell.com/product/micropython-for-the-internet-of-
things-2nd-edition-2nd-charles-bell-55897704

Micropython For The Internet Of Things Charles Bell

https://ebookbell.com/product/micropython-for-the-internet-of-things-
charles-bell-35147354

Micropython For Esp32 Development Workshop Agus Kurniawan

https://ebookbell.com/product/micropython-for-esp32-development-
workshop-agus-kurniawan-44857388

Micropython For Everyone How To Use Esp32 And Esp8266 Micropython


Arduino Donelan

https://ebookbell.com/product/micropython-for-everyone-how-to-use-
esp32-and-esp8266-micropython-arduino-donelan-23641802

Micropython For Everyone How To Use Esp32 And Esp8266 Micropython


Arduino Lamont Donelan

https://ebookbell.com/product/micropython-for-everyone-how-to-use-
esp32-and-esp8266-micropython-arduino-lamont-donelan-33187128
books

MicroPython for
Microcontrollers
Projects with Thonny-IDE, uPyCraft-IDE, and ESP32

Günter Spanner
MicroPython for Microcontrollers
Projects with Thonny-IDE, uPyCraft-IDE, and ESP32

Dr Günter Spanner
● This is an Elektor Publication. Elektor is the media brand of
Elektor International Media B.V.
PO Box 11, NL-6114-ZG Susteren, The Netherlands
Phone: +31 46 4389444

● All rights reserved. No part of this book may be reproduced in any material form, including photocopying, or
storing in any medium by electronic means and whether or not transiently or incidentally to some other use of this
publication, without the written permission of the copyright holder except in accordance with the provisions of the
Copyright Designs and Patents Act 1988 or under the terms of a licence issued by the Copyright Licencing Agency
Ltd., 90 Tottenham Court Road, London, England W1P 9HE. Applications for the copyright holder's permission to
reproduce any part of the publication should be addressed to the publishers.

● Declaration
The Author and the Publisher have used their best efforts in ensuring the correctness of the information contained
in this book. They do not assume, and hereby disclaim, any liability to any party for any loss or damage caused by
errors or omissions in this book, whether such errors or omissions result from negligence, accident or any other
cause.

● British Library Cataloguing in Publication Data


A catalogue record for this book is available from the British Library

● ISBN 978-3-89576-436-3 Print


ISBN 978-3-89576-437-0 eBook
ISBN 978-3-89576-438-7 ePub

● © Copyright 2021: Elektor International Media B.V.


Translation: Carmen Jacquemijns
Editor: Jan Buiting
Prepress Production: D-Vision, Julian van den Berg

Elektor is part of EIM, the world's leading source of essential technical information and electronics products for pro
engineers, electronics designers, and the companies seeking to engage them. Each day, our international team develops
and delivers high-quality content - via a variety of media channels (including magazines, video, digital media, and social
media) in several languages - relating to electronics design and DIY electronics. www.elektormagazine.com

●4
Content

Notices and Disclaimers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

Demo Programs Download Archive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

Chapter 1 • Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

1.1 Python, C, or Arduino? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

1.2 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

Chapter 2 • A Variety of ESP Boards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

2.1 Commissioning and function test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

2.2 ESP32 on battery power . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

Chapter 3 • P
 rogramming and Development Environments . . . . . . . . . . . . . . . . . . 19

3.1 Installing the uPyCraft IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

3.2 MicroPython for the ESP32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

3.3 "Hello World" for the controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

3.4 For professionals: Working with esptool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

3.5 Thonny — a Python-IDE for beginners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

3.6 Working with Thonny . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

3.7 Working with files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

3.8 Troubleshooting tips for the Thonny IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

Chapter 4 • First Steps in Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

4.1 Never without: Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

4.2 The Print() statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

4.3 Indentations and blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

4.4 The hardware under control: digital inputs and outputs . . . . . . . . . . . . . . . . . . . . 45

4.5 Time control and sleep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

4.6 Important values: variables and constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

4.7 Numbers and types of variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

4.8 Converting number types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

4.9 Little Big Data: Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

4.10 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

4.11 With format, please: appealing text and data output . . . . . . . . . . . . . . . . . . . . . . . 55

4.12 Characters in chains: strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

Chapter 5 • The Controller in Practical Use . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

5.1 LED flasher as alarm system simulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

●5
MicroPython for Microcontrollers

5.2 Useful in an emergency: automatic SOS signal . . . . . . . . . . . . . . . . . . . . . . . . . . 61

Chapter 6 • Program Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

6.1 Conditions and loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

6.2 Running lights and airport lighting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

6.3 Electronic rainbow: RGB LED in use . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66

6.4 SOS compact-style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

6.5 Trial and error: try and except . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

Chapter 7 • Analogue-Signal Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

7.1 Pulsewidth modulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

7.2 For romantic evenings: heartbeat simulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

7.3 Light alarm clock for a relaxed wake-up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74

7.4 Mood-Light with multicolour LED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

7.5 Clean and smooth: analogue values from the DAC . . . . . . . . . . . . . . . . . . . . . . . 76

7.6 Output of time-dependent voltages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

7.7 For interesting curves: An arbitrary function generator . . . . . . . . . . . . . . . . . . . . 78

Chapter 8 • Interrupts and Timers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81

8.1 Disruption wanted: Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81

8.2 Automatic night light . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82

8.3 Masters of Time: Timers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84

8.4 A multifunctional flashing light . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

Chapter 9 • Using Sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90

9.1 Acquisition of measurement and sensor values . . . . . . . . . . . . . . . . . . . . . . . . . 90

9.2 Precise recording of voltages: a DIY voltmeter . . . . . . . . . . . . . . . . . . . . . . . . . . 92

9.3 Linearity correction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95

9.4 Linearization by limitation of the value range . . . . . . . . . . . . . . . . . . . . . . . . . . . 96

9.5 Linearization of the ADC input by means of compensation polynomial . . . . . . . . . . 97

9.6 Voltage measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98

9.7 Cross-interferences: side effects in sensor technology . . . . . . . . . . . . . . . . . . . . 101

9.8 Touching permitted: capacitive touch sensors . . . . . . . . . . . . . . . . . . . . . . . . . 102

9.9 Well chilled or overheated: temperature sensors provide clarity . . . . . . . . . . . . . 105

9.10 Digital temperature recording for error-free data transmission . . . . . . . . . . . . . 108

9.11 The DS18×20 One-Wire sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108

●6
Content

9.12 Data power: multi-sensor array with the DS18x20 thermal sensor . . . . . . . . . . 110

9.13 In full view: optical sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112

9.14 For film and photo professionals: electronic luxmeter . . . . . . . . . . . . . . . . . . . 113

9.15 Electronic bats: distance measurement with ultrasound . . . . . . . . . . . . . . . . . . 115

9.16 No more dents and scratches: distance warning device for garages . . . . . . . . . 119

9.17 Optimum indoor climate for flora and fauna . . . . . . . . . . . . . . . . . . . . . . . . . . 121

9.18 "Trust me ...": sensor comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

9.19 Air pressure and altitude measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126

9.20 Detecting magnetic fields with the Hall sensor . . . . . . . . . . . . . . . . . . . . . . . . 129

9.21 Alarm detectors monitor door and gate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130

Chapter 10 • Display Technology and Small-Size Screens . . . . . . . . . . . . . . . . . . 132

10.1 Graphical representations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135

10.2 OLED display as data plotter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138

10.3 The exact time please: digital clock with OLED display . . . . . . . . . . . . . . . . . . 140

10.4 Not just for athletes: a stopwatch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144

10.5 Just touch: stop watch with sensor keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145

10.6 Great climate with the BME280 sensor! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148

Chapter 11 • LED Matrices and Large Displays . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

11.1 LED matrix in action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152

11.2 Running scripts and animated graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153

Chapter 12 • Physical Computing: Servos Bring Movement into Play . . . . . . . . . 155

12.1 A servo tester . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155

12.2 Mega-display servo thermometer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158

Chapter 13 • RFID and Wireless Data Transmission . . . . . . . . . . . . . . . . . . . . . . . 161

13.1 Reading cards and chips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162

13.2 Contactless and secure: RFID lock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164

Chapter 14 • MicroPython and the Internet of Things (IoT) . . . . . . . . . . . . . . . . 167

14.1 For modern detectives: a network scanner . . . . . . . . . . . . . . . . . . . . . . . . . . . 168

14.2 Connected but no cables: WLAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169

14.3 Switch and control with the web server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172

14.4 The WLAN web server in action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176

14.5 Reading out sensor data via WLAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177

●7
MicroPython for Microcontrollers

14.6 Recording environmental parameters: WLAN Thermo/Hygrometer . . . . . . . . . . 179

Chapter 15 • Simple and Good: The MQTT Protocol . . . . . . . . . . . . . . . . . . . . . . . 183

15.1 MQTT via ThingSpeak . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185

Chapter 16 • Sending Data to the Internet via ThingSpeak . . . . . . . . . . . . . . . . . 190

16.1 Rain or storm? Virtual weather station available worldwide . . . . . . . . . . . . . . . 190

16.2 Graphical representation of data in ThingSpeak . . . . . . . . . . . . . . . . . . . . . . . 194

16.3 Data for the smartphone with the ThingView app . . . . . . . . . . . . . . . . . . . . . . 195

16.4 Against unwanted visitors: Optical room surveillance . . . . . . . . . . . . . . . . . . . 196

Chapter 17 • Micropower Techniques and Sleep Modes . . . . . . . . . . . . . . . . . . . . 199

17.1 Saving power protects the environment: low-power technologies . . . . . . . . . . . 199

17.2 Disabling unnecessary consumers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200

17.3 Weather station with battery or solar operation . . . . . . . . . . . . . . . . . . . . . . . 201

Chapter 18 • Bus Systems for Efficient Communication . . . . . . . . . . . . . . . . . . . 202

18.1 Basics and applications of the I²C bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202

18.2 The SPI bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207

18.3 The members of the SPI family . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210

18.4 Controlling SD and µSD cards via SPI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210

Chapter 19 • Building Circuits with Components and Breadboards . . . . . . . . . . . 212

19.1 Breadboards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213

19.2 Wire jumpers and jumper cables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214

19.3 Resistors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215

19.4 Light-emitting diodes (LEDs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216

19.5 Capacitors and electrolytic capacitors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217

Chapter 20 • Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219

Chapter 21 • Hardware Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220

Chapter 22 • List of Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221

Chapter 23 • Bill of Materials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226

●8
Notices and Disclaimers

Notices and Disclaimers

1. The circuits in this book are for educational purposes only.

2. The circuits in this book may only be operated with batteries and/or tested, dou-
ble insulated safety power supplies. Insulation faults of a simple power supply
unit can lead to life-threatening voltages on non-insulated components.

3. Powerful LEDs can cause eye damage. Never look directly into an LED!

4. Neither the Author or the Publisher accept any liability for damage resulting from
the construction of the described projects, or attempts to do so.

5. Electronic circuits can emit electromagnetic interference radiation. Since neither


the Publisher or the Author have any influence on the user's skills in assembling,
operating, and controlling electronic circuits, the user alone is responsible for
compliance with the relevant emission limit values.

●9
MicroPython for Microcontrollers

Demo Programs Download Archive

The demo programs mentioned in this book can downloaded free of charge as a single ar-
chive file (.zip) from the book resources web page:

www.elektor.com/micropython-for-microcontrollers

If a program from the download archive file appears to differ from the version described in
the book, the downloaded version should be used as it may reflect updates made by the
author since printing the book.

● 10
Chapter 1 • Introduction

Chapter 1 • Introduction

The introduction of the ESP32 chip from Espressif Systems marks a new generation of
microcontrollers, which offer excellent performance, Wi-Fi, and Bluetooth functionality at
an unrivalled price. These features have taken the maker scene by storm. The most diverse
applications and projects in the areas of Internet of Things (IoT) and home automation can
be implemented easily and cost-effectively. The ESP32 is as easy to program as the classic
Arduino boards. In comparison, however, the ESP32 also offers, among other things:

• Larger flash and SRAM memory


• Much higher CPU speed
• Integrated Wi-Fi / WLAN
• Bluetooth functionality
• More GPIO pins
• Extensive interface functionality
• Analogue/digital converter with higher resolution
• Digital/analogue converter
• Security and encryption functions

For these reasons, it can be considered the most promising successor to Arduino. The term
"Arduino killer" is often used in this context.

This book introduces the programming of modern single-chip systems (Systems on Chip —
SoCs). In addition to the technical background, the focus is on the programming language
Python, especially in its variant "MicroPython". Basic relationships between electronics and
electrical engineering will only be dealt with to the extent that it is essential for the design of
the circuits and experiments.

The "hardware" for getting started can be kept very simple anyway. At first, only a controller
board and some light emitting diodes as well as suitable series resistors are required. The
PC or laptop required for programming the chip should be available in every household. The
appropriate programming environment can be downloaded free of charge from the internet.
When working with a MicroPython programming environment, however, the first problems
quickly arise. A good introduction can therefore lead to excellent performances.

Python has experienced an enormous upswing in recent years. Various single-board systems
like the Raspberry Pi have especially contributed to its popularity. But Python has also found
widespread use in other areas such as artificial intelligence or machine learning. Hence it
is a logical choice to use Python or the variant MicroPython for the application in SoCs, too.

However, we will not restrict ourselves to a mere introduction to the programming lan-
guage. In many cases, the learned programming skills are put into practice together
with electronic circuitry. The fully described projects are all suitable for use in laborato-
ries or in everyday life. In addition to the educational effect, the pleasure of assembling
complete and useful devices is therefore also in the foreground. Through the use of lab-
oratory plug-in boards, circuits of all kinds can be realised with little effort. The testing

● 11
MicroPython for Microcontrollers

and trial of applications thus becomes an educational pleasure.

Due to the various applications such as weather stations, digital voltmeters and function
generators, the presented projects are also ideally suited for internships or study courses in
the natural sciences or in science and technology lessons.

1.1 Python, C, or Arduino?


For beginners, the Arduino programming environment is one of the easiest places to pro-
gram the ESP32. Behind this interface is the Arduino version of C, as well as C++. These
two programming languages have been popular for years for the development of embedded
systems. The Arduino version of C made it even easier to get started. In addition, one of the
largest technology communities in the world developed for this purpose. With new libraries,
software fixes and board support, problems could usually be solved quickly. However, the
restriction that Arduino-C only works in its designated environment is not insignificant. Es-
pecially for the development of more extensive projects, useful and important functions are
missing. Therefore, Arduino-C remained mostly limited to hobby and beginner projects.

MicroPython is relatively new. The user community is growing, and more and more platforms
are supported. MicroPython is essentially a slim version of Python, one of the most popular
programming languages in the world. Therefore, specific problems can be dealt with not only
in MicroPython communities. In fact, general Python forums are increasingly contributing to
solving MicroPython issues.

In addition to community support, MicroPython also has certain features that put it well
above the class of the Arduino. One of these features is the so-called REPL function. REPL
stands for "Read-Evaluate-Print Loop". This allows programs and code sections to be execut-
ed quickly. Compiling or uploading is not necessary. In this way, parts of a code can be tested
quickly and efficiently during development.

MicroPython contains a very compact implementation of the Python interpreter. It requires


only 256 KB flash memory and 16 KB RAM. Nevertheless the interpreter is designed for max-
imum compatibility with the standard Python. Syntax and language range correspond largely
to Python version 3.4, so experienced Python programmers should be able to find their way
around immediately. In addition, a few language elements beyond the standard are defined,
which keep the memory requirements low and increase the execution speed.

1.2 Requirements
In order to work successfully with this book, the following requirements should be met:

• Secure handling of the Windows operating system;


• Basic knowledge of any programming language such as C, Java or similar;
• Basic knowledge in the field of electronics, especially in the area of "current —
voltage — resistance" is assumed.

For specialized knowledge in the field of electronics, please refer to the extensive technical
literature, especially from Elektor, through their books, magazines, and kits. The hardware

● 12
Chapter 1 • Introduction

structure was deliberately kept simple, as the focus should be on programming with MicroPy-
thon. Nevertheless, different components and parts are required. Explanations can be found
in the individual chapters in which the components are used first. In addition, the last sec-
tions of the book explain some basic components such as resistors or light emitting diodes.
You can consult these if there are any unclarities concerning individual components.

Further requirements are

• a PC or laptop with USB interface,


• the Windows 10 operating system,
• internet access.

It is also useful to employ an active USB hub between the computer and the controller. This
has the advantage that it guarantees a certain protection for the PC. The hub should have
its own 5 V power supply through a separate power supply unit. Then the PC or laptop is best
protected against short-circuits behind the hub, as it is very unlikely that a short circuit will
"blow through" an active hub to the USB port of the computer.

● 13
MicroPython for Microcontrollers

Chapter 2 • A Variety of ESP Boards

The ESP32 is a modern and extremely powerful microcontroller. In addition to a high clock
frequency and the extensive internal functional units, the chip has integrated Wi-Fi and
Bluetooth. The controller was developed by Espressif Systems, a Chinese company based
in Shanghai, and is enjoying increasing popularity. The performance features of the ESP far
exceed the well-known Arduino boards in terms of price and performance.

As the ESP32 is only available as an SMD chip, a so-called break-out board (BoB) or devel-
opment board is required if the controller is to be used in a non-professional environment.
In the meantime, a virtually unmanageable variety of different versions is available on the
market. The best-known versions are:

Board Pins Buttons LiPo Charger

ESP32-PICO-KIT 34 EN and BOOT no

JOY-iT NodeMCU 30 EN and BOOT no

ESP32 DEV KIT DOIT 30/36 EN and BOOT no

Adafruit HUZZAH32 28 RESET yes

ESP32 Thing 40 EN and BOOT yes

LOLIN32 40 EN and BOOT no

Node-ESP-Board 38 EN and BOOT no

The following image shows just three different versions:

Figure 2.1: ESP32 boards (PICO-KIT, Node-ESP and NodeMCU).

These boards have the necessary prerequisites to operate the ESP controller on a solderless
plug-in board or breadboard. Frequently, in addition to the controller, other components
such as pushbuttons, a Li-ion battery charger, or various LEDs are mounted on the boards

● 14
Chapter 2 • A Variety of ESP Boards

available. This means that initial tests and experiments can be carried out without external
circuitry.

The following section summarizes the most important data about ESP32. The overview
should only provide a first impression. A deeper understanding of the individual features
and functions is then provided in the relevant sections in the book.

Processor: 160 / 240 MHz Tensilica LX6 dual-core microprocessor


Memory: 520 KByte SRAM / 16 MByte Flash memory
Power supply: 2.2 V to 3.6 V
Power consumption: Standard: approx. 50 - 70 mA
Wi-Fi mode: approx. 80 - 170 mA
Deep sleep mode: approx. 2.5 µA
Ambient temperature: –40 °C to +125 °C
Inputs/Outputs (GPIOs): 32 general purpose ports with PWM
Function and timer logic
Wi-Fi: 802.11 b/g/n/e/i
Network throughput: 135 MBit/s (via UDP protocol)
Receiver sensitivity: –98 dBm
Bluetooth: V4.2 BR/EDR and BLE
Bluetooth functionality: Classic and Bluetooth Low Energy (with integrated antenna)
Sensors: Hall sensor
10× capacitive touch sensor
Interfaces: 3× UART with flow control via hardware 3x SPI interfaces
CAN bus 2.0 controller
2× I2S and 2xI2C interfaces
18 analogue inputs with 12-bit analogue-to-digital converters
2 analogue outputs with 10-bit digital-to-analogue converters
Infrared (IR) (TX/RX)
Motor PWM
LED-PWM with up to 16 channels
Interface for external SPI flash memory for up to 16 MB
SD card hardware
Security: Wi-Fi: WFA, WPA/WPA2 and WAPI Secure Boot
Flash Encryption
Cryptographic Hardware Acceleration Elliptic Curve Cryptogra-
phy (ECC)
Random Number Generator (RNG)

The ESP32-PICO-KIT is usually employed for the application examples in this book. Alter-
natively the ESP32 DEV KIT or another board can be used. The variant used is mentioned
explicitly in each case. In principle, however, the various boards are largely compatible. They
differ mainly in size and in pin arrangement order. Figure 2.2. shows the PICO-KIT with its
functional units and connections.

● 15
MicroPython for Microcontrollers

Figure 2.2: ESP32 PICO-KIT board.

The breakout boards are best suited as experimental and development boards. Via the port
connections, electronic components such as LEDs, temperature sensors or even smaller ac-
tuators such as R/C model servos can be connected directly. The Pico Kit board has the fol-
lowing features, among others:

• ESP controller with two 32-bit cores


• Fast Wi-Fi and WLAN interface (up to 150 MBit/s)
• ADC & DAC functionality
• Touch Sensor Unit
• Host Controller for SD/SDIO/MMC
• SDIO/SPI Controller
• EMAC and PWM unit for controlling LEDs and motors
• UART, SPI, I²C and I²S interfaces
• Infrared remote-control controller
• GPIO Interface
• Bluetooth/Bluetooth LE (4.2)
• USB-to-Serial-Chip for access via USB interface

2.1 Commissioning and function test


As soon as a board is available, it should be subjected to an initial functional test. For this
purpose, a USB cable is connected to a PC or laptop and the micro-USB socket of the board.
If present, a USB hub should already be connected in between.

On most boards, an LED will light up when connected to a powered USB port. If, contrary to
expectations, this so-called "power-on" LED does not light up, the USB connection should be
disconnected immediately. In this way you can prevent a possible short circuit from causing
major damage. For further troubleshooting, helpful hints are given in the corresponding
chapter at the end of the book.

ESP boards should always be operated in a solderless plug-in board (see Figure 2.3). How-
ever, if you do work without a breadboard, make sure that the base used is not conductive,

● 16
Chapter 2 • A Variety of ESP Boards

otherwise short circuits between the pins may occur. Next to the ESP board itself, this can
even destroy the USB port of the PC.

Figure 2.3: ESP board plugged into a breadboard.

2.2 ESP32 on battery power


In most cases, an ESP board is supplied with power via the Micro-USB socket. Since the con-
troller is connected to a PC or laptop during program creation anyway, no additional power
supply is required.

If a direct data exchange with the PC is no longer necessary, the board can also be supplied
by a USB power supply. This should be able to supply at least 1,000 mA (1 A; 1 amp) of
current output to avoid unwanted voltage drops. In addition, there is a certain amount of
reserve power to operate some LEDs, displays or sensors.

Even without a USB connection, the board can send and receive data via Wi-Fi and Blue-
tooth. In order to achieve complete independence from power and data cables, the module
then only needs to be powered by (rechargeable) batteries.

Some boards have a Lithium-Ion (Li-Ion) battery connector for this purpose (see Figure 2.4).
There, suitable cells can be connected directly via the standard plug. An internal voltage
regulation then ensures that the controllers are optimally supplied. In addition, a connected
battery is charged as soon as the board is connected to a live USB socket.

For this application, cells with a capacity of about 1,500 mAh or more are suitable. Smaller
batteries below 300 mAh should not be used, as they could be overcharged by the integrated
charge controller.

With a typical power consumption of approx. 50 mA, the 1,500 mAh variant can achieve an
operating time of around 30 hours, i.e. just over a day. When using the controller's sleep
functions, even considerably longer operating times can be achieved.

● 17
MicroPython for Microcontrollers

Single cell LiPo (Lithium Polymer) or Lithium-Ion batteries provide sufficient power for the
ESP32. However, their voltage of 3.7 to 4.2 V, depending on the state of charge, is too high
for the ESP32. It is therefore regulated down via an internal module.

As working with Li-ion batteries is always associated with a certain degree of danger, the
following information should not be omitted:

• Lithium-Ion batteries react sensitively to incorrect charging currents or voltag-


es. Under certain circumstances there is even a risk of fire or explosion.
• Each user is responsible for their own construction and operation of the project.
• Neither the Publisher nor the Author assumes any liability.

Figure 2.4: NodeESP board in battery mode.

● 18
Chapter 3 • Programming and Development Environments

Chapter 3 • P
 rogramming and Development
Environments

Unlike the situation with, say, an Arduino system, there are several Integrated Developing
Environments (IDEs) available for working with MicroPython. In principle, you can write pro-
grams with all IDEs and load them onto the controller. The two most widespread program-
ming environments are currently:

• µPyCraft
• Thonny

Both have their own specific advantages and disadvantages. The differences lie mainly in the
different procedures for developing and managing program code for the application projects.

The first variant called µPyCraft offers a comparatively simple interface for MicroPython
development on the ESP32 controller. It works with simple graphic elements and resembles
text-oriented operating systems. The handling of the individual functions is easy to under-
stand and working with the different menus is easy to learn.

Thonny, on the other hand, has a fully graphical interface in Windows style. The IDE is very
popular among makers, especially because it is available under the Raspbian operating sys-
tem on the Raspberry Pi. Many Raspberry Pi users are therefore already very familiar with
Thonny.

The IDEs stand for the most important operating systems such as

• Windows PC
• Mac OS X
• Linux Ubuntu

which are available free of charge on the internet.

If problems occur during installation or use of either system, the other version can be used
as an alternative programming system. The version to choose depends of course on the
personal inclinations and habits of the user.

3.1 Installing the uPyCraft IDE


Before installing uPyCraft IDE, the latest version of Python 3.7.X should be installed on the
computer you are using. If it is not, the installation can be done according to the following
instructions:

1. Download the installation file from the Python download page at:

www.python.org/downloads

● 19
MicroPython for Microcontrollers

2. After the download operation, a file named

python-3.7.X.exe

should reside on your computer. Double-clicking on the file starts the


installation.

3. Select "Add Python 3.7 to PATH" and click the "Install Now" button.

4. The installation process is completed after a few seconds and the message
"Setup was successful" is displayed. The window can then be closed.

Now the uPyCraft IDE for Windows can be downloaded from

https://github.com/DFRobot/uPyCraft

as a file called uPyCraft_V1.x.exe. After clicking on this .exe file, the uPyCraft-IDE will open:

Figure 3.1: uPyCraft-IDE

After the IDE is installed on the computer, the ESP32 firmware can be loaded onto the chip.
The current version of the MicroPython firmware for the ESP32 can be found at

http://micropython.org/download#esp32

There you scroll to the section "ESP32 modules". After clicking the link to "Generic ESP32
module" you will get to the download page of the ESP32-BIN file. This will look as follows:

esp32-idf3-20191220-v1.12.bin

Now you can start the uPyCraft-IDE. Under

Tools -> Serial

● 20
Chapter 3 • Programming and Development Environments

select the ESP32-COM port, here as COM5:

Figure 3.2: Selecting the port.

If the ESP32 board is connected to the computer but the ESP32 port does not appear in the
uPyCraft IDE, the appropriate USB driver may be missing. In this case, the driver must be
reinstalled. A corresponding driver can be found under

https://www.silabs.com/products/development-tools/software/usb-to-uart-
bridge-vcp-drivers

Afterwards you can follow

Tools -> Board

Next, the option "esp32" must be selected:

Figure 3.3: Selecting the board type

Now the MycroPython interpreter can be written onto the ESP32 using

Extras -> Burn Firmware

● 21
MicroPython for Microcontrollers

The appropriate options are:

• board: esp32
• burn_addr: 0x1000
• erase_flash: yes
• com: COMX (here COM5, see above)

Under "USERS", select the downloaded ESP32-BIN file, as shown in Figure 3.4.

Figure 3.4: The parameters for flashing the firmware

If all settings are correctly selected, the "BOOT / FLASH" button on the ESP32 board must
be pressed on some board variants. As soon as the "EraseFlash" process begins, the key can
be released. After a few seconds, the firmware should have flashed onto the ESP32 board.
However, in many cases the download will start without pressing the buttons.

If the "EraseFlash" display does not start or an error message is displayed, repeat the steps
described above. Also press the "BOOT / FLASH" key again to ensure that ESP32 enters the
flash mode.

3.2 MicroPython for the ESP32


With a few exceptions, all features and functions of Python are also available in MicroPython.
The biggest difference is that the micro version was designed for use on single-chip systems
and therefore the classic routines required only for the PC are missing.

For this reason MicroPython does not contain the complete standard library, but only the
parts relevant for microcontrollers. Therefore, all modules required for accessing the used
hardware are available. With the corresponding libraries you can therefore easily access
the GPIO pins. Especially for the ESP32 there are also modules available to support network
connections (Wi-Fi) and Bluetooth. In particular, the following boards are supported:

• ESP32
• ESP8266
• PyBoard
• Teensy 3.X
• WiPy - Pycom

● 22
Chapter 3 • Programming and Development Environments

Although not all functions of the ESP controller are fully available in MicroPython as of yet,
the libraries contain the most important commands and routines. Therefore many projects
and applications can be implemented smoothly. In addition, the implementation of the miss-
ing features is progressing rapidly, so that even this small beauty flaw will be quickly elim-
inated.

Once the MicroPython firmware has been installed on the ESP32, you can also easily return
to the Arduino IDE, for example. To do this, simply load the new C code with the IDE onto
the controller. A special deletion procedure is not necessary. However, if you want to use
MicroPython again afterwards, the MicroPython firmware must be flashed again.

3.3 "Hello World" for the controller


Unlike AVR controllers, such as those used in the Arduino system, the ESP32 can accommo-
date a complete file system. The first generations of controllers were programmed in either
Assembler or C. The program code was therefore created and compiled in a development
environment. Then only the finished "machine code" was transferred to the controller. The
memory of the target system therefore always contained exactly one program.

In contrast, when programming in MicroPython, several programs can be stored on the


ESP32 chip. These can then be processed directly by the interpreter that is also available on
the system. The file system can be managed directly with the uPyCraft-IDE. It is therefore
advisable to familiarise yourself with the IDE a little more closely before loading the first
application program onto the ESP. The development environment contains, similar to many
other programming tools, the following components (see also Figure 3.1)

1. Folders and files


2. Editor
3. MicroPython Shell / Terminal
4. Tools

In the left sub-window ("Folders and files"), the files currently stored on the ESP board are
visible in the device folder ("device"). As soon as the board is connected to uPyCraft-IDE via a
serial connection, all saved files will be loaded when opening the device folder. Directly after
the installation of the Python interpreter only a "boot.py" file is visible here. To execute the
application code, a main.py file should also be created. You can create a main.py file using:

file → new

This creates a new file ("untitled"). Through the floppy disk icon in the "Tools" window this
file can be saved locally under the name "main.py" on the ESP chip.

● 23
MicroPython for Microcontrollers

Figure 3.5: Creating a new file "main.py".

The following two files are now in the device folder:


• boot.py: executed every time the board is rebooted
• main.py: main script for the application code

The SD folder follows under the device folder. This folder is intended for accessing files stored
on an SD card. Some ESP-32 boards have an SD card slot. If a µSD card is inserted here, the
files on the card appear in the "sd" folder.

The uPy_lib folder follows below. Here the integrated IDE library files are shown. Here you
can find different files directly after the installation of the MicroPython interpreter. These are
provided as standard libraries.

Figure 3.6: Standard libraries in the uPy_lib folder.

The last folder contains the so-called "workSpace". This is a directory for saving application
files. The files displayed here are stored on the computer connected via the interface. All
active files should be stored there.

When uPycraft is used for the first time, it is therefore recommended that a suitable working
directory called "workSpace" be created and then used consistently for working with the
controller.

In the Editor area (2) the code for the .py application programs is created. The Editor opens
a new tab for each file.

● 24
Chapter 3 • Programming and Development Environments

The section below the Editor area is the "MicroPython Shell/Terminal" (3) All commands
entered here are immediately executed by the ESP board. In addition, the terminal also
displays information about the status of a running program. Any syntax errors in the current
program or error messages during uploading, etc., appear here.

With the symbols in the "Tools" area at the far right of the main window (4), tasks can be
executed quickly and directly. The buttons have the following functions:

• New File: Creates a new file in the editor


• Open File: Opens a file on the computer
• Save File: Saves a file
• Download and run: Upload code to the ESP board and run it
• Stop: Ends code execution. This corresponds to entering CTRL + C in the shell
• Connect/Disconnect: Connect or disconnect the serial interface. The serial port
can be selected under Tools -> Serial
• Undo: undoes the last change in the code editor
• Redo: Repeat last change in code editor
• Syntax check: Checks the syntax of the current code
• Clear: Deletes the shell / terminal window messages

In order to become familiar with writing a program and executing code on the ESP32, a
short Python program will be developed and executed below, which makes a LED flash. The
first step is to establish communication with the ESP board:

1. Select the current board via Tools -> Board


2. In Tools -> Port select the COM-Port to which the ESP-Board is connected
3. The Connect button then establishes serial communication with the ESP32
module
4. After a successful connection to the board, ">>>" is displayed in the shell
window.

Now a print command can be entered to test whether the communication is working cor-
rectly:

>>> print ('test')

The answer

Test
>>>

appears in the terminal window. When the message is displayed, everything is OK. Other-
wise, check that serial communication with the board is established and that the MicroPy-
thon firmware has been flashed successfully to the board.

● 25
MicroPython for Microcontrollers

Now a LED flashing script can be created. The following steps are required for this:

1. The following program is entered into the Editor window of the file main.py,
which was created above:

from machine import Pin


from time import sleep
led = Pin(2, Pin.OUT)
while True:
led.value(not led.value())
sleep(1)

2. By clicking on the "Stop" button, a script that may still be running can be stopped
3. With a click on the button "Download And Run" the script is written to the con-
troller
4. The shell window should now show the message "download ok".

Figure 3.7: Successful download of the first program.

Now the integrated LED of the ESP32 board should flash every second. This means that
the first Python program was successfully transferred to the controller and executed im-
mediately.

● 26
Chapter 3 • Programming and Development Environments

Figure 3.8: Internal LED at port 02 in action.

Some boards do not have an integrated LED. In this case, an LED including series resistor
must be connected to the controller (see, for example, Figure 4.6 and Figure 4.7). Further
details and information on the flashing program and on connecting external LEDs can be
found in Section 4.4.

3.4 For professionals: Working with esptool


If problems occur with the µPyCraft-IDE or if other reasons stop you from using it, you can
also load the MicroPython firmware onto the controller with the help of a utility called esp-
tool.

It is then even possible to transfer programmes to the controller via a terminal such as PUTTY
or TeraTerm. However, this method already requires some in-depth knowledge of the com-
mand line interface or the device manager. This procedure is therefore less recommended
for beginners. Nevertheless, the method will be described here, as it also provides further
insights into the handling of the controller programming. In addition, the methods presented
here can also be easily transferred to Linux or UNIX systems.

In order to work with esptool, Python 3.7.X or a newer Python installation should be installed
on the System System. The current version of esptool can then be downloaded to the com-
puter via a terminal window using

pip install esptool

With some Python installations, this instruction may cause an error message to appear. In
this case, the following instructions may lead to the destination:

pip3 install esptool


python -m pip install esptool
pip2 install esptool

● 27
MicroPython for Microcontrollers

Now the esptool file should be installed in the standard directory for executable files. To
access the controller, its serial port number must be known. This can be found in the Device
Manager:

Figure 3.9: The COM port of the ESP32 in the Device Manager.

In the figure, the port number is COM3, for example. This allows the following command to
be executed in the terminal window:

esptool --port COM3 flash_id

This provides information about the ESP32 system connected to that port:

Figure 3.10: Information about ESP32.

The lines

...
Detecting chip type... ESP32
Chip is ESP32-PICO-D4 (revision 1)
Features: WiFi, BT, Dual Core, Embedded Flash

● 28
Chapter 3 • Programming and Development Environments

Crystal is 40MHz
MAC: d8:a0:1d:40:54:14
...
Device: 4016
Detected flash size: 4MB

thus provide important information about the chip type, the board, the available interfaces,
the crystal frequency and the available flash memory.

Now you can use the instruction

esptool --port COM3 erase_flash

to erase the flash memory of the chip.

Figure 3.11: Successful erasing of the flash memory.

This clears the way for uploading the MicroPython firmware. The download of the firmware
from the internet was already described in the last chapters. The command for the upload is

esptool --port COM3 --baud 460800 write_flash -fm dio 0x1000


C:\Users\Documents\workSpace\esp32-xxxxxxxx-vx.x.x.bin

Of course, the correct path where the esp32-20xxxxxx- vx.x.x.bin file is located must again
be specified here. After a few seconds, the upload should be finished:

● 29
MicroPython for Microcontrollers

Figure 3.12: Upload of the firmware is completed.

Now you can contact the ESP via PUTTY or TeraTerm. The baud rate must be set to 115200:

Figure 3.13: MicroPython reports to the TeraTerminal.

A first Python program can already be loaded via the terminal, for example:

from machine import Pin


import time
p23 = Pin(23, Pin.OUT)
while True:
p23.value(1)
time.sleep(1)
p23.value(0)
time.sleep(.1)

● 30
Chapter 3 • Programming and Development Environments

Figure 3.14: Programming via TeraTerminal.

After the program has been transmitted, an LED connected to port 23 should flash at a
1-second rate.

The console offers the usual help system, which can provide useful information if neces-
sary:

Figure 3.15: Help function in the terminal.

● 31
MicroPython for Microcontrollers

3.5 Thonny — a Python-IDE for beginners


Thonny is a good alternative to uPyCraft. Although even this programming environment is
not yet completely bug-free, you can generally work well with it. In addition, the system
is constantly being updated and improved, so this flaw will also be eliminated in the fore-
seeable future. Thonny is also available for all common operating systems. Under Raspbian
for Raspberry Pi it is even installed by default. The installation is relatively simple, so there
should be hardly any problems in the installation process. A prerequisite for working with
Thonny is that the MicroPython firmware has already been loaded onto the ESP32. For be-
ginners, the use of the µPyCraft-IDE is recommended. Experts can also use esptool (see last
chapter) to bypass the µPyCraft-IDE completely.

The examples in this book were created with Thonny 3.2. In principle, future versions
should be compatible with it. However, in case of unexpected problems, you should return
to the version mentioned above. The appropriate package can be downloaded from

https://thonny.org

When the download is complete, you can run the installation file. Now you only have to
follow the assistant until the installation process is finished. Afterwards the Thonny-IDE can
be opened.

Figure 3.16: The Thonny-IDE after start-up.

Now the ESP32 board can be connected to the computer. To test the installation, Thonny
must be configured for the MicroPython interpreter. In addition, the board used must be
selected. The following steps are necessary for this:

1. Run → Interpreter opens the following window:

● 32
Chapter 3 • Programming and Development Environments

Figure 3.17: The options window in Thonny.

2. In the first selection window, select "MicroPython" (generic).


3. The COM interface of the ESP32 must be entered under Port.

Now the Thonny-IDE should be connected to the board and the shell window should show
the prompt ">>>". Alternatively the option "Try automatic recognition" can be selected.
However, this does not work reliably with all boards. Finally, the help() command is entered
into the shell. This will return a welcome message and some information:

Welcome to MicroPython on the ESP32!


For generic online docs please visit http://docs.micropython.org/
For access to the hardware use the ‚machine' module:

import machine
pin12 = machine.Pin(12, machine.Pin.OUT)
pin12.value(1)
pin13 = machine.Pin(13, machine.Pin.IN, machine.Pin.PULL_UP)
print(pin13.value())
i2c = machine.I2C(scl=machine.Pin(21), sda=machine.Pin(22))
i2c.scan()
i2c.writeto(addr, b'1234')
i2c.readfrom(addr, 4)

Basic WiFi configuration:

import network

● 33
MicroPython for Microcontrollers

sta_if = network.WLAN(network.STA_IF); sta_if.active(True)


sta_if.scan() # Scan for available access points
sta_if.connect("<AP_name>", "<password>") # Connect to an AP
sta_if.isconnected() # Check for successful connection

Control commands:
CTRL-A -- on a blank line, enter raw REPL mode
CTRL-B -- on a blank line, enter normal REPL mode
CTRL-C -- interrupt a running program
CTRL-D -- on a blank line, do a soft reset of the board
CTRL-E -- on a blank line, enter paste mode

For further help on a specific object, type help(obj)


For a list of available modules, type help('modules')

The installation and commissioning of Thonny has thus been successfully completed. The
hardware functions can now be activated via shell instructions. First of all the machine
module can be imported:

>>> from machine import Pin

Then, an LED connected to port 23 can be switched on via

>>> led = Pin(23, Pin.OUT).value(1)

Alternatively, the standard LED available on most boards can be used. Via

>>> led = Pin(23, Pin.OUT). value(0)

the corresponding LED is switched off again.

3.6 Working with Thonny


In the Thonny-IDE there are several different sections, among which are the editor and the
MicroPython shell or terminal:

• In the editor area, code is created and edited. Multiple files can be opened, with
a new tab available for each file.

• In the MicroPython shell, commands are entered that are to be executed imme-
diately by the ESP card. The terminal also provides information about the status
of an executed program, indicates errors related to uploading, syntax errors,
print messages, etc.

Other useful tabs are also available. These can be configured in the View menu. The "Var-
iables" tab in particular can often be used to great advantage. It shows all variables of a
program and their current values.

● 34
Chapter 3 • Programming and Development Environments

In order to become familiar with writing programs and executing code on the ESP32, the
already known script is used again, which makes the integrated LED of an ESP32 board or
an external LED blink.

At first a main.py file is created on the board:

1. When Thonny starts for the first time, the editor shows a file without title.
This file is saved as main.py. For this purpose, the file is saved via

file → save as

renamed to main.py and saved on the board ("Micro Python Device").

2. Now a tab named "main.py" is available.

3. The following code is entered here:

from machine import Pin


import time
p23 = Pin(23, Pin.OUT)
while True:
p23.value(1)
time.sleep(1)
p23.value(0)
time.sleep(.1)

The code is available in the download package for this book and can be used initially via
copy and paste. Later it is explained how files can be copied directly from the PC to the
controller.

Via the green arrow or

run → run current script

or by pressing function key F5, the code is transmitted to the controller. The following in-
formation is output to the shell:

MicroPython v1.9.4 on 2018-05-11; ESP32 module with ESP32


Type "help()" for more information.
>>> %Run -c $EDITOR_CONTENT

When the ESP is restarted, first the boot.py and then the main.py is executed. If boot.py
is not present, it is started immediately with main. So the program should become active
immediately after uploading, and the LED on the selected port (No. 23 in the example
above) should blink.

● 35
MicroPython for Microcontrollers

With some board variants, it may also be necessary to press the ESP EN / RESET key.

3.7 Working with files


To upload a file with a unique name to the ESP using the Thonny IDE, the following steps
are required:

• Creating a new file


• Save the file on the computer with the exact name, for example "blink.py".

The file can be opened as a new tab in the "This Computer" subwindow. It can then be
opened via the menu

file → save as

on which ESP can be saved under its name ("blink.py") The second selection "MicroPython
device" must be selected in the query (see figure).

Figure 3.18: Query when saving

The file is now uploaded to the board and appears in the sub-window "Files". From there it
can now be started with the green arrow key or F5.

Accordingly, it is also possible to download files from the chip to the computer by selecting
"This Computer". Other commands for deleting or renaming files etc. are also found in the
"file" menu.

3.8 Troubleshooting tips for the Thonny IDE


In the current section some error messages of the Thonny-IDE will be discussed. The cor-
responding problems are usually relatively easy to solve:

• In many cases, restarting ESP with the integrated EN/RST key is already
successful.
• Within the Thonny-IDE, communication problems between PC and chip can often
be solved by pressing the "Stop / Restart Backend" button (or CTRL-F2).

Otherwise, the following tips may help:

● 36
Chapter 3 • Programming and Development Environments

Error 1: No connection to the board.

In this case, the error messages are displayed:

========================= RESTART =========================


Unable to connect to COM4
Error: could not open port 'COM4': FileNotFoundError(2, 'The system cannot
find the file specified.', None, 2)

or:

========================= RESTART =========================


Could not connect to REPL.
Make sure your device has suitable firmware and is not in bootloader mode!
Disconnecting.

or:

========================= RESTART =========================


Lost connection to the device (EOF).

In this case it is often helpful to interrupt the USB connection to the module and then re-es-
tablish it. You should also check whether the correct serial port is set under

Run -> Select Interpreter

This error could also indicate that the serial port is already being used by another program
such as a serial terminal or the Arduino IDE. If this is the case, make sure that all programs
that may be communicating serially with the ESP card are closed. Then the Thonny IDE
should be restarted.

Error 2: Thonny IDE does not answer or gives an internal error.

After closing and re-opening the active window, you should be able to continue working
normally. If there are repeated crashes, the whole Thonny-IDE should be restarted.

Error 3: Thonny IDE no longer responds to the "Stop / Restart Backend" key.

After pressing the button "Stop / Restart Backend" you should wait a few seconds. The ESP
needs time to restart and restore serial communication with Thonny. If the "Stop" button
is clicked several times or very quickly one after the other, the ESP module does not have
enough time to restart properly. This may cause the Thonny IDE to crash.

Error 4: Problem when restarting the ESP card, running a new script or opening the serial
port.

● 37
MicroPython for Microcontrollers

If the following error message appears:

Brownout detector was triggered

or if there are continued reboots, or if the information:

ets Jun 8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)


configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:4732
load:0x40078000,len:7496
load:0x40080400,len:5512

is displayed, this may indicate a hardware problem. This is often caused by one of the fol-
lowing problems:

• USB cable of poor quality,


• USB cables too long,
• The ESP board has a defect, e.g. a bad solder joint,
• Faulty computer USB connection,
• The computer's USB port does not supply enough power.

In these cases, the use of a high quality and shortest possible USB cable will help. Changing
to a different USB socket on the PC can also be helpful. For laptops, an active USB hub with
its own external power supply should be used. This way you are no longer dependent on
the performance of the laptop USB power supply.

If the problems persist or other strange error messages appear, it is recommended to up-
date the ESP board with the latest version of the MicroPython firmware. This will at least
prevent errors that have already been corrected from making work more difficult.

Error 5: No connection between PC and ESP32.

It may happen that the controller is too loaded to establish a USB connection. In this case,
clicking the button "Stop/ Restart Backend" several times may bring the desired success.
However, this repeated clicking should take place at certain intervals (see above).

When running a script that uses Wi-Fi, switches to sleep mode, or performs multiple tasks
in parallel, it is recommended that you try to establish communication three or four times.
If this is still not possible, the ESP should be flashed again with the current MicroPython
firmware.

● 38
Chapter 4 • First Steps in Programming

Chapter 4 • First Steps in Programming

Python has been one of the most frequently used programming languages for several
years. One of the reasons for this is that it was very simply designed and is therefore easy
to learn. The development of MicroPython makes the programming of microcontroller sys-
tems comparatively simple and straightforward. This makes the programming language also
very suitable for beginners in the world of embedded systems.

The developers of MicroPython have set themselves the goal of making the programming
of digital electronics as easy as possible. In this way, the largest possible circle of users can
be addressed. Python programs can be found in the hobby area as well as in education
or scientific use. But professional developers too, increasingly work with Python. In the IT
industry, numerous market leaders such as Google or Amazon have been using Python for
their software developments for a long time.

In addition, freely available modules and libraries such as MatPlotLib, NumPy, SciKit or
SciPy provide extensive possibilities. These range from scientific data analysis to machine
learning and artificial intelligence.

MicroPython was developed as a slim version of Python 3. Since the language has to be in-
terpreted, it is generally slower than compiled systems. MicroPython was designed to work
as efficiently as possible on small embedded systems. Therefore it can also be run on micro-
controllers which are much slower clocked and have much less memory than typical personal
computers.

A disadvantage of classical Python programming is that low-level controls are very difficult to
implement. For this reason, the classic Python variants are used rather secondary in hard-
ware-related programming. This shortcoming is largely eliminated by MicroPython. Based on
the standard, the Micro version is also strongly based on Python 3 in its syntax. In addition
there are virtual machines and the associated libraries.

If one compares the two most popular programming languages in the microcontroller envi-
ronment, one finds that Python is more often preferred over C/C++. In the rankings of the
most popular programming languages, Python more and more often reaches the first place.
The competitor C/C++, on the other hand, is increasingly being relegated to lower ranks.
The reason for this development is mainly based on the following advantages of Python:

• Python is very beginner-friendly due to its simple language structure.


• Various internet forums support the programmer with tutorials and example
codes.
• There are extensive libraries available.

Beginners usually find solutions to their problems quickly in the forums. In other languages
this form of mutual support is not as pronounced.

● 39
MicroPython for Microcontrollers

In C, programming is done via control registers, pointers and other structures and instruc-
tions that are often difficult to understand. The firmware for the target controller must be
programmed, compiled and finally transferred to the controller with a programming device.
MicroPython integrates all these steps. With a simple mouse click, users can control low-lev-
el hardware such as LEDs, displays, or motors. The acquisition of analogue voltage values
or working with SD cards becomes child's play with the appropriate libraries. Integrated
memory cleaning and a dynamic allocation process enables efficient memory management
in Python. This means that you hardly need to resort to pointers or similar constructs, which
are usually difficult for beginners to penetrate.

The often-cryptic C-symbols like x++, <<, >> etc. as well as the complex variable declara-
tion represent a hurdle for the beginner which should not be underestimated. Python is known
for its simplicity and the excellent readability of the code.

Since MicroPython was developed as a "light version" for microcontroller applications, not
all libraries and functions of standard Python are supported. Nevertheless, you can easily
switch to the micro version if you are already familiar with Python. Only a few syntactical
structures or instructions are not available or applicable in MicroPython.

Python is interpreted. This means that the original program code is processed directly by the
target processor. Compilation is therefore not necessary. Python therefore offers the possi-
bility to execute a program once written on a wide variety of systems. For this purpose, only
a corresponding interpreter must be installed. One of the biggest advantages of Python code
is its comprehensive compatibility. Python programs can be executed on classic computers
under Windows, MacOS or Linux as well as on small single-board systems such as the Rasp-
berry Pi or comparable microsystems. Especially the use on the "RPi" (German: "Raspi") has
also contributed to the increasing popularity of Python.

With new powerful controllers such as ESP32, it has now even become possible to use Py-
thon efficiently and conveniently in this area as well. Firmly integrated constructs ensure
that programs can be easily developed on both a small and large scale. Python is therefore
excellently scalable. The possible encapsulation of data and program code in clear, usable
modules, i.e. objects, makes Python an object-oriented programming language. C++ is
generally used nowadays, especially in hardware-oriented programming. Classical Python
variants were not well suited for this purpose until now. With MicroPython this gap is now
closed.

C++ includes client applications as well as powerful server applications, device drivers and
embedded driver components. The area of application ranges from system software to ap-
plication programming. Since Python is a relatively new programming language compared
to C, it has not yet found universal use in all areas of information technology. However, it can
be seen that Python is gaining ground in practically all areas.

The main disadvantage of Python is certainly its comparatively low processing speed. Here
compiled languages like C can clearly show their advantages. Fast control loops or real-time
systems, vehicle controls and safety enquiries can be realised much easier and safer in C.

● 40
Chapter 4 • First Steps in Programming

Since these areas of application hardly play a role for non-professional users, though, the
speed disadvantage is hardly significant.

Python has also gained special importance in the highly topical field of artificial intelligence
(AI). Through extensive libraries such as NumPi, SciPi etc. and distributions such as Anacon-
da, Python has become the most popular programming language by far. All doors are there-
fore open for the experienced Python user. From hardware-related controller programming
to AI applications — with Python there are no limits to intuition and creativity.

In this chapter the basics of MicroPython will be compiled. You should have a functional
programming environment available, because the commands and instructions are always
illustrated with practical examples. These can then be immediately tested directly on the
target hardware, i.e. the ESP32. This does not remain a purely theoretical programming
course, but the knowledge acquired can be immediately put into practice.

4.1 Never without: Comments


Explanatory comments are important in any programming language. This is the only way to
know months or years later what a certain program section does, without having to delve
into old details over and over again.

It is not necessary to comment each program line individually. Experienced coders should
be able to understand individual instructions without comment. Only in the case of special
constructs or unusual or innovative lines of code is a single line comment recommended. For
subprograms or whole logical program sections on the other hand, a short explanation of how
they work should not be missing.

Simple comments will be introduced with the # sign. They begin with # and end with the
end of the line:

>>> print("hello ESP32") # this is a comment


hello ESP32

Multi-line comments can also be marked with a triple double-quate (") character ("""). The
same character string then ends the comment:

"""
first comment line
second comment line
"""

In practice this may look like this:

'''
This is a multi-line comment.
Prints "hello world".
'''

● 41
MicroPython for Microcontrollers

print("hello world")

Alternatively, the commentary function can be used in Thonny. It allows to mark several
lines as comments at the same time with the # (hash) sign.

Figure 4.1: Comment function in Thonny.

The commentary function is also very suitable for commenting-out certain parts of the pro-
gram. If, for example, when testing a more extensive code, certain sections are not to be exe-
cuted on a trial basis, these can be marked with comment signs. The lines are then no longer
observed by the interpreter. This makes a time-consuming deletion and later reinsertion of
the program sections unnecessary.

Comments help beginners in particular to gain a better understanding of the program


structure. From the technical point of view the interpreter ignores all comments, i.e. they
have no influence on the program flow.

4.2 The Print() statement


Information can be output to the terminal using the print() instructions. The command can
be executed directly in the terminal:

Figure 4.2: Print command in the console.

On the other hand, it is used in programs to output text-based information:

● 42
Chapter 4 • First Steps in Programming

Figure 4.3: Print command as program instruction.

print () can contain several strings divided by ",":

>>> print("hello", "world!")


hello world!

The print() statement performs a line break by default. With

end = ""

this can be suppressed:

print("hello", end=" ")


print("world")

and leads to the following result:

hello world

The following two illustrations illustrate the print instruction versions again in the Thonny-
IDE:

Figure 4.4: Print command as program instruction in Thonny.

● 43
MicroPython for Microcontrollers

Figure 4.5: Print command in the Thonny console.

4.3 Indentations and blocks


MicroPython distinguishes different blocks by indentation. It is not necessary to use curly
braces ("{}") or similar. This is one of the main differences to most other languages like C,
Pascal, Basic etc. The advantage of this method is that one is practically forced to a certain
degree of program structure.

if True:
# block 01
print ("True")
else:
# block 02
print ("False")

The number of spaces for indentations is variable, but the same block must always maintain
the same number of spaces for indentations.

Otherwise, an error message is displayed:

if True:
print ("Answer")
print ("True")
else:
print ("Answer")
print ("False") # The different indentation will lead to a runtime error.

This leads to the following message:

>>> %Run -c $EDITOR_CONTENT


Traceback (most recent call last):
File "<stdin>", line 6
IndentationError: unexpected indent

● 44
Chapter 4 • First Steps in Programming

In conditions and loops, blocks are formed in an identical way.

4.4 The hardware under control: digital inputs and outputs


Unlike programming on a PC or a laptop, MicroPython usually focuses on direct access to
hardware functions. Especially the control of individual input/output pins (I/O pins or GPIO
for General Purpose Input Output) is of central importance.

To test the instructions in practice, all you need to do is connect an LED with a series resistor
to the ESP32. The following figure shows the corresponding wiring diagram:

Figure 4.6: Circuit diagram for LED at port 25.

The structure of the circuit on a breadboard looks like this:

Figure 4.7: LED hooked up on port 25.

On the software side, a digital pin must first be initialized. For this purpose, a variable is
created which corresponds to the pin. This is not just a pin number, but a complete object
that knows all aspects of the pin. To use pins, the class "Pin" must be imported from the
module "machine".

From machine import Pin

● 45
MicroPython for Microcontrollers

After that, the initialisation of a single pin can already be done:

led = Pin(25, Pin.OUT)

The number 25 is the GPIO number. This is usually found as a printed circuit board number
near the corresponding pin. The instruction defines the pin as an output.

Figure 4.8: Pin numbers here (here 25 and 26) on the ESP board.

Now the pin can be used:

led.value(1)

This sets the I/O port to "1", i.e. it now carries a voltage of 3.3 V. If everything is connected
correctly, the LED on port 25 will light up after the command is executed via the console.
Resetting the pin to "0" (0 volts) will carry out the following instruction:

led.value(0)

Together with the sleep instruction (see also the following chapter) from the time module
you can now program a LED flasher (blink_simple.py):

# blink_simple.py

from machine import Pin


from time import sleep
led = Pin(25, Pin.OUT)
while True:
led.value(1)
sleep(1)
led.value(0)
sleep(1)

Due to the wait instruction

sleep(1)

the LED now flashes at one-second intervals, i.e. with a period of two seconds or a frequen-
cy of 0.5 hertz.

● 46
Chapter 4 • First Steps in Programming

Each I/O pin can also be used as a digital input. The corresponding initiation is carried out
via:

pin_in = Pin(25, Pin.IN)

This allows the level applied to the pin to be detected, i.e. 0 for 0 V and 1 for 3.3 V. An open
input, i.e. a pin without any wiring does not provide a reliable result. Interference signals
such as 50 Hz interference, WLAN or radio frequencies can change the level randomly. To
prevent this, so-called pull-up or pull-down resistors are necessary. With the ESP32 these
can even be switched on internally. Using

pin_in = Pin(2, Pin.IN, Pin.PULL_UP)

ensures that an unconnected input carries a high signal. Accordingly,

button_pin = Pin(2, Pin.IN, Pin.PULL_DOWN)

carries a low signal on an open input. With the following program the functions can be tested:

# read_pin_25.py

from machine import Pin


from time import sleep

pin_in = Pin(25, Pin.IN, Pin.PULL_DOWN)

while(True):
print(pin_in())
sleep(1)

In the circuit diagram the structure looks like this:

Figure 4.9: Capturing voltage levels.

● 47
MicroPython for Microcontrollers

In the hardware setup, a piece of wire can be used to test the circuit, which is connected
to GND or 3.3 V:

Figure 4.10: Hardware structure for reading voltage levels

Depending on whether the wire bridge is connected to GND (0 V) or 3V3, the value 0 or 1
appears in the terminal. If the input is open, 0 (for pull-down) or 1 (for pull-up) is displayed
in the terminal.

ATTENTION: Under no circumstances should the input be connected to 5 V. This could


lead to the destruction of the chip. The pins of the ESP32 may only be controlled with a
maximum of 3.3 V!

The 1-kΩ resistor is used to protect the input. This reduces the chances of unintentionally
applied excessive voltages causing damage. Still, you should always avoid applying voltages
above 3.3 V to an ESP32 pin.

4.5 Time control and sleep


In the example of the flashing LED, the delay instruction has already been used. This is con-
tained in the "time" module and is controlled by

import time

With the statement

time.sleep(seconds)

a fixed delay time in seconds can be set. Alternatively, only the sleep command itself can
be imported:

from time import sleep

● 48
Chapter 4 • First Steps in Programming

Then the instruction can be shortened to

sleep(seconds)

Although the command can also be used for fractions of a second, for very short delays it
is recommended to use

time.sleep_ms(milliseconds)

because it has a better precision for small times.

The disadvantage of these functions is that they work obstructively. This means that the
controller cannot carry out any other tasks during the waiting period because it is busy
counting processor cycles. An alternative is to use interrupts or other programming tech-
niques. Details are given in later chapters.

The following two routines are available for time queries:

time.ticks_ms()
time.ticks_us()

They indicate the current system runtime in milli- or microseconds. A classic application is
the measurement of program runtimes. With the following code it can be shown, for exam-
ple, that mathematical operations require a certain amount of time:

# runtime.py

import time
import math

while(True):
start = time.ticks_us()

# x = math.exp(math.sin(22.5))

stop = time.ticks_us()
print(stop-start)

If the comment sign is removed before the calculation, the displayed processing speed
increases from approx. 100,050 µs to 100,170 µs. The calculation time for the formula is
therefore around 120 µs.

● 49
MicroPython for Microcontrollers

4.6 Important values: variables and constants


In Python it is particularly easy to create variables. It is not necessary to specify the data
type of the variable during the assignment. This is a major difference to other languages.
There, variables must always be explicitly initialised with a certain type (e.g. int a =...)

Variables can also be used in the console:

>>> a = 17
>>> print(a)
17

The following rules apply to the assignment of variable names:

• The variable name should only contain numbers, letters and underscores.
• The first character of a variable name must be a letter or underscore.
• The variable name is case-sensitive.

Variables can be assigned values of different types. The types in MicroPython include num-
bers, strings, lists, dictionaries, tuples, etc. With type() the data type of variables and con-
stants can be checked, e.g.

>>> a = 17
>>> print(type(a))
<class ‚int'>

>>> a, b, c, d = 17, 1.5, True, 5+7j


>>> print(type(a), type(b), type(c), type(d))
<class ‚int'> <class ‚float'> <class ‚bool'> <class ‚complex'>

Numbers like 10, 100 or strings like "Hello World!" are constants. MicroPython offers the
keyword "const", which marks an unchangeable value:

from micropython import const

a = const(33)
print(a)

4.7 Numbers and types of variables


MicroPython supports the following number types

• Integer (int);
• Floating point (float);
• Boolean (bool); and
• Complex.

● 50
Chapter 4 • First Steps in Programming

A number object is created as soon as a value is specified. With del() you can delete the
objects again. In the console it looks like this:

Figure 4.11: Deleting variables.

It is also possible to assign values to several variables at the same time, i.e. separated only
by commas, e.g.:

a, b = 1, 2

The result of the division (/) always returns a floating-point value, e.g:

12/3 = 4.0

The integer format is equivalent to the numbers in mathematics, including signs:

1, 100, -8080, 0 , ……

Float corresponds to the real numbers. Scientific notation in exponentials can also be used:

>> a = 1.234e3
>>> a
> 1234.0

An important difference between integer and float is that integer values are stored exactly.
Float numbers on the other hand are rounded.

Variables of the type Bool can only take the two values "True" and "False". Here, too, a dis-
tinction is made between upper-case and lower-case letters.

The variable type "complex" is composed of a real and an imaginary part in the form of a
+ bj or complex(a, b). Both the real part a, and the imaginary value b can be floating point
numbers.

This also makes it possible to calculate with complex numbers:

● 51
Random documents with unrelated
content Scribd suggests to you:
Hen. Nay, Henry, love. The name you gave me first.
By that alone I'll live upon your lips.

Gla. I should be gay,—alack, I am half sad.


A sort of music here is gone. Mayhap
I loved my brother better than the king.

Hen. Thy brother? Call me that no more. My bride!


The sleeping angel I would kiss awake,
For waking thou art human and can love.
Ah, Glaia, none doth know how I have dreamed,
For kings must give up all just to be kings—
How oft at night I've left the palace world
To find me lodging in the sweeter air
Where spirits hold their gentle pageantries,
And meet the winds that blow from destiny
Pregnant with fortune for my famished soul,—
While they who stood about the royal bed,
Whose stealthful eyes held me in silken jail,
Knew not my body lay untenanted
And they but guarded clay. And everywhere
'Twas thee I sought, my Glaia. When you came,
I looked, and knew that I need dream no more.

Gla. And thou art no more sad? I make thee happy?

Hen. When I am with thee 'tis continual Spring,


For in my heart is such sweet jugglery
Each winter-ragged month doth put on May.

Gla. It makes me fear to be so much to thee.


O, Henry, leave me,—leave me here a child
That never shall be woman,—ne'er shall seek
The bitter knowledge of the human world.
[A fawn comes to her from the wood. She fondles it]
See, brother! I would ope no book less pure
Than these large eyes. Ah, me, was ever soul
So full of earth as mine? I can love nothing
But woods and streams, and these unspeaking things
That reasonless may build no dream of God.
My Henry, why this fear that if I go
My Henry, why this fear that if I go
From this dear world I'll come to it no more?

Hen. Cast off the doubt—and here I trample it.


We shall come often to this home of peace.
But, Glaia, let us go. The hours run fast,
And eve must find me at the court.

Gla. The court?


There does my rival in my lover speak.
There speaks my enemy, for in the court
I shall find that will make these fears all plain.

Hen. Fear nothing now! I see thou knowest how


To please me best, making me woo thee o'er
And o'er again, for naught could be more sweet!

[Exeunt. Curtain]

Scene 2. Room in Westminster palace. The earl of


Kent and countess of Albemarle talking.
Kent. Why do you doubt? You've ever trusted me.

La. Alb. Ay, while you were all man.

Kent. So am I now.

La. Alb. Nay, you are one half woman, being married.
A wife's the key may ope her husband's heart
To all the world. She is the pick and pry
To every lock of trust, and weasels through
His secrets spite all seals. Swear, Hubert, swear
That Margaret shall not know!

Kent. Have I not sworn?


How many times will you demand my oath?

La. Alb. A thousand thousand will not bring me peace!

Kent. Ah, Eleanor, why desolate your days


With this wild fear? 'Tis Heaven you've sinned against,
Not man. Look thou above for condemnation.
The world is harsh to virtue, not to sin.
See how the daughter of the earl of Valence,
John's one-time mistress, proudly holds her head,
Nor lacks for fawning followers? And mark
How Rosamond's two sons have fixed their line
Fast 'mong our English peers. If you would dare
To bring sweet Glaia forth, I do not doubt
The court would welcome her as princess born.

La. Alb. But Albemarle! He never would forgive!


Christine of Valence was not wife to him,
Else would her mimic court be dungeon close,
And racks, not lovers, kiss her dainty fingers.
You've never seen his rage! O, swear again
You'll set securest watch on act and tongue,
Nor let——

Kent. Here is your lord with Winchester.

La. Alb. O!
Kent. Come, I'll satisfy you, Eleanor.

[Exeunt, right. Winchester and Albemarle enter rear]

Win. The name of Kent erases church and state


And king. Fortune grows doting, and would make
A darling of this man.

Alb. She'll change her love,


Doubt not.

Win. 'Tis time. New favors upon him light


As birds on fruity branches. Castles and estates
Are but as feathers every wind brings in.
Dost not begin to fear him?

Alb. You are pleasant.


I fear? When I could lend him half my power,
And yet o'erbear him? In the north there are
One thousand leaders holding swords of me!

Win. I'm answered then?

Alb. Ay, sir. Though not from love


To Kent, nor hate to you, do I deny you.
But I'll not stand the champion of a wanton,
Though royal daughter of a royal sire.
The knightly Albemarles have never stooped
To lift adultery from its miry bed
And set its colors on their virtuous helm.

Win. Now, by your leave, the half of England comes


Into the world by left hand of the priest,
Yet fight and pray as well as you or I,
Nor bates a jot their honor in men's eyes.

Alb. You have my answer. When I'm ready for 't,


I'll tumble Kent to earth in my own fashion,
And not by means that sets French Adelais
On virtue's pinnacle, a star of gilt
To falsely glitter in the eye of dames
And set them wandering with their vanities
g
Till they forget the way to their true lords.

Win. [Musing] I'm writing a court history, your grace.


'Twas John, I think, who set your countess' father
On fortune's road.

Alb. Nay, 'twas the king before him,


Henry the Second.

Win. [Going] Well, my wary lord,


I have no bruise to nurse, and meet the blow
Befalls from any point.

Alb. What do you say?

Win. I say, my lord, I'll strike as pleases me,


And you keep cover as you will. [Exit]

Alb. A bruise?
Keep cover? Gods! And I stood still! The dog!
I'll after him and take him by the throat!

[Re-enter lady Albemarle, right]

La. Alb. What said our ancient enemy?

Alb. Enough!
He angered me!

La. Alb. But what the cause, my lord?

Alb. He'll quash the claim the church makes to my castles


If I will aid in bringing Kent to trial
On charge of Adelais, who sojourns here
To push her old appeal. I will not do 't!

La. Alb. Thanks that you shield my brother, by whose rise


You droop.

Alb. I shield your brother? When his name


Is Kent? Nay, you mistake me. I refused
Because this princess was no more nor less
Than Henry Second's mistress, and the son,
y , ,
Whose death is laid to Kent, was the vile fruit
Of wantonness. A princess! I'd forgive
A milkmaid false, but error in the great
Is so bestarred by its exalted place
That those beneath mistake what is so lustered
For the true sun.

La. Alb. Hast seen the king, my lord?

Alb. I say 'tis guilt of such a heinous sort,


So foully odorous and so far bestrewn,
The sea o'errunning Britain could not wash
The island free of it!

La. Alb. 'Tis very wrong.

Alb What! Set this princess over all your heads


As she were halo-browed, that you might pray
Her saintly patronage for your loose hopes?

La. Alb. Indeed, it is not well.

Alb. Well? By my life,


Our English dames are running mad enough,
And must be duchesses because—look ye—
They're wantons to a king! Out on your kind!
[Aside, slowly] "'Twas John, I think, who set your countess' father
On fortune's road." You've been a handsome woman—
Could foot right well on Venus' heels. My soul,
There's beauty in you yet to draw an eye
O'er the picket of defence!

La. Alb. My lord, I pray you——

Alb. 'Tis well that our young Richard has my eye,


And trick of walk, and way of sudden speech,
Else I'd suspect a cuckoo in the nest,
For all your dainty strictures and high head!

La. Alb. For Christ's sake, Albemarle——

Alb. Ay, had he not


M h ld hit h d lli k
My very shoulder hitch and swelling neck
This night I'd drag him to the eastern tower
And hurl him to the Thames!

La. Alb. My God!

Alb. For you


I'd pay out my estate in hire of men
To spend their lives devising drawn-out pains
That death might feed and grow upon itself!

La. Alb. Ah, sir, no need. I'm dead now with your words.

Alb. The king is entering. Look up, my dame.


I rage to think you could be false, and not
Because you are. Come, where's your blood, my lady?
Those frosted cheeks are not the royal color.
Smile and I'll pardon you. I know you true.
[Aside] But when we're home again we'll talk somewhat
Of those same favors granted to your father.

[Enter Pembroke, Winchester, and others. Pembroke and Winchester talk


apart]

Pem. But where is Gualo? He is friend to Kent.

Win. Shipped back to Rome.

Pem. Well done!

Win. That is made sure.


And now I'll push the claim of Adelais
With all the power pillared by the church.

Pem. Henry will never yield. He wraps the earl


So close in love 'twill shake the throne to part them.
There's no path to the king not barriered
By Kent's unceasing watch.

Win. I'll drop a canker


Will eat a way for us. Ah, here they come.

Pem. Arm-locked as king and king; and eye to eye,


Like lovers changing souls.

[Enter Henry, Kent, Lord Wynne. Lords and ladies, among whom is
Margaret, enter behind them]

Hen. [To Kent] I fear to tell you, Hubert, even you.

Kent. I do not fear to hear it, whate'er you do


So well becomes a throne.

Hen. You promise then


Your fullest pardon?

Kent. Your open deeds, my lord,


Bear such a noble front I should not fear
To clap a lusty "ay" to all you've done
In secret.

Hen. Thank you, Kent. And Roland, too,—


Our good lord Wynne—must echo you with pardon,
For I have touched him when he felt me not,
And shortly he must look upon his wound.

Wynne. I do not fear to see it. You've taught me, sir,


The wounds you give me carry their own heal.

Hen. But this is deep.

Wynne. The richer then the balm.

Hen. Then out, poor Henry, with thy heart's misdeed.


[Turns to the court]

Listen, my lords,—my gracious court,—to you


I make appeal. Is any here who holds
Me in such wintry and removed regard
He would not grant my heart its choice in love?
[Surprise and silence]

Win. Your wisdom, sire, that sets the cap of age


Upon the curls of youth, gives us excuse
To bid you choose at will your royal mate.
If I speak not for all, we'll hear dissent.
p ,
[Silence]
This silence warrants you to woo and speed.

Hen. That I have done, and now can show to you


This jewel of my choice that late I found
Deep hidden from the world. So fixed my love,
I can not wait to wander through the ways
A king comes to betrothal, and shall win
Your quick assent, even now, by bringing her
To your commending eyes.

[Exit Henry]

A lord. What does he mean?


Is this some princely revel?

Another lord. It may be,


And our part is to smile.

Win. [To Pembroke] Mark you earl Kent?


He changes face.

Pem. And his pale friend, lord Wynne,


Turns corpse on 's feet.

Win. Ha! Is it possible


They were not privy to this kingly move?
[Re-enter Henry, leading Glaia]

Hen. Here, dear my lords! Look on my choice and say


That here might come Rome's vestals to repair
Their tapers dim. Is she not royal, friends?
See how her eyes look bravely into yours,
Though on her cheek a sweet timidity
Doth couch in coral. Now commend me, all!
And Hubert, earl of Kent, say whence is she,
And what her parentage? For all I know
Is that I found her bowered in Greenot woods.

Kent. My God!

Hen. O, Hubert, muffle up the storm


Rid b d il l !
Rides on your brow, and smile upon my love!

Kent. Believe me, sire, she can not be your wife.

Hen. Not be my wife? Unsay the words, dear Hubert.


You mean, perhaps, she's humbler born than I—
The daughter of a duke—an earl—a lord—
Ay, say a knight that bravely bore his shield,
And all the gap 'twixt her degree and mine
Her native graces will bridge o'er and make
Her way unto my throne.

Kent. [Kneeling] O, king beloved,


You must believe me! She can not be yours!

Hen. Then, Heaven, turn foul, thou dost not shine for me!
Rise, Hubert, rise, for I must love you still,
Though you have robbed me of the sun and stars.

Kent. [Rises] My noblest sovereign!

Hen. Now let me hear


Why this ne'er mated dove can not be mine,
And I'll attend thee patient as the dead
Do list their requiem.

Kent. Sire, I am pledged.


Such sacred oaths are warders at my lips
That angels would turn pale in Heaven to hear
Their violation.

Hen. Oaths? We must not hear?

Kent. Not from my lips. It may be from another's


In better time.

Hen. In better time? By Heaven,


You shall uncover here her history,
And I myself shall say if she may be
My own or no!

Kent. Thy mercy on a man


In one hour old!
Hen. You are the torturer!
O, Hubert, Hubert, I am on my knees!

Kent. Sire, give me leave to go, and take this maid,


So long my care that I must keep her still.
Come, Glaia—child—'tis Hubert takes thy hand.
My sovereign lord, I go with sorrow hence.
I would my tongue were torn from its curst root
Than speak you woe,—but do not hope, my liege,
Your husband hand can ever touch this maid.
The thought to ague shakes my soul!

[Exit Kent with Glaia. Margaret would follow, but is detained by lady
Albemarle, who is half swooning. Winchester kneels and kisses
the king's robe]

Win. My king,
Thou'rt still beloved.

Hen. Ah, what canst say to one


So pinioned by distress that he must lose
His dearest friend or dearest love?

Win. My lord, if friendship may have leave to speak


As fits its holy bond and name——

Hen. O, speak!
Say anything!

Win. Too long you have been wronged.


Did not Kent win by stealth the Scottish princess,
Your promised bride? Consorting his base blood
With royalty?—which was his secret aim,
And all his burning love for Margaret
But feigned and politic to gain your pity.
Again he's at your heart! And hopes once more
To bear himself to high success. If not,
With face assumed and sorrowing he'll melt
You to forgiveness.

Mar. Listen not, my liege!


Hen. [To Winchester] Is this your comfort?

Mar. Sire, he slanders love


As true as God's to men, who says my lord
Is false!

Win. Her pride would say as much, my liege.


As for this maid,—whom majesty might choose,
And all the kingdom feel itself adorned,—
She's either heir to vast and rich estates,
Or Kent dotes on her with such jealous love
He will not yield her even to his king.
And both these reasons, sire, I urge as one
T' explain his stout refusal to make known
What honesty would haste to shout aloud.

Wynne. Who says that Kent, in friendship or in love,


E'er sought his gain, doth foully lie!

Win. This man


Is Kent's own creature.

Hen. Ah, that's not his sin.


He loves my Glaia, and would make her his.

Wynne. Yes, sire, I love her,—you are right so far,—


But, sovereign lord, I would expect as soon
To pottle with an angel at an inn
As make her mine. Though Hubert spurred my suit——

Hen. He favored you!

Wynne. He set no bars between us.

Hen. Ah, you could wed her—let the king go beg!

Alb. Away, you perked-up villain! Out of this!

Wynne. When you come with me, sir, that I may slit
The tongue that fouls my name!

Alb. My hot-mouthed sir,


I'll l hi j h b
I'll leave his majesty to teach you better manners.

Hen. And here I do, with a ne'er-ending lesson.


Roland de Born, so lately lord of Wynne,
Thou'rt banished from our realms, not to return,
Though thou shouldst live to see more years than yet
Man ever numbered his.

Wynne. Is this your will?

Hen. In truth, 'tis nothing else!

Wynne. Then, sire, farewell.


Some men are fashioned men by circumstance—
Shaped by what wind blows on them. In their veins
The heavens croak or sing. Does the sky frown,
They're muddy and befouled,—it smiles, and straight
Fair weather's in their blood, sporting its flag
In their new countenance. Not I, my lords!
Nay, on the winds my soul shall leave its shape,
And where I venture I am what I am,
A knight of England, loyal to his king. [Exit]

Alb. Death to his arrogance!

Pem. This judgment, sire,


Is much too modest.

Win. Hear us now, my liege,


For you have heard too little these months past.

Hen. My lords, I am too faint and troubled now


To understand if you be friends or foes,
Or if the earl of Kent be false to me;
But come, and what you choose to speak, I'll hear.
... Glaia, art gone from me? Ah, who would live?
The winds of doom are sold by Lapland witches,
Who mix the compass points and blow us foul
When we have paid our fortune to go fair.

[Exeunt Henry and lords. Lady Albemarle and Margaret are left alone]

Mar Why do you keep me so?


Mar. Why do you keep me so?

La. Alb. Where would you go?

Mar. Where else but to my lord?

La. Alb. You shall not go.


O, stay with me! One moment, Margaret!

Mar. Another? Nay, you're better. I must go.


O, Eleanor, didst hear that Winchester?
Foul murderer of honor—Hubert's honor!
Can these be tongues of men?... And Roland banished!

La. Alb. Canst think of him?

Mar. He's Hubert's friend. Who now


Will stand by him?

La. Alb. You, Margaret, and I.

Mar. Yes—let me go!

La. Alb. What will you say to him?

Mar. Beg him not let his bitter thoughts usurp


Quite all his heart, but leave a little room
That e'er so small will make me ample heaven.

La. Alb. You will not ask of Glaia?

Mar. Ask? Dost think


That I must ask?

La. Alb. He will not tell thee!

Mar. Not?
I am his heart. His veins run not with health
Except as I know how they course, and beat
Concordantly. Doubt not he'll tell me all.

La. Alb. He shall not tell thee!

Mar. Madam, you are strange.


La. Alb. Ay, Margaret, and strangest to myself.
O, he is true! Dear God, I know he's true!

Mar. Make it no question then. For by the sun,


And heaven's starry clock that now goes by,
You shall not say he's false to Margaret!

La. Alb. To you? Ha! false to you? Dost think my thoughts


Must ever web round you?

Mar. [Going] You are his sister.

La. Alb. What, are you gone? Forgive me, Margaret.

Mar. Ah, you forget that I am suffering too.

La. Alb. You suffer? You?

Mar. You have a husband, madam.

La. Alb. I have. Let me remember him. Ha, ha!


You suffer, icicle? What do you know of pain
But as the lookers on about a pit
See one at bottom dying? As curious eyes
Regard the writhing heretic at stake?
Or say, as angels flying heavenward turn
To give one grudged tear unto the damned?
That is your pain, you pure, proud Margaret!
... O, madness, seize me!

Mar. By my fears you have


No need to pray for 't.

La. Alb. Conscience, where dost sleep?


Let me tread by nor rouse thee.

Mar. Eleanor?

La. Alb. Whence are those floods of fire? O, Hubert, save me!

Mar. Dear Eleanor, be calm. I did not think


You loved your brother so.
La. Alb. What's that you say?
Ah, yes, 'tis Margaret. Go to him now.
Ask of this maid—then blazon all—all—all!

Mar. Come with me, Eleanor.

La. Alb. Drive home the knife


Now threats his heart!

Mar. Come with me, come!

La. Alb. 'Tis fit


His wife should do it!

Mar. Come, dear Eleanor.

[Exeunt, right. Henry, Winchester, Albemarle, Pembroke, enter rear]

Win. We're glad you are convinced, my lord.

Hen. Glad, sir?


Glad that one half my heart is mottled, foul,
Diseased, and must be cut away, though I
Die with the cleaving? Ay, I am convinced.

Win. And give consent that Kent be made to answer


The charge of Adelais?

Hen. Be 't as you please.

Pem. 'Twere best to haste in this, ere all the shires


Misled in love by Kent, hear of his danger.

Win. I have the warrant here. It lacks your seal,


My liege.

Hen. [Quickly sealing it] Now it does not. Here splits my heart,
And half falls with thee, Hubert.

[Winchester comforts him. Albemarle and Pembroke talk apart]

Pem. In fewest words,


What purpose you?
What purpose you?

Alb. To ride at once to north,


And through my agents stir up a rebellion
Against the king, whom we must make appear
Kent's sole remover, for he now 's become
The idol of the witless multitude,
With whose hot sanction we may move 'gainst Henry
And roll his head as fast as Kent's to hell.

Pem. But you must see the trial.

Alb. So I aim.
But if I'm blocked therein, I look to you
To keep me stationed in my feudal rights,
And what you venture for me I'll make good
With forty thousand men, or horse or foot.

Hen. Where is lord Wynne? Inquire if he has gone?

Alb. He'll trouble you no more, for if my servants


Be to me loyal they've set him toward the sea.

Hen. You're pert in my own matters. I bethought me


I would recall his sentence. He is noble,
And I have done him wrong. Why press about me?
Ye are devils all! Call me the earl of Kent.

Win. He is not here, my lord.

Hen. Give me the warrant.


Quick, sir! I'll have it back! I'll take more time!

Win. 'Tis gone, my liege.

Hen. Gone? Is the devil your post?

Pem. We pray your pardon, sire.

Hen. Could you not give


One little hour to old friends taking leave,
Though one is a poor king? Away from me!

Win Dear majesty beloved above all kings


Win. Dear majesty, beloved above all kings,
Let not your frown unpay again the service
Your smile even now rewarded. 'Tis too much,
Howe'er we have endured, to ask our silence
While Kent doth rob thee of a fairer queen
Than ever made a court seem gaudy poor
By her rich self. Must we stand humbly back,
That he may please his bosom with her beauty,
And bury in his lust what forth should shine
Thine and a happy England's constant sun?

Pem. No doubt, my liege, we shall remove each bar


That shuts you from your love, and please ourselves
The most in pleasing you.

Hen. O, make her mine,


And all you wish, if kings have power o'er fate.
Will come to pass. I trust you—yet—and yet—
Who can be true when Huberts are found false?

[Curtain]
ACT II
Scene 1. A room in the earl of Kent's palace. An inner
room rear, cut off by curtains. Kent alone.
Kent. Now, Eleanor, wilt prove thee saint, or devil?
Wilt mend this breach, or must I perish in it?
Too well I know that soul's dark history
To think it may breed light. The moment globes
The years' full character; a whole life's face
Peeps out in smallest deeds. Yet wonders are.
And Eleanor may prove false to herself
To once keep faith with Heaven.
[Listens] Glaia? Ay!
[Goes to curtains rear, parts them softly, looks within and returns]
She did not call. I'll watch all night. 'Twill be
No added task since there's no sleep for me.
My Margaret is safe. They dare not touch
A princess of the blood. But I am down.
'Tis said and sung there is no greater pain
Than wrenches Fortune's nurslings when she flies.
Not so. False lady of the wheel, take all!
But O, to see my king yield to the wolves
Now fang-close to his heart—there is my death!
[Sits on a couch, his head bowed. Margaret enters, advances softly
and embraces him. He looks up, returning her caress]
Now let the world go on, I'll rest me here.
Why should I keep my hand proud on the helm,
War with the unsated surge, nor know the pause
That is the spirit's silent growing time?
Ah, Margaret, how little will content thee?
No more nor less than love and poorest me?

Mar. No more, my lord. Nor will aught less make full


My greedy cup. Thou wert the king's, but now
Thou art all mine. All mine, my love? Or is
That little "all" my greatest flatterer?

Kent. You know my heart. Where have you been so long?

Mar. With Eleanor. I brought her home with me.

Kent. She's here?

Mar. Yes, Hubert. Ah, she loves you well.


Kent. She loves me?

Mar. Better than you thought.

Kent. [In sudden hope] Then ... Speak!


What has she told you?

Mar. Nothing. What, my lord,


Should she have told me?

Kent. [Dully] Nothing.

Mar. I have heard


So much of this—this nothing.

Kent. Margaret,
Thou hast my soul. Wilt keep it true for me?

Mar. I keep it? No, I doubt myself.

Kent. Thyself?
Then trust my trust in thee, which meets thy love
As swallows meet the waking winds of Spring
And know where life is.

Mar. Doubt or trust, I love thee!


O Hubert, let us go this night to lands
That know how to be kind and smile on lovers.

Kent. Dost hope by flying England to fly pain,


That everywhere encircles man as fire
To shape his soul in fashion of his God?

Mar. For love and life I beg! Why do I say


For love and life, since there's no life for me
Without thy love? O, you will go with me!
Leave thy ungrateful king to wed at will——

Kent. Leave Glaia to the king? The thought is flame!

Mar. [Standing before him, suddenly tense]


Who is this maiden that you guard as she
Were the one drop of blood that in your heart
p y
Makes living centre? Who?

Kent. [After a pause] You heard my answer.

Mar. Ay, to the king, but not to me—thyself—


Nay more, for when thou takest away thyself,
Though in the smallest part, so much I die,—
And by this secret that divorces us
Am wholly slain. But tell it to me, Hubert,
And 'twill become another blessed bond,
To second union closer than the first
Re-sanctioning our souls.
[He is silent. Her rage overcomes her]
Unseal thy lips,
Or by the fires that flit now through my brain,
By the ancestral wrongs within my blood
That start suspicion where there is no foe,
I shall begin to doubt thee! Who is she
To thee who art my husband?

Kent. Margaret,
Go to the maiden lying yon and look
Once more upon her vestal face, then ask
If she know aught of guilt.
[Margaret looks silently toward the curtains]

Mar. [In subdued tone] She's there?

Kent. Poor child!


I thought you'd be her gentle, elder sister,
And help me still her woeful flutterings.
[Turns away]
Where's now the proud, sure strength that made discount
Of Heaven's arm? O, reed-propped vanities,
Swelling usurpful till ye seem our life,
Ye must come down that we may find ourselves
And God.

Mar. O, take me back! I did not know


This spirit dwelt in me. One of my race,
A woman, long ago, stabbed through a heart
That played her false yet she was gentle too
That played her false, yet she was gentle too,
And died for what her hand had done. May be
The unquiet dead come back to live in us.
O, it was she stirred this strange passion in me.
Twas not myself. Speak to me, Hubert! Say
'Twas not myself.

Kent. [Embracing her] Sole angel of my love!

Mar. You'll take me back? Let Time begin his count


One minute past, and leave the last one out.
O, say a word will sponge it from the day,
Or all my future must turn back its face
And live with gazing on that minute's point.

Kent. It was not you, my heart. But say it were,


Should I pull down my heaven because a bird
Makes flying blot against it? 'Tis the doubts
That darkly flitting show love's constant sky
Forever radiant.

Mar. O me! O me!


And this is shame!

Kent. Nay, sweet! Weep, if you must,


But let thy tears be rain upon the soul
Making a fair new season.

Mar. Let me die!

Kent. So overwrought? Thou who hast been my strength?

Mar. If I were dead then you——

Kent. Should be as thou!


'Tis not thy death but Glaia's that would be
The sad solution of these woes.

Mar. Not her,


So fair ... and dear to us.

Kent. [Kissing her] My gentle love!


... 'Twere best she died, who now must drink the cup
Th t k d th ti i I lf
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookbell.com

You might also like