Simplifying application development with Anaconda

WebREPL is a really cool tool that can be useful for working with an interactive web page to move files to and from the ESP32 over Wi-Fi. For a seasoned developer, developing software with WebREPL can seem quite tedious. For that reason, in this section, I'm going to discuss an alternative way for you to push the application code to the ESP32. We are going to do that using an Anaconda prompt.

Anaconda is a free package and environment manager that contains a Python distribution that includes thousands of open source packages. It provides an Anaconda prompt that can be used across any major PC platform and that allows a developer to create their own Python virtual machines. Most importantly for us, it provides a convenient way to download ampy, which is an Adafruit package specifically designed to interface with the ESP32 for MicroPython development.

In order to set up Anaconda, perform the following steps:

  1. Visit https://www.anaconda.com/distribution/, click Download, and select your platform.
  2. Once downloaded, install Anaconda.
  3. When the download is complete, open the Anaconda prompt.

From within the prompt, set up your environment by issuing the following commands:

  1. conda create -n ESP32-uPython python =3.7
  2. conda activate ESP32-uPython
  3. pip3 install ampy-adafruit

Successfully installing ampy will result in a terminal output that looks something like the following:

You now have an Anaconda Python virtual machine set up that we can use to transfer files to and from the ESP32. Let's quickly write a simple script to practice sending and getting scripts:

  1. From within the prompt, use the following command to pull the default main.py script (obviously changing COM3 to the port that your device is on):
ampy –port COM3 --baud 115200 get main.py main.py
  1. Yes, main.py is written twice in order to tell the prompt that we want to download the file. Once you have downloaded main.py, open it in your favorite text editor. Write a simple toggle application similar to the one shown here:
import machine
import time
pin = machine.Pin(2, machine.Pin.OUT)
def toggle(p):
p.value(not p.value())
while True:
toggle(pin)
time.sleep_ms(500)
  1. Save the script and then use the following command to upload the new script:
ampy --port COM3 --baud 115200 put main.py
  1. Make sure that you connect an LED to the GPIO 2. Unplug the ESP32 and then plug it back in. You should now see your LED blinking at a rate of 500 milliseconds! You now have a simpler way to interact with the ESP32 and push your scripts to it.
Note: Once you close out of Anaconda, your ampy virtual machine will be closed. When you open Anaconda again, you will be in the base environment. To restart your ampy environment, type activate ampy. This will get you back to where you can use the terminal to load your code.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.244.201