0

members

Easy Basics: Project 070j ESP32 Development board and ESP8266 ESP-12E module - MicroPython

of Acoptex.com in ESP8266 ESP-32

Basics: Project 070j

Project name: ESP32 Development board - MicroPython

Tags: EESP32 Dev Module, ESP32 development board, ESP32 Development board with WiFi and Bluetooth, ESP32-DevKitC V4 development board, ESP-WROOM-32 module with ESP32‑D0WDQ6 chip, Espressif Systems, ESP32-based development board, ESP32 modules, ESP32-WROOM-32, ESP32-WROOM-32U, ESP32-WROOM-32D, ESP32-SOLO-1, USB-UART bridge, IOT, ESP-WROOM-32 Dev Module, ESP32 DEVKITV1, Installing the ESP32 Board in Arduino IDE, Uploading sketch, ESP, ESP8266, WI FI module, ESP-12E, Ai Thinker, AI-Cloud, SOC, GPIO, General Purpose Input Output, System On a Chip, IOT, internet of things, FTDI232, FTDI 232, LoLin NODEMCU V3, NODEMCU, V3, Development Board with USB-to-Serial Onboard, NodeMCU DevKit, Uploading MicroPython firmware, flashing, uPyCraft IDE, Troubleshooting

In this project, you need these parts :

1. ESP32 development board with WiFi and Bluetooth and USB A / micro USB B cable 1 pc

2. uPyCraft IDE (you can download and read more about it here)

3. 

ESP8266 ESP-12E module with micro USB cable 1pc

General

We will learn about MicroPython, differences between MicroPython and regular Python, and how to program your ESP32 development board/ESP8266 ESP-12E module with MicroPython using uPyCraft IDE. 

Understanding the MicroPython

MicroPython is a re-implementation of Python 3 targeted to microcontrollers and embedded systems. MicroPython is very similar with regular Python. If you know how to program with Python - you know how to program with MicroPython too.

Python vs MicroPython

Apart from a few exceptions, the language features of Python are also available in MicroPython. The biggest difference between Python and MicroPython is that MicroPython was designed to work under constrained conditions - MicroPython does not come with the full standard library. It only includes a small subset of the Python standard library. However, it does include modules to access low-level hardware – this means that there are libraries to easily access and interact with the GPIOs.

Devices with Wi-Fi capabilities like the ESP8266 ESP-12E module and ESP32 Development board include modules to support network connections.

Python is one of the most widely used, simple and easy-to-learn programming languages around. So, the emergence of MicroPython makes it very easy and simple to program digital electronics. If you have never programmed digital electronics before, MicroPython is a good starting point.

MicroPython’s goal is to make programming digital electronics as simple as possible, so it can be used by anyone. MicroPython is used by hobbyists, researchers, teachers, educators and in commercial products.

One great feature of MicroPython is that it comes with an interactive REPL (Read-Evaluate-Print Loop). The REPL allows you to connect to a board and execute code quickly without the need to compile or upload code.

MicroPython runs on many different devices and boards, such as:

  • ESP32
  • ESP8266
  • PyBoard
  • Micro:Bit
  • Teensy 3.X
  • WiPy – Pycom
  • Adafruit Circuit Playground Express
  • Other ESP32/ESP8266 based boards

You can find more information about boards on MicroPython Forum and MicroPython Github.

We use MicroPython with the ESP32 Development board and ESP8266 ESP-12E boards in our projects.

You need to have uPyCraft IDE installed on your PC in order to upload the MicroPython firmware to your ESP board. You can find out how to do it here.

You can find out how to upload the MicroPython firmware on ESP8266 ESP-12E module here, ESP32 development board here.

Let's check uPyCraft IDE software, so that you can start programming with MicroPython. The uPyCraft IDE is a software that contains tools to make the process of development, debugging and upload code easier. There are many ways to program your ESP board with MicroPython. The uPyCraft IDE software works great with the ESP boards.

To start programming with MicroPython you need to have:

  1. uPyCraft IDE installed on your computer;
  2. ESP32 Development board/ESP8266 ESP-12E module flashed with MicroPython firmware.

When you open uPyCraft IDE sofware you see the followning window:

Let's have a look at each section of uPyCraft IDE:

  1. Folder and files
  2. Editor
  3. MicroPython Shell/Terminal
  4. Tools

1. Folder and files

This section shows several folders and files. The device folder shows the files that are currently stored on your ESP board. If you have your ESP32 or ESP8266 ESP-12E connected via serial to uPyCraft IDE, when you expand the device folder, all files stored should load. By default, you should only have a boot.py file. To run your main code, it is recommended to create a main.py file.

boot.py - runs when the device starts and sets up several configuration options;

main.py - this is the main script that contains your code. It is executed immediately after the boot.py.

The sd folder - meant to access files stored on SD cards – this is only works with boards like the PyBoard that come with an SD card slot.

The uPy_lib shows the built-in IDE library files.

The workspace is a directory to save your files. These files are saved in your computer in a directory defined by you. This is a specially useful to keep all your files organized at hand.

When using uPycraft for the first time, to select your working directory, select the workspace folder. A new window pops up for you to chose your workspace path. Create a new folder or select an existing folder to be your working directory.

Go to File -> Reflush Directory to update the directory.

Go to Tools -> InitConfig and select the workspace directory folder to chose a different path if you want to change the user directory.

2. Editor

The Editor section is where you write your code and edit your .py files. You can open more than one file, and the Editor will open a new tab for each file.

3. MicroPython Shell/terminal

On the MicroPython Shell you can type commands to be executed immediately by your ESP board without the need to upload new files. The terminal also provides information about the state of an executing program, shows errors related with upload, syntax errors, prints messages and so on.

4. Tools

The icons placed at the rightmost side allow you to quickly perform tasks. Each button is labeled in the figure below:

  • New file: make a new file on the Editor;
  • Open file: open a file from your computer;
  • Save file: save a file;
  • Download and run: upload the code to your board and execute the code;
  • Stop: stop the execution of the code (CTRL+C on the Shell to stop all scripts from running);
  • Connect/Disconnect: connect or disconnect to your board via Serial. You must select the serial port first in Tools -> Serial;
  • Undo: undo last change in the code Editor;
  • Redo: redo last change in the code Editor;
  • Syntax check: checks the syntax of your code;
  • Clear: clear the Shell/terminal window messages.

Understanding the ESP32 Development board with WiFi and Bluetooth

You can read more about it here.

Understanding the ESP8266 ESP-12E WI FI module (LoLin NODEMCU V3)

You can read more about it here.

Signals and connections of the ESP8266 ESP-12E WI FI module (LoLin NODEMCU V3)

TX - transmit pin. GPIO pin

RX  - receive pin.  GPIO pin

3V3 (or 3V or 3.3V) - power supply pin (3-3.6V). 

GND ( or G) - ground pin.

RST - reset pin. Keep it on high (3.3V) for normal operation. Put it on 0V to reset the chip.

EN - Chip enable. Keep it on high (3.3V) for normal operation.

Vin - External power supply 5VDC.

D0-D8 - GPIO (General Purpose Input Output) pins 

D5-D8 - SPI interface

D1-D2– I²C/TWI Interface

SC (or CMD) - (Chip Select) - the pin that the master can use to enable and disable specific devices. GPIO pin

SO (or SDO) - Master In Slave Out (MISO) - SPI communication. The Slave line for sending data to the master. GPIO pin

SK (or CLK) - SCK (Serial Clock) - SPI communication.The clock pulses which synchronize data transmission generated by the master. GPIO pin

S1 (or SD1) - Master Out/Slave In (MOSI). SPI communication. The Master line for sending data to the peripherals. GPIO pin

S2 (or SD2) - GPIO pin

S3 (or SD3) - GPIO pin

VU (or VUSB) - external power 5VDC.

A0 - ADC output.

RSV - reserved

Signals and connections of the ESP32 Development board with WiFi and Bluetooth

You can find more information (datasheets, schematics, pins descriptions, functional desgn descriptions) about each board (made by Espresiff Systems) by pressing Getting started link close to each board here.

Let's check our development board - ESP32 DEVKITV1with ESP-WROOM-32 module from Espressif Systems:

Pinout diagram for the ESP Wroom 32 breakout:

ESP32-WROOM-32 - ESP32-WROOM-32 module soldered to the development board. Optionally ESP32-WROOM-32D, ESP32-WROOM-32U or ESP32-SOLO-1 module may be soldered instead of the ESP32-WROOM-32.

USB-UART Bridge - A single chip USB-UART bridge provides up to 3 Mbps transfers rates.

BOOT button - Download button: holding down the Boot button and pressing the EN button initiates the firmware download mode. Then user can download firmware through the serial port.

EN button - Reset button: pressing this button resets the system.

Micro USB Port - USB interface. It functions as the power supply for the board and the communication interface between PC and the ESP module.

TX0, TX2 - transmit pin. GPIO pin

RX0, RX2  - receive pin.  GPIO pin

3V3 (or 3V or 3.3V) - power supply pin (3-3.6V). 

GND - ground pin.

EN - Chip enable. Keep it on high (3.3V) for normal operation.

Vin - External power supply 5VDC.

Step by Step instruction

  1. Install uPyCraft IDE on your PC;
  2. Plug the ESP32 development board/ESP8266 ESP-12E module to your PC and wait for the drivers to install (or install manually any that might be required).
  3. Upload MicroPython firmware to your ESP32 Development board or ESP8266 ESP-12E module - Uploading MicroPython firmware.
  4. Open uPyCraft IDE. Double-click uPyCraft_V1.1.exe file. A new window opens with the uPyCraft IDE software.
  5. Go to Tools -> Board. If you are using ESP32 development board select esp32 or esp8266 option for ESP8266 ESP-12E module.
  6. Go to Tools -> Serial and select your ESP32 Development board/ESP8266 ESP-12E module COM port (in our case it’s COM8). If you don’t see the COM Port, you need to install the ESP32 CP210x USB to UART Bridge VCP Drivers , check your USB cable too (it should be data cable).
  7. You have established a serial communication with your board. The >>> should appear in the Shell window after a successful connection with your board. You can type the print command to test if it’s working: print('Hello'). It will print the Hello message. 
  8. Press New file button to create a new file.
  9. Press Save file button to save the file in your PC. Input file name main.py and press ok button.
  10. You should see the following in your uPyCraft IDE -the boot.py file in your device and a new tab with the main.py file.
  11. Press Download and run button to upload the file to your ESP32 Development board/ESP8266 ESP-12E module. The device directory should now load the main.py file. Your ESP32 Development board/ESP8266 ESP-12E module has two files - boot.py and main.py stored now.
  12. You should see a message download ok in the Shell window.
  13. Copy the following code to the Editor on the main.py file.
  14. Press Stop button to stop any script from running in your board.
  15. Press Download and Run button to upload the script to the ESP32 Development board/ESP8266 ESP-12E module.
  16. You should see a message download ok in the Shell window. The on-board LED of your ESP32 Development board or ESP8266 ESP-12E module is blinking now every 500 ms.

Troubleshooting

The common errors that occur with uPyCraft IDE:

1. When you are getting the message:

>>>
Select Serial Port could not open port 'COM4': FileNotFoundError(2, 'The system cannot find the file specified.', None, 2)

>>>Select Serial Port could not open port 'COM8': FileNotFoundError(2, 'The system cannot find the file specified.', None, 2) or

>>> could not open port 'COM8': PermissionError(13, 'A device attached to the system is not functioning.', None, 31)

Unplug and plug back your ESP32 Development board/ESP8266 ESP-12E module. Double-check that you selected the right serial port in the Tools -> Serial menu. Press Connect/disconnect button to establish a serial communication. You should now be able to upload a new script. This error can be because you use your serial port in another program, for example, in the Arduino IDE.

2. Trouble uploading a new script:

>>> already in download model,please wait.

Press Stop button in uPyCraft IDE one or several times to make sure that any code which was running stops. Press Download and run button to upload the new script to your ESP32 Development board/ESP8266 ESP-12E module.

3. After uploading a new script you see the following message:

>>>

Ready to download this file,please wait!

... 

download ok

os.listdir('.')

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

NameError: name 'os' isn't defined or

>>>

Ready to download this file,please wait!

... 

download ok

os.listdir('.')

OSError: [Errno 98]

It means that the new file was uploaded to your board successfully. You can notice that it printed the download ok message. Press the ESP32 Development board/ESP8266 ESP-12E module on-board EN/RST button to restart your board and re-run the new uploaded script from the beginning.

4. Problem restarting your ESP32 Development board/ESP8266 ESP-12E module, running a new script or opening the serial port:

>>>

Brownout detector was triggered

This error message means that there is a hardware problem. It is often related to one of the following issues:

  • Poor quality USB cable;
  • USB cable is too long;
  • Board with some defect (bad solder joints);
  • Bad computer USB port;
  • Or not enough power provided by the computer USB port.

Try a different shorter USB data cable or a different computer USB port.

If you keep having constant problems or error messages, we recommend updating your ESP32 Development board/ESP8266 ESP-12E module with the latest version of MicroPython firmware.

Summary

We have learnt about MicroPython, differences between MicroPython and regular Python, and how to program your ESP32 development board/ESP8266 ESP-12E module with MicroPython using uPyCraft IDE. 

Libraries

  • None

Sketch

  • None


Other projects of Acoptex.com
Easy CBASIC Lesson 9 Compiling and debugging in Visual Studio of Acoptex.com in Csharp 10-04-2019
Easy Basics: Project 081d ESP8266 ESP-12E module and Nextion HMI display of Acoptex.com in ESP8266 ESP-12 24-03-2019

« Go back to category
Is this project fake? Report it!   
Recommend to a friend
Published at 03-10-2018
Viewed: 580 times