ESP32-C3 CORE 开发板,接口摸底

合宙的 ESP32-C3 CORE 开发板有 经典版(含CH343转串口芯片)和简约版(USB直接拉通芯片),设备管理器中显示的串口号不同:

 

 

 

 

 

 

 

 下载2个版本的线路图,D4-GPIO12,D5-GPIO13 LED灯KEY-GPIO19按键 标上注记,可以看出经典版走 CH343-GPIO20/21简约版走 USB-GPIO18/19

 

 

 

 

 

 

 

找到 blink.py 稍作修改,就能亮灯。

保存 + 执行 blink_input_ESP32-C3.py,D4/ D5 j交替亮灯,SHELL窗口显示BOOT按键值  key_boot: 1 ,key_boot: 0

# -*- coding: UTF-8 -*-
# 合宙CORE ESP32-C3 核心板板载2颗LED +  16MB Flash(原4MB)
# D4(GPIO12) 高电平有效
# D5(GPIO13) 高电平有效

import time
from machine import Pin

ledD4=Pin(12, Pin.OUT, value=0)     #create LED object from pin12,Set Pin12 to output
ledD5=Pin(13, Pin.OUT, value=0)     #create LED object from pin13,Set Pin13 to output
key_boot = Pin(9, Pin.IN, Pin.PULL_UP) # GPIO9/ KEY-BOOT_active0
print("key_boot:", key_boot())

while True:
    ledD4.value(1)        #turn on
    ledD5.value(0)        #turn off
    time.sleep(0.5)
    print("key_boot:", key_boot())
    ledD4(0)              #turn off
    ledD5(1)              #turn on
    time.sleep(0.5)
    print("key_boot:", key_boot())

 

测试所有GPIO口的输入上下拉 与 输出特性:

 

 

把GPIO口依序填入 ps[ ] 并执行测试。

ps = [2,3,10,6,7,11,5,4,8,9,0,1,12,13,18,19] #ESP32-C3 CH343 ,20,21

保存 + 执行 GPIOtest_ESP32-C3_CH343.py

SHELL窗口报错,无法使用,例如正在通信的 CH343-GPIO20/21

# 合宙CORE ESP32-C 核心板板载2颗LED +  16MB Flash(原4MB)
# D4(GPIO12) 高电平有效
# D5(GPIO13) 高电平有效

from machine import Pin
import time

ps = [2,3,10,6,7,11,5,4,8,9,0,1,12,13,18,19] #ESP32-C3 CH343 ,20,21
for p in ps:
    pi = Pin(p,Pin.IN,pull = Pin.PULL_DOWN)
    if(pi() == 1):
        print(p,pi(),"mode in with pulldown FAIL")
for p in ps:
    pi = Pin(p,Pin.IN,pull = Pin.PULL_UP)
    if(pi() == 0):
        print(p,pi(),"mode in with pullup")
for p in ps:
    pi = Pin(p,Pin.OUT,pull = Pin.PULL_DOWN)
    pi(1)
    if(pi() == 0):
        print(p,pi(),"out 1 FAIL")
    pi(0)
    if(pi() == 1):
        print(p,pi(),"out 0 FAIL")

led_d4 = Pin(12,Pin.OUT,pull = Pin.PULL_DOWN,value = 1) # D4 on
led_d5 = Pin(13,Pin.OUT,pull = Pin.PULL_DOWN,value = 0) # D5 off
while True:
    time.sleep_ms(500)
    led_d4(0)
    led_d5(1) # D5 on
    time.sleep_ms(500)
    led_d4(1)
    led_d5(0) # D5 off

 

把GPIO口依序填入 ps[ ] 并执行测试。

ps = [2,3,10,6,7,11,5,4,8,9,0,1,12,13,20,21] #ESP32-C3 USB ,18,19

保存 + 执行 GPIOtest_ESP32-C3_USB.py

SHELL窗口报错,无法使用,例如正在通信的USB-GPIO18/19

# 合宙CORE ESP32-C 核心板板载2颗LED +  16MB Flash(原4MB)
# D4(GPIO12) 高电平有效
# D5(GPIO13) 高电平有效

from machine import Pin
import time

ps = [2,3,10,6,7,11,5,4,8,9,0,1,12,13,20,21] #ESP32-C3 USB ,18,19
for p in ps:
    pi = Pin(p,Pin.IN,pull = Pin.PULL_DOWN)
    if(pi() == 1):
        print(p,pi(),"mode in with pulldown FAIL")
for p in ps:
    pi = Pin(p,Pin.IN,pull = Pin.PULL_UP)
    if(pi() == 0):
        print(p,pi(),"mode in with pullup")
for p in ps:
    pi = Pin(p,Pin.OUT,pull = Pin.PULL_DOWN)
    pi(1)
    if(pi() == 0):
        print(p,pi(),"out 1 FAIL")
    pi(0)
    if(pi() == 1):
        print(p,pi(),"out 0 FAIL")

led_d4 = Pin(12,Pin.OUT,pull = Pin.PULL_DOWN,value = 1) # D4 on
led_d5 = Pin(13,Pin.OUT,pull = Pin.PULL_DOWN,value = 0) # D5 off
while True:
    time.sleep_ms(500)
    led_d4(0)
    led_d5(1) # D5 on
    time.sleep_ms(500)
    led_d4(1)
    led_d5(0) # D5 off

 

 

 执行结果

心得:

  1. ps = [2,3] 可以一个一个的将GPIO数填入,马上做测试,不能用的GPIO口会报错或者无法正常执行
  2. 点亮 led_d4 能有多种写法:led_d4(1),led_d4.value(1)。有一种写法,这里不适用 led_d4.high()
  3. Tonny IDE 切换串口很容易,测试2个板子不费劲
  4. 试错在 micropython 里真的很方便,学习上更有效率

  

 

posted @ 2023-01-10 20:02  mickey_163  阅读(854)  评论(0编辑  收藏  举报