winterw 发表于 2016-6-4 12:28:04

[分享]搭建esp8266+ardunio-IDE的开发环境

本帖最后由 winterw 于 2016-6-4 12:30 编辑

前面的文章说明了如何安装arduino的IDE。http://www.amobbs.com/thread-5652063-1-1.html
这篇文章主要记录如何通过arduino编译下载后的代码到esp8266的板子上去。

首先按照原理图连接好esp8266的各个引脚。

需要说明的是,我用的usb2ttl是没有RTS和DTR这两个引脚的。



所以REST通过10K的上拉接到VCC,然后想复位的时候手动连接到GND一下。
GPIO0引脚也如法炮制。

其他引脚按照上面的电路图连接就行。

完了之后打开电源,可以看到esp8266板子上的蓝色LED闪了一下,不知道什么意思,看起来是活了,仔细观察了一会,板子没有冒烟儿,不错。继续。

回到Arduino-IDE。上一篇记录已经安装完了SDK,所以此时需要选一个板子的SDK。
Tools->Board里面就选吧,我这里就选了个Generic ESP8266 Module,你要问我为什么选这个,我会告诉你,我看视频里就选的这个,你会问哪里的视频? 视频在这里 https://www.youtube.com/watch?v=8J7zflVO8K0 其实也能猜出来,毕竟我买的时候人卖家也没说我这是什么什么开发板,都是公版来的,那不是generic是什么,当然了,这种猜测也不完全正确,万一错了也好办,就一个一个的试吧,啥都不懂的时候是这样的,就像没头的苍蝇乱撞一样。所以为了防止以为我哪天想不起来怎么搭建环境了,趁着现在还有印象赶紧记下来吧,也别说我很无私为了大家,其实也为了自己。你看,事情往往就是这样,没有唯一的属性。



这里还有个疑问,就是我不知道板子上的flash是多大的,所以暂时先选512K,以后再想办法看看能不能读取板子上的flash容量。

然后开始选择测试程序,见下图,选HelloServer。


然后需要修改一下代码中的变量值,把你家里的WIFI的SSID和接入面面填进去。


然后怀着忐忑的心开始编译,下载,也就是点击Arduino上的Upload按钮,我会成功吗?会成功吗?就这样担心的看着它在编译,过了一会,一颗激动的心终于平静了,那是因为我看到了结果…MBD我就就知道没有这么简单。


我一看图片,卧槽,这是什么鬼,通讯错了?
检查了一下硬件和设置参数,没错啊,跟视频上的一样。

然后放狗去搜,点了几个链接后欣然发现这是个通病。
http://arduino.stackexchange.com/questions/20219/upload-with-esptool-fails-with-espcomm-send-command-cant-receive-slip-payload

摘录如下:
This is a known issue with the included esptool, and for the Arduino IDE there are quite a few blog posts to be found on this problem. But most are outdated, and are not applicable when using PlatformIO with some other IDE. So, February 2016:

Install esptool.py

git clone https://github.com/themadinventor/esptool/ (or download the ZIP file)
cd esptool
sudo Python setup.py install
When using Arduino IDE

Open ~/Library/Arduino15/packages/esp8266/hardware/esp8266/2.0.0/platform.txt.
Find the line tools.esptool.upload.pattern and disable that by prefixing with a hash. Check that your version only mentions -ca 0x00000, not -ca 0x10000 as well (like in most outdated blog posts):

# tools.esptool.upload.pattern="{path}/{cmd}" {upload.verbose} -cd {upload.resetmethod} -cb {upload.speed} -cp "{serial.port}" -ca 0x00000 -cf "{build.path}/{build.project_name}.bin"

Add the following, referring to the esptool.py you installed above and also using different command line parameters:

# Fix for espcomm_send_command: cant receive slip payload data
tools.esptool.upload.pattern="/path/to/new/esptool.py" --port "{serial.port}" --baud {upload.speed} write_flash 0x00000 "{build.path}/{build.project_name}.bin"

Restart the IDE.
(One might be tempted to just change tools.esptool.path and tools.esptool.cmd instead, but beware that the command line parameters need changing as well.)

完全照做。

重启IDE之后再次点击Upload,喔,看起来好像下载成功了?真的成功了?


此时把GPIO0的接地端把掉,让它接到VCC,即退出flash编程模式,然后累,把RST接地地一下,也就是复位一下,这时打开串口,没有意外的话应该能看到下图的提示信息:


bluechris是我的wifi-ssid,就是在HelloServer中填写的那个ssid的变量值。

这时基本上就是成功了,为什么说是基本上呢,因为还需要最后一步,找个终端比如手机或pc的浏览器,访问一下esp8266的局域网地址,看看它是不是把自己当服务器运行呢。



看到上面的那个图才可以说:终于完成了。我流下了两行幸福的眼泪。

Shampoo 发表于 2016-6-4 14:26:21

不错,现在都用官方SDK开发。

mcuprogram 发表于 2016-6-4 23:02:45

mark         

shawn_bu 发表于 2016-6-5 05:36:49

直接买了一个nodemcu,二十块钱左右,不用折腾。我已经做了一个温度湿度的终端。https://thingspeak.com/channels/121508有Google cdn引用,需*蔷*外*才能打开。

winterw 发表于 2016-6-5 05:56:02

shawn_bu 发表于 2016-6-5 05:36
直接买了一个nodemcu,二十块钱左右,不用折腾。我已经做了一个温度湿度的终端。https://thingspeak.com/ch ...

你的flash是多大的

shawn_bu 发表于 2016-6-5 18:47:40

winterw 发表于 2016-6-5 05:56
你的flash是多大的

我也不知道,没看详细的。

winterw 发表于 2016-6-5 20:07:26

shawn_bu 发表于 2016-6-5 18:47
我也不知道,没看详细的。

我知道我的是多大了,512K。调用这个接口 ESP.getFlashChipSize() 可以显示出来。

shawn_bu 发表于 2016-6-14 20:40:26

buck 发表于 2016-6-14 10:55
呵呵,坐标暴露了,温度数据太平了,连续10小时保持27度?

哈哈,,坐标是暴露了。现在温度有曲线了。不知道是否是温度传感器不靠谱。

yinian 发表于 2016-10-26 21:56:29

mark 谢谢

zhang_mike2000 发表于 2016-11-16 16:50:31

按楼主的方法搞成了,谢谢

aitchow 发表于 2018-7-3 21:56:27

多谢。开始学esp8266

Joyje 发表于 2018-10-8 15:10:56

刚接触,学习一下

chengying 发表于 2019-4-8 17:44:48

用arduino 确实简单

fsclub 发表于 2019-4-8 17:58:12

最可恨的是更新开发板管理器的时候因墙原因频繁失败

sniper.q 发表于 2019-4-8 18:26:02

stm32F1, F4也可以用ardunio-IDE
https://github.com/rogerclarkmelbourne/Arduino_STM32
页: [1]
查看完整版本: [分享]搭建esp8266+ardunio-IDE的开发环境