700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > Arduino ESP8266 通过WiFi 串口与DMX灯光通讯

Arduino ESP8266 通过WiFi 串口与DMX灯光通讯

时间:2024-06-20 09:00:30

相关推荐

Arduino ESP8266 通过WiFi 串口与DMX灯光通讯

之前有项目做串口自定数据转dmx协议控制灯光。

链接

奔驰灯光互动项目开发历险记,春节前10天/qq_38288618/article/details/88559412

python 设备ArtNetToDMX512的协议测试/qq_38288618/article/details/87564627

前一阵呢有同仁看了找我交流,看能不能改wifi无线控制灯光。

正好有esp8266模块,wifi通讯是没问题的,觉得有戏,看有没有前辈老师们造好的轮子。

列出Brief :

1、smartconfig配网,8266连接AP

2、开UDP端口,接收解析数据

3、开串口,接收解析数据

4、将这些数据转换成DMX协议,发送给设备

5、按键控制配网任务

6、led显示运行状态

7、串口和udp数据自定协议

网上搜索了不少相关资料:

/ESP8266-Artnet-to-DMX/

/mtongnz/ESP8266_ArtNetNode_v2

/JonasArnold/EthernetDmxNode_esp8266

/sparkfun/SparkFunDMX

/forkineye/E131

/forkineye/ESPAsyncE131

/rstephan/ArtnetWifi

/FastLED/FastLED

/v6/api/jsondocument/

/mtongnz/espDMX

使用 espDMX库做个实践活动:

引用原文部分说明

esp8266DMX v2

Initial version by Matthew Tong, June . This library is derived from the HardwareSerial library.

This library has been updated to support new functionality but is compatible with the previous library.

This library will transmit up to 2 DMX universes from an ESP8266 module. It utilizes the hardware UARTs and is entirely interupt driven meaning the DMX output has very precise timing.

The DMX will refresh at a minimum rate of 44Hz. The library will detect how many channels have been set, outputting less than 512 if possible to increase the refresh rate. This increases the responsiveness of fixtures. It will still output a full 512 channels at least once per second.

View my Instructable for an ESP8266 Artnet to DMX device: /id/ESP8266-Artnet-to-DMX/

If this library is helpful and you're feeling generous, why not shout me a beer: https://www.paypal.me/mtongnz

主要大意简译:

8266开了两路dmx;

刷新频率至少44Hz,

作者DIY的链接

觉得有意义,可以请作者喝两杯啤酒,还是折现吧https://www.paypal.me/mtongnz(应该搞个微信、支付宝收款码效果会更好)

good,我觉得有意义。thanks,不过没办法请你喝两杯了,帮着宣传宣传吧,赠人玫瑰手留余香也好。

使用前文简易的diy多任务框架,造车主文件代码 :

前文任务框架在这里

/*dmxChaser - a simple example for espDMX libraryCopyright (c) , Matthew Tong/mtongnz/espDMXThis program is free software: you can redistribute it and/or modify it under the terms of the GNU General PublicLicense as published by the Free Software Foundation, either version 3 of the License, or (at your option) anylater version.This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the impliedwarranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.You should have received a copy of the GNU General Public License along with this program.If not, see /licenses/*/#include <ESP8266WiFi.h>#include <WiFiClient.h>#include <WiFiUdp.h>WiFiUDP Udp;char packetBuffer[UDP_TX_PACKET_MAX_SIZE + 1]; //buffer to hold incoming packet,char ReplyBuffer[] = "acknowledged\r\n"; // a string to send back#include <espDMX.h>unsigned char dd[512];void dmxWrite(int id , unsigned char v) {dd[id] = v;}#include "sys_rw.h"#include "rw_KEY.h"#include "rw_ledblink.h"#include "rw_smartconfig.h"#include "FramePkg.h"FramePkg pkg = FramePkg(520);//-------------//ff//[1~2]frame length//[3~4] startID//[5~n] data//crc//fe//-------------//n=5~516//frame length=7~519 pkg[1]+pkg[2]<<8//arr={3-n};//len=frame length-5;static void on_pkg_data_ok(unsigned char arr[], int len) {if (len >= 2) {//on_FramePkg_ok(arr, len);uint16_t startID = arr[0] + (arr[1] << 8);for (uint16_t i = 2; i < len; i++) {dmxWrite(startID + i - 2, arr[i]);//Serial.print(arr[i], 16);//Serial.print(" ");}dmxB.setChans(dd);} else {Serial.print("pkg err");}// Serial.println("ok");}// 10 steps with 10 channels in each//byte dmxChase[][10] = { { 255, 0, 0, 0, 0, 0, 0, 0, 0, 0 },// { 0, 255, 0, 0, 0, 0, 0, 0, 0, 0 },// { 0, 0, 255, 0, 0, 0, 0, 0, 0, 0 },// { 0, 0, 0, 255, 0, 0, 0, 0, 0, 0 },// { 0, 0, 0, 0, 255, 0, 0, 0, 0, 0 },// { 0, 0, 0, 0, 0, 255, 0, 0, 0, 0 },// { 0, 0, 0, 0, 0, 0, 255, 0, 0, 0 },// { 0, 0, 0, 0, 0, 0, 0, 255, 0, 0 },// { 0, 0, 0, 0, 0, 0, 0, 0, 255, 0 },// { 0, 0, 0, 0, 0, 0, 0, 0, 0, 255},// { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 },// { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }//};//===================================================typedef unsigned long clock_t;clock_t nowt ;clock_t oldt;unsigned char waitWIFI=0;void setup() {pkg.dispatch_event = &on_pkg_data_ok;Serial.begin(256000);// Start dmxA, status LED on pin 12 with full intensity//dmxA.begin(12);//dmxA.begin();// Start dmxB, status LED on pin 13 with 75/255 intensity//dmxB.begin(13, 75);dmxB.begin();////nowt = millis();rw_KEY_setup(0);rw_ledblink_setup(2);if (start_on_key_down == 1) {rw_smartconfig_setup(1);} else {WiFi.mode(WIFI_STA);delay(1000);//WiFi.begin("robotnet", "robotnetpass");//WiFi.setAutoConnect(true);//WiFi.setAutoReconnect(true);while (WiFi.status() != WL_CONNECTED) {delay(1000);waitWIFI++;if(waitWIFI>10){Serial.printf("wifi wait time out.");break;}Serial.printf("wifi wait %d\n.",waitWIFI);}unsigned int localPort = 6454;// local port to listen onSerial.printf("UDP server on port %d\n", localPort);Udp.begin(localPort);}oldt = nowt;}unsigned char sbuf[16];void loop() {nowt = millis();clock_t dis ;if (nowt >= oldt) {dis = nowt - oldt;} else {dis = (~oldt - 1) + nowt;}rw_run((int)dis);int packetSize = Udp.parsePacket();//Serial.println("packetSize");//Serial.println(packetSize);if (packetSize) {// Serial.printf("Received packet of size %d from %s:%d\n (to %s:%d, free heap = %d B)\n",// packetSize,// Udp.remoteIP().toString().c_str(), Udp.remotePort(),// Udp.destinationIP().toString().c_str(), Udp.localPort(),// ESP.getFreeHeap());int n = Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);packetBuffer[n] = 0;// Serial.print("lenth=");// Serial.println(n);// Serial.println("Contents:");// for (int i = 0; i < n; i++) {//Serial.write(packetBuffer[i]);// }pkg.writeArrayToBuf((unsigned char *)packetBuffer, n);}while (Serial.available()) {int numdata = Serial.readBytes(sbuf, 1);//Serial.write( sbuf[0]);pkg.writeArrayToBuf(sbuf, numdata);//Serial.write( pkg.getDatLen() );}// for (int i = 0; i < 10; i++) {//// // Output channels 1 - 10 on dmxA// dmxA.setChans(dmxChase[i], 10, 1);//// // Map values 1-5 to dmx channels 101 - 105 on dmxB// dmxB.setChans(dmxChase[i], 5, 101);//// // 1 second between each step// delay(1000);// }////// for (int i = 0; i < 170; i++) {//// int id = i * 3 ;// dmxWrite(id, 0xff);// dmxWrite(id + 1, 0x00);// dmxWrite(id + 2, 0x00);//// }// dmxB.setChans(dd);// delay(1000);// for (int i = 0; i < 170; i++) {//// int id = i * 3 ;// dmxWrite(id, 0x00);// dmxWrite(id + 1, 0x00);// dmxWrite(id + 2, 0xff);//// }// dmxB.setChans(dd);// delay(1000);// for (int i = 0; i < 170; i++) {//// int id = i * 3 ;// dmxWrite(id, 0x00);// dmxWrite(id + 1, 0xff);// dmxWrite(id + 2, 0x00);//// }// dmxB.setChans(dd);// delay(1000);//// for (int i = 0; i < 170; i++) {//// int id = i * 3 ;// dmxWrite(id, 0xff);// dmxWrite(id + 1, 0xff);// dmxWrite(id + 2, 0xff);//// }// dmxB.setChans(dd);// delay(1000);// for (int i = 0; i < 170; i++) {//// int id = i * 3 ;// dmxWrite(id, 0x00);// dmxWrite(id + 1, 0x00);// dmxWrite(id + 2, 0x00);//// }// dmxB.setChans(dd);// delay(1000);//// for (int i = 0; i < 170; i++) {//// int id = i * 3 ;// dmxWrite(id, 0xff);// dmxWrite(id + 1, 0xff);// dmxWrite(id + 2, 0xff);// dmxB.setChans(dd);// Serial.println(i);// if (i > 30 && i < 50)//delay(500);////// }// dmxB.setChans(dd);// delay(1000);////oldt = nowt;}

If this is helpful and you're feeling generous, why not shout me a beer。呵呵,maotai也是极好的。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。