Micropython : esp32 #2 button

python

Development environment

reference

Arch linux

windows 10 WSL2 installation method

arch mac : Initial setting #1 install

Board schematic

key

reference image

key

ESP32/io12 → switch → ESP32/GND

Connect the microcomputer and PC with USB

Install esptool

reference

mkdir micropython

cd micropython

download Firmware

Be sure to download to the current hierarchy

sudo pacman -S esptool

sudo esptool.py flash_id

esptool.py v3.0
Found 1 serial ports
Serial port /dev/ttyUSB0
Connecting....
Detecting chip type... ESP32
Chip is ESP32-D0WD (revision 1)
Features: WiFi, BT, Dual Core, Coding Scheme None
Crystal is 40MHz
MAC: 30:ae:a4:9d:51:1c
Uploading stub...
Running stub...
Stub running...
Manufacturer: 20
Device: 4016
Detected flash size: 4MB
Hard resetting via RTS pin...

serial poat /dev/ttyUSB0

Check the part of /dev/ttyUSB0

sudo esptool.py --port /dev/tty??????? erase_flash

Because it is /dev/ttyUSB0 in my development environment

sudo esptool.py --port /dev/ttyUSB0 erase_flash

esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting....
Detecting chip type... ESP32
Chip is ESP32-D0WD (revision 1)
Features: WiFi, BT, Dual Core, Coding Scheme None
Crystal is 40MHz
MAC: 30:ae:a4:9d:51:1c
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 8.5s
Hard resetting via RTS pin...

sudo esptool.py --chip esp32 --port /dev/ttyUSB0 write_flash -z 0x1000 esp32-idf3-20210202-v1.14.bin

esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting....
Chip is ESP32-D0WD (revision 1)
Features: WiFi, BT, Dual Core, Coding Scheme None
Crystal is 40MHz
MAC: 30:ae:a4:9d:51:1c
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Compressed 1445632 bytes to 925476...
Wrote 1445632 bytes (925476 compressed) at 0x00001000 in 82.2 seconds (effective 140.8 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

add main.py in ESP32

yay -S adafruit-ampy

Installation method yay

sudo ampy -p /dev/ttyUSB0 get boot.py

Output the contents of boot.py contained in the microcomputer

# This file is executed on every boot (including wake-boot from deepsleep)
#import esp
#esp.osdebug(None)
import webrepl
webrepl.start()

Microcomputer button

touch main.py

micro main.py

micro editor installation method

import machine
import time
button = machine.Pin(12, machine.Pin.IN, machine.Pin.PULL_UP)
while True:
    first = button.value()
    time.sleep(0.01)
    second = button.value()
    if first and not second:
        print('Button pressed!')
    elif not first and second:
        print('Button released!')

sudo ampy -p /dev/ttyUSB0 put main.py

Upload main.py to the microcontroller

ampy Cheet sheet

sudo ampy -p /dev/ttyUSB0 ls

List display

sudo ampy -p /dev/ttyUSB0 get ??????

Output the contents of ??????

sudo ampy -p /dev/ttyUSB0 put ??????

Upload ??????

sudo ampy -p /dev/ttyUSB0 rm ??????

Remove ??????

REPL connection

sudo pacman -S picocom

sudo picocom /dev/ttyUSB0 -b115200

picocom v3.1

port is        : /dev/ttyUSB0
flowcontrol    : none
baudrate is    : 115200
parity is      : none
databits are   : 8
stopbits are   : 1
escape is      : C-a
local echo is  : no
noinit is      : no
noreset is     : no
hangup is      : no
nolock is      : no
send_cmd is    : sz -vv
receive_cmd is : rz -vv -E
imap is        : 
omap is        : 
emap is        : crcrlf,delbs,
logfile is     : none
initstring     : none
exit_after is  : not set
exit is        : no

Type [C-a] [C-h] to see available commands
Terminal ready

key

Press the EN Button on the board

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:5008
ho 0 tail 12 room 4
load:0x40078000,len:10600
ho 0 tail 12 room 4
load:0x40080400,len:5684
entry 0x400806bc

key

Press the switch

Button pressed!
Button released!

Exit picocom

Ctrl + c

Exit En mode

Hold Ctrl + a Then release. Then hold Ctrl + x

End picocom

thank you

Thank you for watching until the end. I'm glad if you can use it as a reference.

Thank you for Helping

Give money to us for Amazon gift

We will continue to update useful information. I am delighted to jump to your help. Thank you very much.