本帖最后由 王大富 于 2021-7-15 20:58 编辑
1.硬件
esp8266,rs485转ttl,rs485接口得8通道采集器,应变片若干
2.接线方式
桥式应变片按照红黄蓝黑接到A,B,C,D上,普通应变片接到A,B上,并将B,B+短接,D和D+短接。之后将采集器的485A和B接到rs485转ttl的A和B上,最后将485的GND,RX,TX,VCC接到ESP8266上3.实物图
4.OneNET应用管理界面
5.代码
- <blockquote>#include <ESP8266WiFi.h> //esp8266wifi模块库
复制代码 JXBS.h函数
- #define MYADRESS1 0x01 //485地址
- const unsigned char readcmd1[8]={MYADRESS1,0x03,0x00,0x01,0x00,0x0A,0x94,0x0D}; //读取温湿度指令
- signed int strain_1=0,strain_2=0,strain_3=0,strain_4=0,strain_5=0,strain_6=0,strain_7=0,strain_8=0; //湿度
- void JXBSInit()
- {Serial.begin(9600);}
- unsigned char com_buf[150]; //接收数据缓存变量
- bool rec_flag=false;
- bool rec_flag1=false;
- bool receive_success_flag=false;
- bool receive_success_flag1=false;
- ///////////////////////////////////////////////
- void readJXBS1()
- {Serial.write(readcmd1,8);//发射数据
- }
- void JXBSListen1()
- {unsigned char com_num = 0;
- while (Serial.available())
- {char inChar = (char)Serial.read();
- com_buf[com_num] = inChar;
- com_num++;
- delay(2);
- }
- if(com_buf[0]==MYADRESS1 && com_buf[1]==0x03)
- {strain_1=com_buf[7]*256+com_buf[8];
- strain_2=com_buf[9]*256+com_buf[10];
- strain_3=com_buf[11]*256+com_buf[12];
- strain_4=com_buf[13]*256+com_buf[14];
- strain_5=com_buf[15]*256+com_buf[16];
- strain_6=com_buf[17]*256+com_buf[18];
- strain_7=com_buf[19]*256+com_buf[20];
- strain_8=com_buf[21]*256+com_buf[22];
- }
- }
复制代码
|