5686浏览
查看: 5686|回复: 2

[项目] 智能点灯=DFRduino UNO R3+ESP8266-01s模块+APP Inventor2

[复制链接]
本帖最后由 云天 于 2022-2-17 20:28 编辑

智能点灯=DFRduino UNO R3+ESP8266-01s模块+APP Inventor2图1

一直想实现一个小巧的WIFI开关,但想实现小巧,需要考虑电池、继电器、变压器、Wifi模块、控制器等的体积大小。近日在网上发现了ESP8266-01s模块应该能实现我的想法。购买回来之后,发现自己没有烧写程序的工具。
【DFRduino UNO R3烧写ESP8266-01s模块】
Arduino是一个世界级的电子原型开发平台,全球每天都有众多的电子爱好者,或者创客都在用它开发出令人脑洞大开又或者非常实用的小作品,而ESP8266则又是近几年大家都在讲的物联网界中的一批黑马,而且是总部位于上海的一家企业—乐鑫设计制造的,目前累计出货已经1亿多了,不仅创客非常喜欢玩这一款硬件,而且很多智能设备也都使用了这款芯片。
给ESP8266-01s烧写程序可使用USB -TTL模块,但我手里只有USB-Serial模块,两个的工作电压不同,USB -TTL模块为3.3V,而USB-Serial模块是5V。给ESP8266-01s烧写程序时,应使用3.3V。
解决方法:可使用DFRduino UNO R3作为 USB -TTL给ESP8266-01s烧写程序。
1、安装ESP8266板
这一步是非常重要的,因为Arduino支持开发非常多的硬件,但是不可能在安装包里就直接继承了这么多开发板的开发资源,因为很多硬件的架构和编译器都不一样,所以我们就需要安装一下附加开发板选项,也就是安装ESP8266的SDK和编译器之类的,但是由于SDK已经提供了Arduino的接口,所以我们就可以像开发UNO一样去开发ESP8266。我们依次点击文件->首选项->附加开发板管理器网址右侧的小图标,然后将以下内容添加进去:
  1. https://arduino.esp8266.com/stable/package_esp8266com_index.json
复制代码
智能点灯=DFRduino UNO R3+ESP8266-01s模块+APP Inventor2图15
之后点击工具 - 开发板 - 开发板管理器,进入开发板管理器界面:
智能点灯=DFRduino UNO R3+ESP8266-01s模块+APP Inventor2图16
输入esp, 找到 esp8266 并安装;
智能点灯=DFRduino UNO R3+ESP8266-01s模块+APP Inventor2图17
2、接线
ESP8266-01s模块与DFRduino UNO R3连接注意TX接TX, RX接RX(使板载USB转串口模块(FTDI/CH340G/PL2303/Atmega)的数据直接流转到其他设备,也因此Rx-Rx,Tx-Tx连接,无需像往常那样交叉连接。)。其它按下面的连接。
区分 下载模式和运行模式,就是GPIO0高低电平问题。
1、下载模式:CH_PD(EN)、RST、GPIO2、(接3.3V),GPIO0接地。
2、运行模式:CH_PD(EN)、RST、GPIO2、(接3.3V),GPIO0接3.3V。
智能点灯=DFRduino UNO R3+ESP8266-01s模块+APP Inventor2图19
智能点灯=DFRduino UNO R3+ESP8266-01s模块+APP Inventor2图3
智能点灯=DFRduino UNO R3+ESP8266-01s模块+APP Inventor2图4

3、DFRduino UNO R3配置
DFRduino UNO R3中可先烧写一个空程序(我烧写了一个Blink程序),也可烧写如下程序:
  1. void setup()
  2. {
  3.   pinMode(0,INPUT);
  4.   pinMode(1,INPUT);
  5. }
  6. void loop()
  7. {
  8. }
复制代码
可避免DFRduino UNO R3中原程序有使用到串口的代码,占用TX、RX引脚。
3、IDE进行如下设置:

智能点灯=DFRduino UNO R3+ESP8266-01s模块+APP Inventor2图18
4、上传ESP8266WIFI的相关程序
  1. /*
  2.     This sketch demonstrates how to set up a simple HTTP-like server.
  3.     The server will set a GPIO pin depending on the request
  4.       http://server_ip/gpio/0 will set the GPIO2 low,
  5.       http://server_ip/gpio/1 will set the GPIO2 high
  6.     server_ip is the IP address of the ESP8266 module, will be
  7.     printed to Serial when the module is connected.
  8. */
  9. #include <ESP8266WiFi.h>
  10. #ifndef STASSID
  11. #define STASSID "########"//自己WIFI的SSID
  12. #define STAPSK  "########"//自己WIFI的密码
  13. #endif
  14. #define JDQ 0
  15. const char* ssid = STASSID;
  16. const char* password = STAPSK;
  17. // Create an instance of the server
  18. // specify the port to listen on as an argument
  19. WiFiServer server(80);
  20. void setup() {
  21.   Serial.begin(115200);
  22.   // prepare LED
  23.   pinMode(LED_BUILTIN, OUTPUT);
  24.   pinMode(0, OUTPUT);
  25.   digitalWrite(LED_BUILTIN, 0);
  26.   // Connect to WiFi network
  27.   Serial.println();
  28.   Serial.println();
  29.   Serial.print(F("Connecting to "));
  30.   Serial.println(ssid);
  31.   WiFi.mode(WIFI_STA);
  32.   WiFi.begin(ssid, password);
  33.   while (WiFi.status() != WL_CONNECTED) {
  34.     delay(500);
  35.     Serial.print(F("."));
  36.   }
  37.   Serial.println();
  38.   Serial.println(F("WiFi connected"));
  39.   // Start the server
  40.   server.begin();
  41.   Serial.println(F("Server started"));
  42.   // Print the IP address
  43.   Serial.println(WiFi.localIP());
  44. }
  45. void loop() {
  46.   // Check if a client has connected
  47.   WiFiClient client = server.available();
  48.   if (!client) {
  49.     return;
  50.   }
  51.   Serial.println(F("new client"));
  52.   client.setTimeout(5000); // default is 1000
  53.   // Read the first line of the request
  54.   String req = client.readStringUntil('\r');
  55.   Serial.println(F("request: "));
  56.   Serial.println(req);
  57.   // Match the request
  58.   int val;
  59.   if (req.indexOf(F("/gpio/0")) != -1) {
  60.     val = 0;
  61.   } else if (req.indexOf(F("/gpio/1")) != -1) {
  62.     val = 1;
  63.   } else {
  64.     Serial.println(F("invalid request"));
  65.     val = digitalRead(LED_BUILTIN);
  66.   }
  67.   // Set LED according to the request
  68.   digitalWrite(LED_BUILTIN, val);
  69.   digitalWrite(JDQ, val);
  70.   // read/ignore the rest of the request
  71.   // do not client.flush(): it is for output only, see below
  72.   while (client.available()) {
  73.     // byte by byte is not very efficient
  74.     client.read();
  75.   }
  76.   // Send the response to the client
  77.   // it is OK for multiple small client.print/write,
  78.   // because nagle algorithm will group them into one single packet
  79.   client.print(F("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now "));
  80.   client.print((val) ? F("high") : F("low"));
  81.   client.print(F("<br><br>Click <a href='http://"));
  82.   client.print(WiFi.localIP());
  83.   client.print(F("/gpio/1'>here</a> to switch LED GPIO on, or <a href='http://"));
  84.   client.print(WiFi.localIP());
  85.   client.print(F("/gpio/0'>here</a> to switch LED GPIO off.</html>"));
  86.   // The client will actually be *flushed* then disconnected
  87.   // when the function returns and 'client' object is destroyed (out-of-scope)
  88.   // flush = ensure written data are received by the other side
  89.   Serial.println(F("Disconnecting from client"));
  90. }
复制代码

【硬件连接】
从旧风扇上拆下,变压模块,可由3.7V锂电池供电,升压到5-6V,可给ESP8266-01s继电器模块供电。
智能点灯=DFRduino UNO R3+ESP8266-01s模块+APP Inventor2图5
将ESP8266-01s插在继电器模块上
智能点灯=DFRduino UNO R3+ESP8266-01s模块+APP Inventor2图7
ESP8266-01s继电器模块供电
智能点灯=DFRduino UNO R3+ESP8266-01s模块+APP Inventor2图6

背景灯供电路与继电器连接
智能点灯=DFRduino UNO R3+ESP8266-01s模块+APP Inventor2图8

智能点灯=DFRduino UNO R3+ESP8266-01s模块+APP Inventor2图9

智能点灯=DFRduino UNO R3+ESP8266-01s模块+APP Inventor2图10

【APP Inventor2程序】
界面设计
智能点灯=DFRduino UNO R3+ESP8266-01s模块+APP Inventor2图12
逻辑设计
智能点灯=DFRduino UNO R3+ESP8266-01s模块+APP Inventor2图11
智能点灯=DFRduino UNO R3+ESP8266-01s模块+APP Inventor2图2
【App控制演示视频】

【组装灯】
智能点灯=DFRduino UNO R3+ESP8266-01s模块+APP Inventor2图13

智能点灯=DFRduino UNO R3+ESP8266-01s模块+APP Inventor2图14



水晶  初级技师

发表于 2022-3-8 12:19:07

6666666666666666666
回复

使用道具 举报

QQQQQQQ  初级技匠

发表于 2022-3-13 13:56:34

厉害厉害
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail