这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 活动中心 » 板卡试用 » esp32s3开发板驱动电机并测速

共1条 1/1 1 跳转至

esp32s3开发板驱动电机并测速

菜鸟
2026-07-14 07:31:26     打赏

一、产品概述

 

Adafruit 5691ESP32S3 Reverse TFT Feather) 是美国Adafruit公司推出的Feather规格物联网开发板,集成ESP32S3无线模组、1.14英寸反向安装TFT彩屏,专为面板安装与带屏IoT原型设计,支持Arduino/CircuitPython双开发环境。

 

二、核心参数

 

- 主控:ESP32S3Xtensa LX7双核,240 MHz),4 MB Flash + 2 MB PSRAM + 512 KB SRAM

 

- 无线:WiFi 802.11 b/g/n2.4 GHz)、Bluetooth 5.x BLE,模组带FCC/CE认证。

 

- 显示:1.14英寸IPS TFT240×135像素,反向安装(背面出线)。

 

- 接口:STEMMA QTI²C)、原生USBGPIO排针,预留3个按键位置。

 

- 供电:3.3 V,支持USB/电池供电,Feather标准尺寸(51×23 mm)。

 

三、产品特点

 

1. 反向屏幕设计:TFT屏装在板背,适配面板嵌入安装,正面可贴面板/外壳。

 

2. 大容量存储:4 MB Flash+2 MB PSRAM,支持CircuitPython大程序与图像缓存。

 

3. 即插即用生态:STEMMA QT免焊传感器扩展,Adafruit IO云平台无缝对接。

 

4. 双编程支持:Arduino IDECircuitPython,适合入门到进阶开发。

 

5. 无线一体化:WiFi+BLE双模,覆盖IoT数据传输与蓝牙近场通信场景。

四、测评内容

   本次测评将使用开发板产生PWM输出脉冲控制直流电机运行,然后通过引脚读取电机自带光电编码器输出脉冲进行测速,首先查询硬件引脚:

 image.png

image.png

 

电机引脚图如下:

image.png 

硬件接线如图:

image.png 

编写程序:

# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries

# SPDX-License-Identifier: MIT

# This example uses an L9110 H-bridge driver to run a DC Motor using two PWM pins.

#  https://www.adafruit.com/product/4489

# Hardware setup:

#   DC motor via L9110 H-bridge driver on two PWM pins that are on their own channels

#   e.g., RP2040 Pico pins GP28, GP27

import time

import board

import pwmio

import countio

from adafruit_motor import motor

PWM_PIN_A = board.D13  # pick any pwm pins on their own channels

PWM_PIN_B = board.D12

PULSE_PIN = board.D11

# 初始化计数器

# edge: 计数模式

#   countio.Edge.RISE: 仅计数上升沿

#   countio.Edge.FALL: 仅计数下降沿

#   countio.Edge.RISE_AND_FALL: 计数上升和下降沿(注意:部分ESP32变种可能不支持双边沿,若报错请改用单边沿)

try:

    counter = countio.Counter(PULSE_PIN, edge=countio.Edge.RISE)

except ValueError:

    # 如果双边沿不支持,尝试仅上升沿

    counter = countio.Counter(PULSE_PIN, edge=countio.Edge.RISE)

 

pwm_a = pwmio.PWMOut(PWM_PIN_A, frequency=10000)

pwm_b = pwmio.PWMOut(PWM_PIN_B, frequency=10000)

motor1 = motor.DCMotor(pwm_a, pwm_b)

 

print("***DC motor test***")

 

print("\nForwards slow")

motor1.throttle = 0.5

print("  throttle:", motor1.throttle)

time.sleep(1)

 

print("\n***Motor test is complete***")

 

print("开始计数... 请将脉冲信号连接到引脚:", PULSE_PIN)

 

last_count = 0

last_time = time.monotonic()

 

while True:

    current_count = counter.count

    current_time = time.monotonic()

 

    # 每秒打印一次计数值和频率

    if current_time - last_time >= 1.0:

        pulses_per_second = current_count - last_count

        print(f"总脉冲数: {current_count}, 最近1秒频率: {pulses_per_second} Hz")

 

        last_count = current_count

        last_time = current_time

 

    # 短暂延时,避免过度占用USB通信带宽,但不影响硬件计数

    time.sleep(0.1)

 

# 注意:在实际应用中,如果需要停止计数或释放引脚,请调用:

# counter.deinit()

 

 

REPL界面可以观察到1秒输入的脉冲个数:

image.png 

外接逻辑分析仪检测D13引脚脉冲输出:

image.png 

 





关键词: 电机     测速    

共1条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]