3年前能用,但现在连接不上了
CH340是盗版的,电脑驱动现在不兼容了
用外部usb转串口连esp8266 引脚上, 或在linux环境用
在 linux 环境用
bash
sudo apt install minicom
minicom -D /dev/ttyUSB0 -b 115200
# CTRL+ C 进交互
# CTRL+ D 进软重启
# CTRL+D X 退出minicom
MPY: soft reboot
led ▒亮
led ▒灭
led ▒亮
Traceback (most recent call last):
File "main.py", line 10, in <module>
KeyboardInterrupt:
MicroPython v1.19.1 on 2022-06-18; ESP module (1M) with ESP8266
Type "help()" for more information.
>>>
MPY: soft reboot
led ▒亮
安装 esptool
bash
# 更新包列表
sudo apt update
# 安装esptool
pip3 install esptool
或者
bash
sudo apt update
sudo apt install esptool
esptool命令
bash
minglie@minglie:~$ esptool --help
用法:esptool [-h] [--chip {auto,esp8266,esp32}] [--port 端口] [--baud 波特率]
[--before {default_reset,no_reset}]
[--after {hard_reset,soft_reset,no_reset}]
{load_ram,dump_mem,read_mem,write_mem,write_flash,run,image_info,make_image,elf2image,read_mac,chip_id,flash_id,read_flash_status,write_flash_status,read_flash,verify_flash,erase_flash,erase_region,version}
...
esptool.py v2.1 ------ ESP8266 芯片ROM引导加载工具
位置参数(子命令):
{load_ram,dump_mem,read_mem,write_mem,write_flash,run,image_info,make_image,elf2image,read_mac,chip_id,flash_id,read_flash_status,write_flash_status,read_flash,verify_flash,erase_flash,erase_region,version}
执行 esptool 子命令 -h 可查看该命令更多帮助
load_ram 将固件镜像下载到内存并运行
dump_mem 将任意内存内容导出保存到磁盘
read_mem 读取任意内存地址的数据
write_mem 对任意内存地址执行读‑修改‑写操作
write_flash 把二进制固件写入闪存(烧录固件)
run 运行闪存里的应用程序
image_info 打印应用固件镜像的头部信息
make_image 通过二进制文件生成应用固件镜像
elf2image 将ELF编译文件转为烧录用固件镜像
read_mac 从OTP只读存储器读取MAC地址
chip_id 从OTP只读存储器读取芯片ID
flash_id 读取SPI闪存的厂商ID与设备ID
read_flash_status 读取SPI闪存状态寄存器
write_flash_status 写入SPI闪存状态寄存器
read_flash 读取SPI闪存全部内容
verify_flash 将二进制文件和闪存内数据做校验比对
erase_flash 对SPI闪存执行整片擦除
erase_region 擦除闪存的某一段区域
version 打印esptool工具版本
可选参数:
-h, --help 显示帮助信息并退出
--chip {auto,esp8266,esp32}, -c {auto,esp8266,esp32}
指定目标芯片型号
--port 端口, -p 端口 串口设备路径(例如 /dev/ttyUSB0)
--baud 波特率, -b 波特率
烧录、读取时使用的串口波特率
--before {default_reset,no_reset}
连接芯片之前执行的操作
--after {hard_reset,soft_reset,no_reset}, -a {hard_reset,soft_reset,no_reset}
esptool执行完成之后执行的操作
读mac地址
bash
minglie@minglie:~$ sudo esptool -p /dev/ttyUSB0 read_mac
esptool.py v2.1
Connecting.....
Detecting chip type... ESP8266
Chip is ESP8266
Enabling default SPI flash mode...
MAC: 98:f4:ab:d5:1a:3d
Hard resetting...
刷固件
bash
minglie@minglie:~$ sudo esptool -p /dev/ttyUSB0 -b 460800 write_flash 0x00000 esp8266-1m-20220618-v1.19.1.bin
microPython 上传main.py
安装mpfshell-lite 改ttyUSB0权限
bash
# 安装mpfshell-lite
pip3 install --user mpfshell-lite
sudo chmod a+rw /dev/ttyUSB0
用mpfs上传main.py
bash
minglie@minglie:~/桌面$ export PATH="$HOME/.local/bin:$PATH"
minglie@minglie:~/桌面$ mpfs
Documented commands (type help <topic>):
========================================
EOF close get lexecfile ls mput open quit runfile
cat exec help lls md mpyc put repl view
cd execfile lcd lpwd mget mrm pwd rm
Undocumented commands:
======================
c e ef lef o q r rf v
can input help ls or other command if you don't know how to use it.
looking for all port...
serial name : ttyS0 : ttyS0
serial name : USB2.0-Ser! : ttyUSB0
input ' open ttyUSB0 ' and enter connect your board.
** Micropython File Shell v1.0.2, sw@kaltpost.de & junhuanchen@qq.com **
-- Running on Python 3.6 using PySerial 3.5 --
mpfs [/]> open /dev/ttyUSB0
Could not enter raw repl, Press Reset key after 5 seconds.
Connected to esp8266
mpfs [/]> ls
Remote files in '/':
boot.py
main.py
# 上传main.py
mpfs [/]> put main.py
main.py
transfer 62 of 62
mpfs [/]> repl
>
*** Exit REPL with Ctrl+] ***
MicroPython v1.19.1 on 2022-06-18; ESP module (1M) with ESP8266
Type "help()" for more information.
>>>