ESP32 (MicroPython)
The following examples show how to connect GUI-O application with ESP32 in various communication modes using MicroPython.
Setup MicroPython environment
The examples are based on ESP32-WROOM-32 board and PyCharm Community Edition IDE (Integrated Development Environment) with MicroPython plugin.Â
Note that any other ESP32 board can also be used. Also note that any other IDE that supports ESP32 & MicroPython can be used.
Step 1: Install MicroPython on ESP32
Download the ESP32 firmware (for more information and support for other boards, see the firmware download page)
Download the esptool for Linux or Windows (for more information, see esptool Git repository)Â
Extract the downloaded archive and move the downloaded firmware into the extracted esptool folder
Open the Terminal (Linux) or Command Prompt (Windows) and navigate to the extracted esptool folder
Connect ESP32 to the PC and erase the flash:
./esptool --chip esp32 --port <port> erase_flash
NOTE #1: Replace <port> in the command with the actual port where the ESP32 is connected. On Windows, this might be something like COM4 (or something like /dev/ttyUSB0 on Linux).
NOTE #2: If the command is not recognized on Linux, make the tool executable (for all users):
chmod a+x esptool
Finally, program the ESP32 firmware:
./esptool --chip esp32 --port <port> --baud 460800 write_flash -z 0x1000 <.bin_file>
Step 2: Setup PyCharm IDE
Download and install PyCharm Community Edition for Windows or Linux
Run PyCharm and select Plugins (from welcome screen) or navigate to "File -> Settings -> Plugins"
Search for MicroPython plugin and install it
Create a New Project and specify desired project location
Navigate to "File -> Settings -> Languages & Frameworks -> MicroPython" and enable MicroPython support
Select ESP8266 under "Device type"
Under "Device path" enter the actual port where the ESP32 is connected - on Windows, this might be something like COM4 (or something like /dev/ttyUSB0 on Linux)
Your project is now ready to run MicroPython code - see the examples below
ESP32 & MicroPython & GUI-O basic examples
The following examples show basic interaction between GUI-O application and ESP32 module in various communication modes using MicroPython.
ESP32 Bluetooth LE
IMPORTANT NOTE: This example assumes that MicroPython environment has already been set up and a new PyCharm project was created (see Setup MicroPython environment).
Step 1: Run the Python script
Connect ESP32 to the PC via USB cable
Download the main.zip and ble_advertising.zip packages to your PC and extract the packages
Copy main.py and ble_advertising.py into the root of your PyCharm project and double-click on it within the PyCharm IDE
Right click on main.py, select Run 'Flash main.py' and confirm
NOTE: In case of any missing libraries, just click on "Fix" button and PyCharm will automatically install them.
Right click on ble_advertising.py, select Run 'Flash ble_advertising.py' and confirm
After the upload, ESP32 should issue a soft-reboot and begin program execution
NOTE: All debug messages during program execution can be observed using any serial console terminal (baud rate 115200 bps).
Step 2: Using GUI-O application to interact with ESP32
Open GUI-O application and navigate to "Settings -> Connections -> Bluetooth LE"
Tap "Available devices" to search for ESP32 Bluetooth device
Tap "BasicBLE" device and wait for successful connection
Close "Settings" and tap GUI-O initialize button from the home screen to try the example
ESP32 MQTT (supports SSL/TLS)
IMPORTANT NOTE: This example assumes that MicroPython environment has already been set up and a new PyCharm project was created (see Setup MicroPython environment).
Step 1: Create tokens for MQTT communication
Open GUI-O application and select "Add" from the top-right corner of the home screen
Select "IoT (Create device)" and add a new device (specifying arbitrary name and optional user name)
After adding a device, note the In and Out tokens which are required in the following step (tokens can be shared via email by pressing the "Share" icon)
Step 2: Modify and run the Python script
Connect ESP32 to the PC via USB cable
Download the main.zip package to your PC and extract the package
Copy main.py into the root of your PyCharm project and double-click on it within the PyCharm IDE
Set your router name and password
Set the In and Out tokens generated in Step 1
You can optionally disable SSL/TLS (this will make the connection insecure and is not recommended)
Right click on main.py, select Run 'Flash main.py' and confirm
NOTE: In case of any missing libraries, just click on "Fix" button and PyCharm will automatically install them.
After the upload, ESP32 should issue a soft-reboot and begin program execution
NOTE: All debug messages during program execution can be observed using any serial console terminal (baud rate 115200 bps).
Step 3: Using GUI-O application to interact with ESP32
Open GUI-O application and select "Connect" from the top-left corner of the home screen
Tap on the device created in Step 1
Wait for successful connection and try the example
ESP32 USB
IMPORTANT NOTE: This example assumes that MicroPython environment has already been set up and a new PyCharm project was created (see Setup MicroPython environment).
IMPORTANT NOTE: The programming port on ESP32 cannot be used for communication with GUI-O application. Therefore, an additional USB to serial converter should be used (e.g., TTL-232R-3V3). This example assumes that USB to serial converter is connected to ESP32 UART2.
In order to connect ESP32 to your Android device, a simple adapter cable is needed (as shown in the image). Also note that not all Android devices support USB OTG functionality.
Step 1: Run the Python script
Connect ESP32 to the PC via USB cable
Download the main.zip package to your PC and extract the package
Copy main.py into the root of your PyCharm project and double-click on it within the PyCharm IDE
Right click on main.py, select Run 'Flash main.py' and confirm
NOTE: In case of any missing libraries, just click on "Fix" button and PyCharm will automatically install them.
After the upload, ESP32 should issue a soft-reboot and begin program execution
NOTE: All debug messages during program execution can be observed using any serial console terminal (baud rate 115200 bps).
Step 2: Using GUI-O application to interact with ESP32
Connect ESP32 UART2 via USB to serial converter to your Android device
Open GUI-O application and navigate to "Settings -> Connections -> Usb serial"
Make sure baud rate 115200 bps is selected, tap "Connect" and wait for successful connection
Close "Settings" and tap GUI-O initialize button from the home screen to try the example
ESP32 Ethernet
IMPORTANT NOTE: This example assumes that MicroPython environment has already been set up and a new PyCharm project was created (see Setup MicroPython environment).
Step 1: Run the Python script
Connect ESP32 to the PC via USB cable
Download the main.zip package to your PC and extract the package
Copy main.py into the root of your PyCharm project and double-click on it within the PyCharm IDE
Right click on main.py, select Run 'Flash main.py' and confirm
NOTE: In case of any missing libraries, just click on "Fix" button and PyCharm will automatically install them.
After the upload, ESP32 should issue a soft-reboot and begin program execution
NOTE: All debug messages during program execution can be observed using any serial console terminal (baud rate 115200 bps).
Step 2: Using GUI-O application to interact with ESP32
Open GUI-O application and navigate to "Settings -> Connections -> Ethernet"
Tap "Add device" icon and set the device name, IP (e.g., 192.168.1.123) and port (e.g., 34567) based on your configuration
Tap the created device and wait for successful connection
NOTE: Make sure that your Android device is connected to the same WiFi network as ESP32 device.
Close "Settings" and tap GUI-O initialize button from the home screen to try the example
ESP32 & MicroPython & GUI-O manual pairing via Bluetooth
The following example shows how to manually pair GUI-O application with ESP32 in MQTT (IoT) mode using Bluetooth connection.
The ESP32 is initially started in Bluetooth mode. GUI-O application then connects via Bluetooth and the user manually enters the IoT communication tokens. After storing the tokens, the ESP32 reboots in MQTT (IoT) mode and remote communication can begin.
IMPORTANT NOTE: This example assumes that MicroPython environment has already been set up and a new PyCharm project was created (see Setup MicroPython environment).
Step 1: Create tokens for MQTT communication
Open GUI-O application and select "Add" from the top-right corner of the home screen
Select "IoT (Create device)" and add a new device (specifying arbitrary name and optional user name)
After adding a device, share the In and Out tokens via email by pressing the "Share" icon
Step 2: Modify and run the Python script
Connect ESP32 to the PC via USB cable
Download the main.zip package to your PC and extract the package
Copy modules folder and main.py into the root of your PyCharm project and double-click main.py within the PyCharm IDE
Set your router name (ssid) and password (ssid_pass)
Right click on modules folder and select Run 'Flash modules'
Right click on main.py and select Run 'Flash main.py'
NOTE: In case of any missing libraries, just click on "Fix" button and PyCharm will automatically install them.
After the upload, ESP32 should issue a soft-reboot and begin program execution in Bluetooth mode (on-board LED indicator flashes rapidly)
NOTE: All debug messages during program execution can be observed using any serial console terminal (baud rate 115200 bps).
Step 3: Using GUI-O application to manually pair with ESP32
Open GUI-O application and select "Add" from the top-right corner of the home screen
Tap Bluetooth LE and search for devices (enable Bluetooth and Location services, if prompted)
Tap "Basic BLE" device and wait for successful connection
Close "Settings" and tap GUI-O initialize button
Enter (or copy-paste) the In and Out tokens created in Step 1
NOTE: When entering the tokens, press the 'Enter' button on the keyboard to send the tokens to ESP32.
Tap 'Restart in IoT mode' button (this will store the tokens and initialize ESP32 reboot in IoT mode; on-board LED indicator flashes slowly)
NOTE: Bluetooth error message will be displayed, but this is normal since Bluetooth connection is terminated
Select "Connect" from the top-left corner of the home screen
Tap on the device created in Step 1
Wait for successful connection. Note that the example can be modified further to fit your specific needs, e.g.:
Add logic to MicroPython program to create a custom GUI when IoT connection is established (see 'parse_mqtt_msg' function in main.py)
Implement barcode reader widget to read QR codes in order to simplify transfer of IoT communication tokens
etc.
Connect . Create . Control