当前位置:网站首页>测试ESP32-Zigbee转发命令 : 滑轨、继电器控制
测试ESP32-Zigbee转发命令 : 滑轨、继电器控制
2022-08-02 21:22:00 【卓晴】
简 介: 本文给出了利用ESP32-Zigbee 转发模块控制滑轨与继电器控制命令。
关键词
:ESP32,Zigbee,继电器
§01ESP32转发Zigbee
在利用ESP32构造一个ZIGBEE的网络发送转接 构造了一个通过ESP32转发ZigBee转发模块。下面对于这个模块中相关的很多命令进行测试。
一、继电器命令
改造其中的 zbcmd 函数,然后重新定义了一组继电器相关的命令。下面命令经过测试都可以正常执行。
#------------------------------------------------------------
ESP32_ZIGBEE_IP = '192.168.0.114'
ESP32_ZIGBEE_PORT = 4567
def zbcmd(str):
# ccloadSerial.write(str + b'\r')
strcmd = str + '\r'
udpsendstr(ESP32_ZIGBEE_IP,
ESP32_ZIGBEE_PORT,
strcmd)
下面是相应的改造命令:
#------------------------------------------------------------
def V45ON():
zbcmd('on')
def V45OFF():
zbcmd('off')
def V45SET(num):
zbcmd('set %d'%num)
#------------------------------------------------------------
def RClick():
zbcmd('solenoidrelay pulse 4 50')
def R1Click(t):
zbcmd('solenoidrelay pulse 2 %d'%t)
zbcmd('solenoidrelay pulse 2 %d'%t)
def R2Click(t):
zbcmd('solenoidrelay pulse 8 %d'%t)
zbcmd('solenoidrelay pulse 8 %d'%t)
def R1ON():
zbcmd('solenoidrelay on 2')
zbcmd('solenoidrelay on 2')
def R1OFF():
zbcmd('solenoidrelay off 2')
zbcmd('solenoidrelay off 2')
def R2ON():
zbcmd('solenoidrelay on 8')
zbcmd('solenoidrelay on 8')
def R2OFF():
zbcmd('solenoidrelay off 8')
zbcmd('solenoidrelay off 8')
def OCON(bit123):
setbit = 0x0
if (bit123 & 0x1) != 0:
setbit = setbit | 0x10
if (bit123 & 0x2) != 0:
setbit = setbit | 0x20
if (bit123 & 0x4) != 0:
setbit = setbit | 0x40
zbcmd('solenoidrelay on %x'%setbit)
def OCOFF(bit123):
setbit = 0x0
if (bit123 & 0x1) != 0:
setbit = setbit | 0x10
if (bit123 & 0x2) != 0:
setbit = setbit | 0x20
if (bit123 & 0x4) != 0:
setbit = setbit | 0x40
zbcmd('solenoidrelay off %x'%setbit)
def RAllON():
zbcmd('solenoidrelay set 0x7b')
def RALLOFF():
zbcmd('solenoidrelay set 0x0')
def RSetHV(num):
zbcmd('solenoidrelay hv %x'%num)
二、滑轨控制命令
1、单轴步进驱动SH-20403
在 单轴步进驱动模块SH-20403 给出了 SH-20403的驱动参数。
▲ 图1.2.1 单轴驱动器
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# LSCM8.PY -- by Dr. ZhuoQing 2022-08-01
#
# Note:
#============================================================
from headm import *
from tsmodule.tshardware import *
#------------------------------------------------------------
COMMAND_FRAME_HEAD = 0x56
COMMAND_FRAME_TAIL = 0x65
COMMAND_STATUS_WAIT = 0x0
COMMAND_STATUS_COMMAND = 0x1
COMMAND_STATUS_LENGTH = 0x2
COMMAND_STATUS_DATA = 0x3
COMMAND_STATUS_CHECK = 0x4
COMMAND_STATUS_TAIL = 0x5
#------------------------------------------------------------
COMMAND_HELLO_ECHO = 0x20
COMMAND_BEEP_ON = 0x21
COMMAND_BEEP_OFF = 0x22
COMMAND_DIR_ON = 0x23
COMMAND_DIR_OFF = 0x24
COMMAND_REL_ON = 0x25
COMMAND_REL_OFF = 0x26
COMMAND_PUL_SET = 0x27
COMMAND_PUL_STOP = 0x28
COMMAND_GOTO_HEAD = 0x29
COMMAND_GOTO_TAIL = 0x2A
COMMAND_GET_STATE = 0x2B
COMMAND_GET_PULSEOUT = 0x2C
COMMAND_CLEAR_PULSEOUT = 0x2D
#------------------------------------------------------------
def lscm8cmd(cmd, cmddata):
checksum = cmd + len(cmddata)
for cd in cmddata:
checksum = checksum + cd
checksum = (checksum & 0xff) ^ 0xff
cmdstr = b'' + byte(COMMAND_FRAME_HEAD) + byte(cmd) + byte(len(cmddata)) +\
cmddata + byte(checksum) + byte(COMMAND_FRAME_TAIL)
zbdata(cmdstr)
def lscm8hello():
lscm8cmd(COMMAND_HELLO_ECHO, b'')
def lscm8beepon():
lscm8cmd(COMMAND_BEEP_ON, b'')
def lscm8beepoff():
lscm8cmd(COMMAND_BEEP_OFF, b'')
#------------------------------------------------------------
def lscm8relon(bits):
cmd = bits.to_bytes(1, byteorder='big')
lscm8cmd(COMMAND_REL_ON, cmd)
#------------------------------------------------------------
# bits:0:relay0, 1:relay1
def lscm8reloff(bits):
cmd = bits.to_bytes(1, byteorder='big')
lscm8cmd(COMMAND_REL_OFF, cmd)
def lscm8diron(bits):
cmd = bits.to_bytes(1, byteorder='big')
lscm8cmd(COMMAND_DIR_ON, cmd)
def lscm8diroff(bits):
cmd = bits.to_bytes(1, byteorder='big')
lscm8cmd(COMMAND_DIR_OFF, cmd)
#------------------------------------------------------------
def lscm8setpulse(bits, pulse):
cmd = bits.to_bytes(1, byteorder='big') +\
pulse.to_bytes(4, byteorder='big')
lscm8cmd(COMMAND_PUL_SET, cmd)
def lscm8stoppulse():
lscm8cmd(COMMAND_PUL_STOP, b'')
def lscm8gotohead():
lscm8cmd(COMMAND_GOTO_HEAD, b'')
def lscm8gototail():
lscm8cmd(COMMAND_GOTO_TAIL, b'')
def lscm8clearpulseout():
lscm8cmd(COMMAND_CLEAR_PULSEOUT, b'')
def lscm8mf(steps):
lscm8diron(3)
lscm8reloff(3)
lscm8setpulse(3, steps)
def lscm8mb(steps):
lscm8diroff(3)
lscm8reloff(3)
lscm8setpulse(3, steps)
#------------------------------------------------------------
if __name__ == "__main__":
lscm8mb(1000)
#------------------------------------------------------------
# END OF FILE : LSCM8.PY
#============================================================
2、双轴滑轨控制
这个控制器在 DRV8825步进电机驱动控制模块以及双轴平台 进行了描述。
▲ 图1.2.1 Zigbee双轴驱动器
三组命令:
- zbcmd(’drvm1 1000’) : 对于顶层移动;
- zbcmd(’drvm2 1000’):对于底层驱动;
- zbcmd(’drvorg’) : 两个电机都回复的复位原点。
当参数大于零时,平台原理步进电机;当参数小于0,平台移动到步进电机;
- 移动参数: N= 200000,移动距离:6.6mm
from headm import *
from tsmodule.tshardware import *
zbcmd('drvorg')
3、双轴SH20403
在 SH-20403AXIS12双轴蓝牙移动框架 给出了这款ZIGBEE移动控制框架的描述。
▲ 图1.2.3 SH-20403双轴蓝牙移动
(1)波特率:115200;
(2)COM2:该端口已经连接有ZIGBEE
(1)波特率:115200;
(2)COM2:该端口已经连接有ZIGBEE
2.通讯命令
① sm2pul n1 n2 : 同时移动AXIS1,AXIS2
② sm2pul1 n1:移动AXIS1
n1的范围 41000
③ sm2pul2 n2:移动AXIS2
n2范围:195000:
移动距离100mm
④ sm2arr n : 0~65535 :设置TIM1的ARR
该数值不要小于50.
※ 总 结 ※
本文给出了利用ESP32-Zigbee 转发模块控制滑轨与继电器控制命令。
■ 相关文献链接:
● 相关图表链接:
边栏推荐
猜你喜欢
Add and delete all these years, finally planted in MySQL architecture design!
Flink Yarn Per Job - 启动AM
A brief discussion on the transformation of .NET legacy applications
圆锥折射作为偏振计量工具的模拟
win10安全中心设置不扫描某个文件夹的方法
行业 SaaS 微服务稳定性保障实战
【流媒体】推流与拉流简介
FRED应用:激光二极管光源耦合到光纤的仿真
面试官居然问我:删库后,除了跑路还能干什么?
ECCV 2022 | ByteTrack: 简单高效的数据关联方法
随机推荐
微软SQL服务器被黑客入侵以窃取代理服务的带宽
SublimeText3 安装、配置项、包管理、常用必备插件、常用快捷键以及修改
IP协议(网际协议)
Flink优化的方方面面
【3D视觉】深度摄像头与3D重建
Informatics Olympiad All-in-One (1257: Knight Moves)
包管理工具Chocolate - Win10如何安装Chocolate工具、快速上手、进阶用法
y85.第四章 Prometheus大厂监控体系及实战 -- prometheus告警机制进阶、pushgateway和prometheus存储(十六)
华为设备配置BFD多跳检测
The Orsay in Informatics (1256: Bouquet for Algernon)
解道9-编程技术6
Electrical diagram of power supply system
js: 实现一个cached缓存函数计算结果
博客主题美化第二弹
Add and delete all these years, finally planted in MySQL architecture design!
Command line startup FAQs and solutions
源码构建LAMP环境-3
【C语言进阶】--指针典题剖析
SSM integration steps (emphasis)
Adobe官方清理工具Adobe Creative Cloud Cleaner Tool使用教程