![]() |
![]() |
ESP8266 cost: 2.21 Euros |
ESP32 cost: 4.1o Euros |
![]() |
![]() |
ESP8266 | ESP32 |
to the GPIO pin numbers
The pins in the white fields go to the WeMos D1 mini bus
and are also available on the ESP8266
The other pins are only accessible on the ESP32 CPU card
The pin numbers Dx do not correspond to GPIO pin numbers!
Please refer to the next slide for correspondence
|
![]() |
![]() |
Several development tools are available:
Please see:
see: https://docs.espressif.com/projects/esp-idf/en/latest
see: |
We can however also execute esptool directly.
First we need a Micropython interpreter!
You find the sources here:
https://github.com/micropython/micropython/
In the repository you find ports for the ESP8266 and the ESP32.
In order to compile the code you need the ESP-IDF and its cross compilers
The code compiles into a binary file (firmware-combined.bin) which contains a boot loader and the interpreter.
This binary must be uploaded and flashed.
For documentation of the ESP8266 port of Micropython look at
https://docs.micropython.org/en/latest/esp8266/tutorial/index.html
We use a serial connection passing through the micro USB connection.
As soon as we connect the processor card to the PC we see the
UART bridge and a new device: dev/ttyUSB0 is created.
This device is used to communicate with the Micropython REPL.
You see the command prompt and you can interact with Micropython. But … how to upload scripts?
You see the command prompt and you can interact with Micropython.
But … how to upload scripts?
uPyCraft is a rather complete Integrate Development Environment (IDE)
which lets you
This has already been done for you! However, it is easy if you want to do it
at home with a new processor board.
Compiling a new version of Micropython is substantially harder but also perfectly possible.
uPyCraft is based on QT4 and is available for Linux, Windows and Mac.
It is written in PyQt4 the Python language binding to Qt4.
The Linux version did not work for me when running Ubuntu 18.04 or later.
I found a version based on PyQt5 (new version of QT) which was even worse.
I tried to correct as much as I could to make the PyQt5 version usable on Linux:
https://github.com/uraich/uPyCraft-Qt5
Thonny is an IDE for Python which has provisions for Micropython.
Under Tools → Options button you can select the type of
Python interpreter you intend to use.
A “Hello World” program, just printing “Hello World” on the screen
does not look very exciting.
However, this is generally used to verify that the infrastructure
Compiler, linker, downloader, flash program
are working correctly
In embedded systems printing can be quite complex
and a blinking LED is used instead.
The ESP8266 and the ESP32 have a “user LED” connected to GPIO 2.
How do we control this LED?
Now we put the code into a script and run it
The LED is connected to a digital line which can only be set to 0 or Vcc.
How can we change the light intensity and dim the LED?
The light intensity depends on the average current flowing through the LED.
The answer is PWM: pulse width modulation.
A more complex LED:
For all the details on the ws2812b look at
https://cdn-shop.adafruit.com/datasheets/WS2812B.pdf
24 bit of colour data puts 2e24 colours at your disposal
Coding of a single bit
The control word:
We have a single neopixel connected to
GPIO pin 4 (ESP8266)
or
GPIO pin 21 (ESP32)
This code works on both CPUs!
I2C stands for Inter-Integrated-Circuit. It was invented by Philips Semiconductor
in 1982. Slow, short distance.
Quite a number of sensors in the "WeMos D1 sensor shield collection use the I2C bus
The CPU (master) connects to the sensors (slaves) through
2 digital lines:
When the master want to talk to the slave it issues a start sequence
It terminates the transfer with a stop sequence
When talking to a slave the master sends a seven bit address
followed by a read/write bit
This allows to access at most 128 devices
Data is transmitted 8 bits at a time followed by an acknowledge bit.
If acknowledge is low, transfer ok, otherwise: send stop sequence
The SHT30 is a digital temperature and humidity sensor based on the I2C bus
Here is its data sheet.
Temperature precision: +- 0.3 °C
Relative humidity: +- 3 %
Works on 2.4V – 5.5 V
https://afnog.iotworkshop.africa/pub/AFNOG/HardwareAccessAndMicropython/sht30.py.txt
While for the course we only use the CPU and 2 sensor shields:
![]() |
![]() |
![]() |
Pushbutton | WS2812 cascadable rgb LED | SSD1306 OLED display |
![]() |
![]() |
![]() |
DS118B20 temperature sensor | DHT11 temperature and relative humidity sensor | 8x8 LED Matrix |
![]() |
![]() |
![]() |
Passive Buzzer | Data Logger | SHT30 temperature and humidity sensor |
![]() |
![]() |
|
triple base | my prototype board: LED + photo resistor |
Demo programs for all the shields are available on github:
https://github.com/uraich/MicroPython_IoTDemos
A short description of every program can be found in the README
The data logger features a DS1307 Real Time Clock (RTC) backed up by a battery This allows to store large amounts of data locally |
![]() |
![]() |
![]() |
![]() |
![]() |
This one is also an I2C device
It provides 48*64 pixels and allows to
framebuf class included in Micropython such that all
drawing methods of the framebuf are available for drawing:
https://docs.micropython.org/en/latest/library/framebuf.html
For an example see:
https://github.com/uraich/MicroPython_IoTDemos/tree/master/drivers/oled
![]() |
![]() |
The DHT11 is a digital temperature and relative humidity sensor. It uses a proprietary protocol of communication with its controlling host implemented in the dht.DHT11 class |
The LED matrix has 8x8 LEDs on it, which can individually be switched on or off. and the device and which has classes to clear the display, set a pixel on or off and to change the brightness, lights this number of LEDs starting from bottom left |
![]() |
This shield implements a passive buzzer. and produces a sound at this frequency.
In RTTTL (Ring Tone Text Transfer Language) and playing these on the buzzer
|
![]() |
This is a home build module featuring a photo-resistor measuring the light intensity impinging on it. by the ADC on the WeMos D1 CPU while the ESP32 has 3 12 bit ADCs. A MUX provides up to 18 analogue channels
|
![]() |
This module allows to easily stack a rather larger number of shields to a sandwich.
Make sure however that the GPIO lines used by the modules do not clash
The exercises are here:
https://afnog.iotworkshop.africa/do/view/AFNOG/Session2
I![]() |
Attachment | History | Action | Size | Date | Who | Comment |
---|---|---|---|---|---|---|---|
![]() |
sht30.py.txt | r1 | manage | 6.5 K | 2019-05-14 - 14:43 | UliRaich | |
![]() |
ampy.png | r1 | manage | 100.7 K | 2019-05-14 - 11:42 | UliRaich | |
![]() |
blinkingLed.png | r1 | manage | 79.9 K | 2019-05-14 - 12:17 | UliRaich | |
![]() |
cost.png | r1 | manage | 43.6 K | 2019-06-09 - 15:02 | UliRaich | |
![]() |
cpuPinouts.png | r1 | manage | 34.1 K | 2019-05-13 - 20:32 | UliRaich | |
![]() |
dht11Code.png | r1 | manage | 54.5 K | 2019-05-14 - 16:44 | UliRaich | |
![]() |
ds18b20Code.png | r1 | manage | 64.8 K | 2019-05-14 - 15:33 | UliRaich | |
![]() |
esp32-pinout-chip-ESP-WROOM-32.png | r1 | manage | 137.4 K | 2019-05-14 - 09:50 | UliRaich | |
![]() |
esp32Pinout-v2.png | r1 | manage | 151.2 K | 2019-05-14 - 09:01 | UliRaich | |
![]() |
esp8266.png | r1 | manage | 116.1 K | 2019-05-13 - 20:27 | UliRaich | |
![]() |
esp8266PinMeaning.png | r2 r1 | manage | 155.3 K | 2019-05-14 - 09:43 | UliRaich | |
![]() |
esp8266Pinout.png | r1 | manage | 176.4 K | 2019-05-13 - 20:41 | UliRaich | |
![]() |
esp8266Programming.png | r1 | manage | 108.3 K | 2019-05-14 - 09:59 | UliRaich | |
![]() |
esptool.png | r1 | manage | 114.3 K | 2019-05-14 - 11:28 | UliRaich | |
![]() |
hardwareFunctions.png | r1 | manage | 159.5 K | 2019-05-14 - 12:17 | UliRaich | |
![]() |
i2cAddress.png | r1 | manage | 1.3 K | 2019-05-14 - 14:09 | UliRaich | |
![]() |
i2cBus.png | r1 | manage | 1.6 K | 2019-05-14 - 14:09 | UliRaich | |
![]() |
i2cData.png | r1 | manage | 1.3 K | 2019-05-14 - 14:25 | UliRaich | |
![]() |
i2cScan.png | r1 | manage | 134.8 K | 2019-05-14 - 14:32 | UliRaich | |
![]() |
i2cStartStop.png | r1 | manage | 2.7 K | 2019-05-14 - 14:09 | UliRaich | |
![]() |
i2c_uP.png | r1 | manage | 248.6 K | 2019-05-14 - 14:26 | UliRaich | |
![]() |
ledControl1.png | r1 | manage | 19.8 K | 2019-05-14 - 12:17 | UliRaich | |
![]() |
ledControl2.png | r1 | manage | 19.8 K | 2019-05-14 - 12:18 | UliRaich | |
![]() |
lsusb.png | r1 | manage | 73.3 K | 2019-05-14 - 11:48 | UliRaich | |
![]() |
minicom.png | r1 | manage | 17.2 K | 2019-05-14 - 11:42 | UliRaich | |
![]() |
neopixel.png | r1 | manage | 165.5 K | 2019-05-14 - 12:46 | UliRaich | |
![]() |
neopixelCode.png | r1 | manage | 79.9 K | 2019-05-14 - 12:46 | UliRaich | |
![]() |
pinClass.png | r1 | manage | 160.1 K | 2019-05-14 - 12:20 | UliRaich | |
![]() |
pinControl2.png | r1 | manage | 19.8 K | 2019-05-14 - 12:18 | UliRaich | |
![]() |
proto.png | r1 | manage | 114.2 K | 2019-05-14 - 15:14 | UliRaich | |
![]() |
protoBoard.png | r1 | manage | 882.8 K | 2019-05-14 - 15:13 | UliRaich | |
![]() |
pushbuttonCode.png | r1 | manage | 65.6 K | 2019-05-14 - 15:33 | UliRaich | |
![]() |
pwm.png | r1 | manage | 51.4 K | 2019-05-14 - 12:27 | UliRaich | |
![]() |
pwmImpl.png | r1 | manage | 116.7 K | 2019-05-14 - 12:31 | UliRaich | |
![]() |
pwm_uP.png | r1 | manage | 24.6 K | 2019-05-14 - 12:31 | UliRaich | |
![]() |
repl.png | r1 | manage | 20.2 K | 2019-05-14 - 11:45 | UliRaich | |
![]() |
shieldPins.png | r1 | manage | 68.3 K | 2019-05-14 - 15:13 | UliRaich | |
![]() |
sht30Block.png | r1 | manage | 27.3 K | 2019-05-14 - 14:41 | UliRaich | |
![]() |
sht30Code.png | r1 | manage | 85.0 K | 2019-05-14 - 14:47 | UliRaich | |
![]() |
sht30Results.png | r1 | manage | 168.5 K | 2019-05-14 - 14:47 | UliRaich | |
![]() |
thonny.png | r1 | manage | 148.1 K | 2019-05-14 - 12:05 | UliRaich | |
![]() |
thonny_uP.png | r1 | manage | 31.0 K | 2019-05-14 - 12:05 | UliRaich | |
![]() |
tripleBase.png | r1 | manage | 196.1 K | 2019-05-14 - 15:11 | UliRaich | |
![]() |
uPyCraft.png | r1 | manage | 164.1 K | 2019-05-14 - 11:43 | UliRaich | |
![]() |
updateFirmware.png | r1 | manage | 27.3 K | 2019-05-14 - 11:59 | UliRaich | |
![]() |
wemosButton.png | r1 | manage | 113.3 K | 2019-05-14 - 14:55 | UliRaich | |
![]() |
wemosBuzzer-v2.png | r1 | manage | 108.9 K | 2019-05-14 - 15:21 | UliRaich | |
![]() |
wemosBuzzer.png | r1 | manage | 252.7 K | 2019-05-14 - 15:11 | UliRaich | |
![]() |
wemosDHT11.png | r1 | manage | 113.4 K | 2019-05-14 - 14:55 | UliRaich | |
![]() |
wemosDS18B20.png | r1 | manage | 71.5 K | 2019-05-14 - 14:55 | UliRaich | |
![]() |
wemosDataLogger-v2.png | r1 | manage | 72.7 K | 2019-05-14 - 15:21 | UliRaich | |
![]() |
wemosDataLogger.png | r1 | manage | 263.9 K | 2019-05-14 - 15:11 | UliRaich | |
![]() |
wemosEsp32.png | r1 | manage | 213.3 K | 2019-05-13 - 20:29 | UliRaich | |
![]() |
wemosLedMatrix.png | r1 | manage | 109.8 K | 2019-05-14 - 14:55 | UliRaich | |
![]() |
wemosOLED.png | r1 | manage | 139.2 K | 2019-05-14 - 14:55 | UliRaich | |
![]() |
wemosSHT30.png | r1 | manage | 102.9 K | 2019-05-14 - 15:11 | UliRaich | |
![]() |
wemosWS2812.png | r1 | manage | 144.2 K | 2019-05-14 - 14:55 | UliRaich | |
![]() |
ws2812Bits.png | r1 | manage | 11.9 K | 2019-05-14 - 12:42 | UliRaich | |
![]() |
ws2812Chain.png | r1 | manage | 19.9 K | 2019-05-14 - 12:42 | UliRaich | |
![]() |
ws2812ControlWord.png | r1 | manage | 7.6 K | 2019-05-14 - 12:42 | UliRaich | |
![]() |
afnog19-ws-session2.odp | r1 | manage | 6431.5 K | 2019-05-14 - 09:01 | UliRaich |