0

members

Easy Basics: Project 086o ESP8266 ESP-12E module - Using Thonny IDE

of Alek C. in ESP8266 ESP-12

Basics: Project 086o

Project name: ESP8266 ESP-12E module - Using Thonny IDE

Tags: ESP8266 ESP-12E module, ESP, ESP8266, WI FI module, ESP-12E, LoLin NODEMCU V3, NODEMCU, micropython, Thonny IDE

Attachments: none

In this project, you needed these parts (Dear visitors. You can support our project buy clicking on the links of parts and buying them or donate us to keep this website alive. Thank you):

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

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

General

We will learn how to install and use the Thonny IDE with the ESP8266 ESP-12E module.

Understanding the Thonny IDE

Thonny is Python IDE for beginners. It allows you to program your ESP32 and ESP8266 boards with MicroPython, and it is compatible with Windows, Mac OS X, and Linux. It even comes installed by default with Raspbian OS for Raspberry Pi. Additionally, it's easy to install, so you shouldn’t have problems with the installation process.

Features:

  • Easy to get started. Thonny comes with Python 3.7 built in, so just one simple installer is needed and you're ready to learn programming. (You can also use a separate Python installation, if necessary.) The initial user interface is stripped of all features that may distract beginners.
  • No-hassle variables. Once you're done with hello-worlds, select View -> Variables and see how your programs and shell commands affect Python variables.
  • Simple debugger. Just press Ctrl+F5 instead of F5 and you can run your programs step-by-step, no breakpoints needed. Press F6 for a big step and F7 for a small step. Steps follow program structure, not just code lines.
  • Step through expression evaluation. If you use small steps, then you can even see how Python evaluates your expressions. You can think of this light-blue box as a piece of paper where Python replaces subexpressions with their values, piece-by-piece.
  • Faithful representation of function calls. Stepping into a function call opens a new window with separate local variables table and code pointer. Good understanding of how function calls work is especially important for understanding recursion.
  • Highlights syntax errors. Unclosed quotes and parentheses are the most common beginners' syntax errors. Thonny's editor makes these easy to spot.
  • Explains scopes. Highlighting variable occurrences reminds you that the same name doesn't always mean the same variable and helps spotting typos. Local variables are visually distinguished from globals.
  • Mode for explaining references. Variables are initially presented according to simplified model (name -> value) but you can switch to more realistic model (name -> address/id -> value).
  • Code completion. Students can explore APIs with the help of code completion.
  • Beginner friendly system shell. Select Tools -> Open system shell to install extra packages or learn handling Python on command line. PATH and conflicts with other Python interpreters are taken care of by Thonny.
  • Simple and clean pip GUI. Select Tools -> Manage packages for even easier installation of 3rd party packages.

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

Step by Step instruction

We are using Windows 7 64 bit OS version on our PC.

1. Preparations

  1. Install uPyCraft IDE on your PC;
  2. Plug the ESP8266 ESP-12E module to your PC and wait for the drivers to install (or install manually any that might be required).
  3. ESP8266 ESP-12E module - Uploading MicroPython firmware.

2. Installing the Thonny IDE.

  1. Go to thonny.org website and download the file for installation suitable for your OS. We have Windows OS so we downloaded thonny-3.1.2.exe for Windows.
  2. Double-click on thonny-3.1.2.exe to open the file. Click on Run button.
  3. Click on Next button.
  4. Select I accept the agreement and click on Next button.
  5. Click on Next button.
  6. Click on Next button.
  7. Click on Install button.
  8. The installation process will start.
  9. Click on Finish button.
  10. After completing the installation, open Thonny IDE.

3. Testing the installation

  1. Your ESP8266 ESP-12E module should have MicroPython firmware.
  2. Plug the ESP8266 ESP-12E module to your PC and wait for the drivers to install (or install manually any that might be required).
  3. Go to Tools -> Options and select the Interpreter tab.
  4. Select MicroPython on a generic device.
  5. Select your device serial port. You can also select the Try to detect automatically option, but only if you just have one board connected to your computer at a time. Otherwise, select the specific port for the board you're using.
  6. Click on OK button.
  7. Thonny IDE should now be connected to your board and you should see the prompt on the Shell.
  8. Type the command help() in the Shell and see if it responds back.
  9. If iyou received response then everything is working fine. You can send a few more commands to test now.
  10. Send the following commands to light up the ESP8266 ESP-12E module on-board LED: from machine import Pin
  11. Pin(2, Pin.OUT).value(0)
  12. To turn off the on-board LED send the command: Pin(2, Pin.OUT).value(1)
  13. Congrats. You have done.

4. Using the Thonny IDE

  1. When you open the Thonny IDE you can see two sections: Editor and Terminal/Shell. 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. In the Terminal/Shell section you can type commands to be executed immediately by your ESP8266 ESP-12E module 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.
  2. You can customize your Thonny IDE to show other useful tabs. Go to View and you can select several tabs that provide more information.
  3. Let's make a script and run it. It will blink the on-board LED on your ESP8266 ESP-12E module.
  4. When you open Thonny IDE for the first time, the Editor section shows an untitled file. Save that file as main.py - click on save icon and give the name to the file main.py. You will have the tab main.py now.
  5. Type the folowing code in main.py file.
  6. Save it - click on save icon.
  7. Go to Device and select Upload current script as main script.
  8. It should show the following in the Terminal/Shell section. Uploading the code as main script will save the current file with the name main.py on the ESP8266 ESP-12E module, even if you have saved it in your computer with a different name. The same happens for the boot.py file.
  9. After uploading the script press the on-board RST (RESET) button on your ESP8266 ESP-12E module. When the ESP8266 esp-12e module restarts, first it runs the boot.py file and afterwards the main.py.
  10. The ESP8266 ESP-12E module on-board LED should be blinking. Congrats.
  11. To list all files saved on the ESP8266 ESP-12E module type the command in the Terminal/Shell: %lsdevice 

  12. If you want to see the file content, use %cat / followed by the file path, for example: %cat /main.py

  13. If you want to see the boot.py and main.py scripts, go to Device, select Show device's main script or Show device's boot script.
  14. If you want to upload the file with script which has a special name. Make the file, save it (for example we had best.py), go to Device and select Upload current script with current name.
  15. The file will be saved on the ESP8266 ESP-12E module with the name best.py.
  16. If you want to remove/delete all files completely from your ESP8266 ESP-12E module, you need to re-flash it with MicroPython firmware. You can also upload a blank script to the ESP8266 ESP-12E module to remove/delete code.

Troubleshooting

Normally the restarting your ESP8266 ESP-12E module with the on-board RST button fixes your problem or pressing in the Thonny IDE Stop/Restart backend button and repeating your desired action.

If it doesn't work for you check the solutions below:

  1. If you are getting an error: = RESTART = Unable to connect to COM4 Error: could not open port 'COM4': FileNotFoundError(2, 'The system cannot find the file specified.', None, 2) Check the configuration, select Run -> Stop/Restart or press Ctrl+F2 to try again. (On some occasions it helps to wait before trying again.) or = RESTART = Could not connect to REPL.Make sure your device has suitable firmware and is not in bootloader mode!Disconnecting o= RESTART = Lost connection to the device (EOF)Disconnect and connect your ESP8266 ESP-12E module. Then, double-check that you selected correct serial port in the Tools -> Options... -> Interpreter -> Port. Click on Stop/Restart backend button to establish a serial communication. You should now be able to upload a new script or re-run new code. These errors might also mean that you have your serial port being used in another program (like a serial terminal or in the Arduino IDE). Double-check that you closed all the programs that might be establishing a serial communication with your ESP8266 ESP-12E module. Disconnect and connect your ESP8266 ESP-12E module again. Do restart Thonny IDE.
  2. If Thonny IDE fails to respond or gives an Internal Error window. When it happens, close that window and it will continue to work. If it will continue to crash restart the Thonny IDE software.
  3. Thonny IDE hangs when you click on Stop/Restart backend button. When you click on Stop/Restart backend button you need to wait a few seconds. The ESP8266 ESP-12E module needs time to restart and establish the serial communication with Thonny IDE. If you click on this button multiple times or if you click on this button very quickly, the ESP8266 ESP-12E module will not have enough time to restart properly and it's very likely crash Thonny IDE.
  4. Problem restarting your ESP8266 ESP-12E module, running a new script or opening the serial port - Brownout detector was triggered or if the ESP8266 ESP-12E module keeps restarting and printing the ESP boot information. Brownout detector was triggered error message or constant reboots  means that there's some sort of hardware problem. It's 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, try a different computer USB port or use a USB hub with an external power supply. If you keep having constant problems or error messages we recommend to re-flash your ESP8266 ESP-12E module with the latest version of MicroPython firmware.
  5. When you try to establish a serial communication with the ESP8266 ESP-12E module in Thonny IDE but can not get it to connect. When you are running a script in your board, sometimes it's busy running that script and performing the tasks. So, you need to try start the connection by click on Stop/Restart backend button multiple times or restart the ESP8266 ESP-12E module to catch available to establish the serial communication. Please  do not click on Stop/Restart backend button multiple times very quickly. After pressing that button, you need to be patient and wait a few seconds for the command to run. If you are running a script that uses Wi-Fi, deep sleep or it's doing multiple tasks we recommend trying 3 or 4 times to establish the communication. If you can not we recommend to re-flash the ESP8266 ESP-12E module with MicroPython firmware.
  6. Debug tools are grayed out. Thonny IDE debug tools are not available for MicroPython. The debug tools are only available for the Python Interpreter, so being grayed out is the expected behavior. 

Summary

We have learnt how to install and use the Thonny IDE with the ESP8266 ESP-12E module.

Libraries

  • None

Script

  • None


Other projects of Alek C.
Easy Basics: Project 086p ESP32 development board - Using Thonny IDE of Alek C. in ESP8266 ESP-32 09-08-2019

« Go back to category
Is this project fake? Report it!   
Recommend to a friend
Published at 09-08-2019
Viewed: 100 times