4 Star 52 Fork 16

HonestQiao / iot_beginner

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

互联网卷B同学玩转物联网开发入门课

  1. 安全说明:开发板是精密电子产品,怕水怕静电怕短路,特别是通电后,千万不要短路,不要直接触摸金属部分、针脚等!
  2. 最新版本:https://gitee.com/honestqiao/iot_beginner

学习硬件:

  • 开发板:ESP32-C3 开发板

    PIN_DEF
  • 元器件:

    • SHT30温湿度传感器:蓝色I2C板,或者绿色串口版
    • 红绿灯模块
    • 光敏二极管模块
    • 按键模块

入门步骤:

  • 刷机:

    • 刷机前准备

    • 使用VsCode + Haas Studio刷机:【Win10及以下、macOS Big Sur】

      • VsCode安装Haas Studio插件

      • 打开VsCode中的Haas Studio的烧录工具,选择正确的串口,以及上述准备好的固件

      • 烧录后,在下部的输出窗口,按上键,调出烧录执行的指令,把0x1000修改为0x00,然后回车,再次刷机

        esptool.py -b 460800 -p 串口号 write_flash 0x00 固件文件
    • 使用esptool刷机:【Win11及以下、macOS Monterey及以下、Linux】【推荐使用

      • 打开cmd,复制命令,然后将COM3d:\esp32c3-20220102-v1.17.bin 替换成实际串口号、固件文件,回车开始刷机

      • #Windows
        set PATH=%PATH%;%CD%
        
        #macOS、Linux
        export PATH="$PATH:$(pwd)"
        
        # 请根据系统,设置对应的COM端口和固件地址
        esptool -b 460800 -p COM3 erase_flash
        esptool -b 460800 -p COM3 write_flash 0x00 d:\esp32c3-20220102-v1.17.bin
        
        # 以下为输出结果
        esptool.py v3.2
        Serial port COM3
        Connecting....
        Detecting chip type... ESP32-C3
        Chip is ESP32-C3 (revision 3)
        Features: Wi-Fi
        Crystal is 40MHz
        MAC: 7c:df:a1:d6:55:14
        Uploading stub...
        Running stub...
        Stub running...
        Changing baud rate to 460800
        Changed.
        Configuring flash size...
        Flash will be erased from 0x00000000 to 0x0015afff...
        Compressed 1419328 bytes to 855976...
        Wrote 1419328 bytes (855976 compressed) at 0x00000000 in 23.8 seconds (effective 476.3 kbit/s)...
        Hash of data verified.
        
        Leaving...
        Hard resetting via RTS pin...
  • 编程交互:

    • Windows、macOS环境:

      • 使用Mu-Editor与设备交互;暂时不要使用VsCode + Haas Studio,因为用了也没用

      • 打开菜单左上角 模式 选择 Esp MicroPython,然后按照下面的方式即可运行代码:

        Mu.Editor
      • 编写代码,点菜单 运行,主板蓝灯亮起,点灯成功:

      from machine import Pin
      # 3 红 4 绿 5 蓝
      p4=Pin(5, Pin.OUT)
      p4.on()
    • Linux环境:

      • 操作参考上述Windows环境
  • 学习:

控制LED:

  • ESP32-C3开发板可以控制的LED:

    • 三色LED:GPIO3、GPIO4、GPIO5
    • 暖色:GPIO18
    • 冷色:GPIO19
    • 说明:开发板背面,标注了对应的端口
  • 操作指令:

    # 引用模块
    from machine import Pin
    
    # 初始化
    p3=Pin(3, Pin.OUT)    # 表示把GPIO3设置为输出状态
    p4=Pin(4, Pin.OUT)
    p5=Pin(5, Pin.OUT)
    p18=Pin(18, Pin.OUT)
    p19=Pin(19, Pin.OUT)
    
    # 点亮
    p3.on()
    p4.on()
    p5.on()
    p18.on()
    p19.on()
    
    # 熄灭 GPIO3、GPIO4、GPIO5可以交替on、off,观察LED的变化
    p3.off()
    p4.off()
    p5.off()
    p18.off()
    p19.off()

LED闪烁:注意缩进必须全部使用空格,不得使用tab

# 引用模块
from machine import Pin
import time

# 初始化
p3=Pin(3, Pin.OUT)    # 表示把GPIO3设置为输出状态

# 循环处理
while True:
    p3.on()
    time.sleep(1)    # 延时1秒
    p3.off()
    time.sleep(1)

LED 交替:注意缩进必须全部使用空格,不得使用tab

# 引用模块
from machine import Pin
import time

# 初始化
p3=Pin(3, Pin.OUT)    # 表示把GPIO3设置为输出状态
p4=Pin(4, Pin.OUT)
p5=Pin(5, Pin.OUT)

# 循环处理
times=0
while True:
    p3.off()
    p4.off()
    p5.off()
    if times % 3 == 0:
        p3.on()
    elif times % 3 == 1:
        p4.on()
    elif times % 3 == 2:
        p5.on()
    times+=1
    
    time.sleep(1)

例子程序:

  • Hello World

  • LED控制

  • LED循环控制

  • WiFi连接

  • mqtt通讯

  • mqtt控制LED

  • mqtt控制多个LED

  • 手机App组态控制LED

  • 温湿度读取

  • mqtt接收温湿度信息

  • 手机App组态接收温湿度信息

    手机端控制界面

补充说明:

  • 本仓库中,各软件所属版权归属各软件所有者,集中于此仅用于方便大家使用,如有不适尽情告知,将立刻处理,谢谢!
MIT License Copyright (c) 2022 HonestQiao Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

互联网卷B同学玩转物联网开发入门课仓库 展开 收起
Python
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Python
1
https://gitee.com/honestqiao/iot_beginner.git
git@gitee.com:honestqiao/iot_beginner.git
honestqiao
iot_beginner
iot_beginner
master

搜索帮助