f6262ba212 | 4 years ago | |
---|---|---|
.. | ||
ESP32-Pinout2.jpeg | 4 years ago | |
ESP32-pinout-mapping.png | 5 years ago | |
README.md | 4 years ago | |
boot.py | 5 years ago | |
test.py | 6 years ago |
README.md
The Basics
The first boot.py
will be executed when the interpreter starts. This file should contain only code associated with configuration. Then main.py
will run. It is within this main.py
that you will place your entry point code.
Setting the AMPY_PORT variable.
All of the commands below specify a serial port in their execution. We can use the AMPY_PORT
environmental variable in our terminal session to avoid having to specify this port everytime.
export AMPY_PORT=/dev/cu.SLAB_USBtoUART
Uploading files with Ampy
First review the list of commands that the ampy
tool provides.
ampy --help
We can view the contents of the current file system:
ampy --port /serial/port ls
We can execute a command immediately on a connected board:
ampy --port /serial/port run test.py
We can also upload the code directly to the board. Notice we are passing the upload path after the file in our current directory. So, this command is placing our test.py file on the board in a file under the root dir named main.py
.
ampy --port /serial/port run test.py /main.py
We can pull the file from the board to our current working directory if we'd like so:
ampy --port /serial/port get main.py ./dirp.py
Connecting to a micropython board using screen on a Mac
screen /dev/cu.SLAB_USBtoUART 115200
To detach from a screen session first press Ctrl-A
then Ctrl-D
.
To resume a detach session use:
screen -r
To kill a screen session press Ctrl-A
then k
. You will be prompted to confirm with y\n
whether to kill the session or not.
Memory Usage
These two functions can help you determine approximate memory usage.
import gc
import os
def df():
s = os.statvfs('//')
return ('{0} MB'.format((s[0]*s[3])/1048576))
def free(full=False):
gc.collect()
F = gc.mem_free()
A = gc.mem_alloc()
T = F+A
P = '{0:.2f}%'.format(F/T*100)
if not full: return P
else : return ('Total:{0} Free:{1} ({2})'.format(T,F,P))
installing micropython on esp32
- Delete flash
esptool.py --port /dev/cu.SLAB_USBtoUART erase_flash
- If you have external spi ram (4MB) you want to use the spiram bin.
esptool.py --chip esp32 --port /dev/cu.SLAB_USBtoUART --baud 460800 write_flash -z 0x1000 ./binaries/esp32-idf4-20210202-v1.14.bin