终极ampy安装教程:3分钟上手MicroPython工具 终极ampy安装教程3分钟上手MicroPython工具【免费下载链接】ampyMicroPython Tool - Utility to interact with a MicroPython board over a serial connection.项目地址: https://gitcode.com/gh_mirrors/am/ampyampyAdafruit MicroPython工具是一款通过串口连接与CircuitPython或MicroPython开发板交互的命令行工具。它能轻松实现文件传输、代码执行等功能是MicroPython开发者的必备工具。本教程将带你快速完成ampy的安装与基础配置让你在3分钟内即可开始使用这个强大的工具。准备工作安装环境要求在开始安装ampy前请确保你的系统已满足以下要求Python环境支持Python 2.7.x或3.x版本推荐Python 3以获得最佳体验依赖库ampy需要以下Python库支持click命令行界面框架pyserial串口通信库python-dotenv环境变量管理工具这些依赖会在安装ampy时自动安装无需手动操作。快速安装3种方法任选方法1使用pip安装推荐这是最简单快捷的安装方式适用于大多数用户在MacOS或Linux系统打开终端执行pip3 install --user adafruit-ampy在Windows系统打开命令提示符执行pip install adafruit-ampy如果遇到权限问题Linux/MacOS可以尝试使用sudosudo pip3 install adafruit-ampy方法2从源码安装如果你需要最新开发版本可以从Git仓库克隆源码安装git clone https://gitcode.com/gh_mirrors/am/ampy cd ampy python3 setup.py install方法3开发模式安装如果你是开发者想要修改ampy源码并实时测试可以使用开发模式安装git clone https://gitcode.com/gh_mirrors/am/ampy cd ampy python3 setup.py develop验证安装确认ampy已正确安装安装完成后我们需要验证ampy是否可以正常运行。在终端或命令提示符中执行ampy --help如果安装成功你将看到ampy的帮助信息包含版本号当前最新为1.2.0和可用命令列表Usage: ampy [OPTIONS] COMMAND [ARGS]... ampy - Adafruit MicroPython Tool Ampy is a tool to control MicroPython boards over a serial connection. Using ampy you can manipulate files on the boards internal filesystem and even run scripts. Options: -p, --port PORT Name of serial port for connected board. [required] -b, --baud BAUD Baud rate for the serial connection. (default 115200) -d, --delay DELAY Delay in seconds before entering RAW MODE (default 0) --help Show this message and exit. Commands: get Retrieve a file from the board. ls List contents of a directory on the board. mkdir Create a directory on the board. mv Rename/move a file or directory on the board. put Put a file or folder and its contents on the board. rm Remove a file from the board. rmdir Forcefully remove a folder and all its children from the board. run Run a script and print its output. reset Perform soft reset/reboot of the board.基础配置设置环境变量为了避免每次使用ampy时都需要指定端口等参数我们可以通过环境变量或配置文件进行设置。临时环境变量设置在Linux/MacOS系统终端中执行export AMPY_PORT/dev/tty.SLAB_USBtoUART # 替换为你的串口 export AMPY_BAUD115200 # 波特率默认115200 export AMPY_DELAY0.5 # 延迟时间部分系统需要设置在Windows系统命令提示符中执行set AMPY_PORTCOM4 # 替换为你的串口 set AMPY_BAUD115200 set AMPY_DELAY0.5永久配置使用.ampy文件创建一个名为.ampy的文件保存以下内容根据你的实际情况修改# 示例.ampy配置文件 # 请填写你的端口、波特率和延迟时间 AMPY_PORT/dev/cu.wchusbserial1410 # Linux/MacOS示例 # AMPY_PORTCOM4 # Windows示例 AMPY_BAUD115200 # macOS用户解决Could not enter raw repl问题尝试0.5或更低值 AMPY_DELAY0.5将此文件保存到以下任一位置当前工作目录工作目录的任意父目录你的用户主目录常见问题解决权限问题如果遇到Permission denied错误可能是因为没有串口访问权限。在Linux系统中可以将用户添加到dialout组sudo usermod -a -G dialout $USER修改后需要注销并重新登录才能生效。依赖冲突如果安装过程中出现依赖冲突可以尝试使用虚拟环境python3 -m venv ampy-env source ampy-env/bin/activate # Linux/MacOS # ampy-env\Scripts\activate # Windows pip install adafruit-ampy端口识别不知道开发板的串口名称可以尝试以下方法Linux系统ls /dev/tty* | grep -i usbMacOS系统ls /dev/cu.* | grep -i usbWindows系统 在设备管理器的端口(COM和LPT)中查看开始使用ampy常用命令示例安装并配置完成后你可以开始使用ampy与MicroPython开发板交互了。以下是一些常用命令列出开发板文件ampy ls上传文件到开发板ampy put main.py从开发板下载文件ampy get boot.py在开发板上创建目录ampy mkdir lib运行开发板上的脚本ampy run test.py重置开发板ampy reset总结通过本教程你已经掌握了ampy的安装方法、配置技巧和基本使用命令。ampy作为一款轻量级但功能强大的MicroPython工具能够极大简化你的开发流程。无论是文件传输还是远程执行代码ampy都能帮你轻松完成。如果你想了解更多高级用法可以查看项目中的README.md文件或探索ampy的命令帮助信息。祝你在MicroPython开发之路上取得成功【免费下载链接】ampyMicroPython Tool - Utility to interact with a MicroPython board over a serial connection.项目地址: https://gitcode.com/gh_mirrors/am/ampy创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考