ESP32 PlatformIO IDE 安装教程

PlatformIO 简介

PlatformIO 是独立于平台运行的,实际上它只依赖于 python,然而 python 在 macOS、linux 和 windows 都能完美适配. 也就是说 PlatformIO 的工程从一个电脑很容易迁移到另一个电脑,只需要拷贝再使用 PlatformIO 就能完美打开,不管团队中的成员使用什么操作系统 PlatformIO 可以让工程共享变得异常简单. 除此之外, PlatformIO 不仅可以在笔记本和台式机上运行,同样可以运行在没有显示桌面的服务器。PlatformIO 的核心(PlatformIO Core) 就是一个终端程序, 它能配合您喜欢的多款云 IDE、桌面 IDE 或者 通用代码编辑器构建 PlatformIO 的 IDE,比如 Atom, CLion, Eclipse, Emacs, NetBeans, Qt Creator, Sublime Text, VIM, Visual Studio, VSCode 等等。

目前官方推荐的 IDE 使用方案就是 VSCode + PlatformIO IDE 插件,界面如图:
在这里插入图片描述

安装教程

提示:本篇文章使用的是官方推荐的IDE使用方案,所以要预先下载VSCode。
下载VSCode

1.在VSCode左侧活动栏搜索PlatformIO IDE。

在这里插入图片描述

2.找到PlatformIO IDE点击“install”。

3.等待下载好所有组件。(如果下的很慢,时常下到一半进度条不动请到跳到最后)。

在这里插入图片描述

4.安装完成后会在左侧活动栏中看到"蚂蚁头"的logo。

在这里插入图片描述

5.测试:试着完成一个小程序(实现esp32-cam闪灯)。

1.打开platform主页(点击“home”),选择新建项目。

在这里插入图片描述

2.键入项目名称,开发板名称,框架,项目的地址。(记住!!)

在这里插入图片描述

3.等待创建完成。

项目创建完成会有这几个目录。
在这里插入图片描述


4.我们闪灯的代码主要在main.cpp里面完成。

#include <Arduino.h>

// Set LED_BUILTIN if it is not defined by Arduino framework
// #define LED_BUILTIN 2

void setup()
{
  // initialize LED digital pin as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
  // turn the LED on (HIGH is the voltage level)
  digitalWrite(LED_BUILTIN, HIGH);
  // wait for a second
  delay(1000);
  // turn the LED off by making the voltage LOW
  digitalWrite(LED_BUILTIN, LOW);
   // wait for a second
  delay(1000);
}

代码的效果:esp32-cam的白色的led灯一亮一暗,时间间隔为1s。

5.代码的配置在platformio.ini文件里编写。

[env:esp32cam]
platform = espressif32
board = esp32cam
framework = arduino
monitor_speed = 115200
build_flags = 
	; https://docs.espresslf.com/projects/esp-dif/en/latest/get-started/get-started-wrover-kit.html#rgb-led
	-D LED_BUILTIN=4
lib_deps = yoursunny/esp32cam@^0.0.20221229

这是我的配置文件,这个程序主要就是想要哪个led灯闪就定义其对应的针脚。
白色led灯针脚为4,红色的则为33。
monitor_speed设置的是波特率,为了解决在运行是在Monitor里看到esp32-cam的信息为乱码。

6.编译,烧录,监控。
编译:将我们编写的代码编译成esp32-cam可运行的代码
烧录:将我们编写的代码转移到esp32-cam中
监控:显示esp32-cam运行后返回的信息
在这里插入图片描述
编写完程序我们先进行编译,然后烧录(esp32-cam处于下载模式),烧录完之后拔掉esp32-cam上的跳脚帽,按下reset键重启。之后就能看到esp32-cam上的白色led灯一亮一暗实现闪灯效果。
至此我们已成功在vscode中安装platformio IDE,并使用它编写了一个程序。

安装PlatformIO IDE进度条卡着不动解决方法。

1.修改host文件

#*********************github 2023-03-11 update********************
#******* get latest hosts: http://blog.yoqi.me/lyq/16489.html
151.101.65.194	github.global.ssl.fastly.net
185.199.111.153	assets-cdn.github.com
185.199.111.153	documentcloud.github.com
140.82.114.4	gist.github.com
185.199.110.133	gist.githubusercontent.com
185.199.109.154	github.githubassets.com
140.82.112.17	help.github.com
140.82.113.9	nodeload.github.com
185.199.111.133	raw.github.com
140.82.113.18	status.github.com
185.199.111.153	training.github.com
185.199.111.133	avatars.githubusercontent.com
185.199.110.133	avatars0.githubusercontent.com
185.199.108.133	avatars1.githubusercontent.com
185.199.110.133	avatars2.githubusercontent.com
185.199.108.133	avatars3.githubusercontent.com
185.199.110.133	avatars4.githubusercontent.com
185.199.109.133	avatars5.githubusercontent.com
185.199.109.133	avatars6.githubusercontent.com
185.199.109.133	avatars7.githubusercontent.com
185.199.108.133	avatars8.githubusercontent.com
185.199.109.133	favicons.githubusercontent.com
140.82.114.10	codeload.github.com
3.5.28.180	github-cloud.s3.amazonaws.com
52.217.197.113	github-com.s3.amazonaws.com
52.217.96.60	github-production-release-asset-2e65be.s3.amazonaws.com
52.216.246.4	github-production-user-asset-6210df.s3.amazonaws.com
54.231.131.49	github-production-repository-file-5c1aeb.s3.amazonaws.com
185.199.108.153	githubstatus.com
140.82.113.17	github.community
185.199.109.133	media.githubusercontent.com
185.199.110.133	camo.githubusercontent.com
185.199.111.133	raw.githubusercontent.com
185.199.109.133	cloud.githubusercontent.com
185.199.111.133	user-images.githubusercontent.com
185.199.110.153	customer-stories-feed.github.com
185.199.111.153	pages.github.com
140.82.112.5	api.github.com
140.82.112.25	live.github.com
140.82.114.29	githubapp.com
52.224.38.193	github.dev
140.82.112.3	github.com

windows:

1.文本编辑器“管理员权限”打开 C:\Windows\System32\drivers\etc\hosts 文件,新增一行,复制上面hosts内容并保存即可。

2.命令行执行 ipconfig /flushdns 刷新 dns,或者重启电脑。

mac:

1.文本编辑器打开 /etc/hosts 文件,新增一行,同上,复制上面的hosts内容即可。

2.命令行执行 sudo killall -HUP mDNSResponder ,或者重启电脑。
/etc/hosts 文件,新增一行,同上,复制上面的hosts内容即可。

2.命令行执行 sudo killall -HUP mDNSResponder ,或者重启电脑。

参考资料:
http://blog.yoqi.me/lyq/16489.html

  • 7
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值