测试ESP32-Zigbee转发命令 : 滑轨继电器控制
Posted 卓晴
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了测试ESP32-Zigbee转发命令 : 滑轨继电器控制相关的知识,希望对你有一定的参考价值。
简 介: 本文给出了利用ESP32-Zigbee 转发模块控制滑轨与继电器控制命令。
关键词
: ESP32,Zigbee,继电器
§01 ESP32转发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 转发模块控制滑轨与继电器控制命令。
■ 相关文献链接:
● 相关图表链接:
以上是关于测试ESP32-Zigbee转发命令 : 滑轨继电器控制的主要内容,如果未能解决你的问题,请参考以下文章
ESP3221.WIFI Web Servers 继电器实验(ESPAsyncWebServer-异步服务器库)
ESP3221.WIFI Web Servers 继电器实验(ESPAsyncWebServer-异步服务器库)
物联网 Nodemcu esp8266 LUA 脚本的 DAST 安全扫描 www HTML 服务器连接到摄像头和空调继电器
ESA2GJK1DH1K基础篇: APP使用APUConfig配网绑定ESP8266,实现远程温湿度显示和远程控制继电器