完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我正在使用此处读取卡尺测量值的代码:
://www.instructables.com/id/Interfacing-a-Digital-Micrometer-to-a-Microcontrol/在 Arduino Uno 上运行良好。现在我打算有一套测量设备,每个都基于Wemos D1R2,通过wifi将数据发送到服务器。 具体我现在的版本是这样的: 代码:全选#define Dest 2 //1=Arduino Uno; 2=Wemos D1R2&mini #if Dest==1 //Uno int req = 5; //mic REQ line goes to pin 5 through q1 (arduino high pulls request line low) int dat = 2; //mic Data line goes to pin 2 int clk = 3; //mic Clock line goes to pin 3 #endif #if Dest==2 //Wemos D1R2&mini int req = D5; //mic REQ line goes to pin 5 through q1 (arduino high pulls request line low) int dat = D2; //mic Data line goes to pin 2 int clk = D3; //mic Clock line goes to pin 3 #endif int i = 0; int j = 0; int k = 0; int signCh = 8; int sign = 0; int decimal; float dpp; int units; byte mydata[14]; String value_str; long value_int; //was an int, could not measure over 32mm float value; void setup() {//****************************************************************************** Serial.begin(9600); Serial.println("setup start"); pinMode(req, OUTPUT); pinMode(clk, INPUT_PULLUP); pinMode(dat, INPUT_PULLUP); digitalWrite(req,LOW); // set request at high Serial.println("setup end"); } void loop() { //****************************************************************************** Serial.println("loop start"); digitalWrite(req, HIGH); // generate set request for( i = 0; i < 13; i++ ) { k = 0; for (j = 0; j < 4; j++) { Serial.print("j="); Serial.println(j); while( digitalRead(clk) == LOW) { Serial.println("here"); } // hold until clock is high while( digitalRead(clk) == HIGH) { } // hold until clock is low bitWrite(k, j, (digitalRead(dat) & 0x1)); } mydata = k; } sign = mydata[4]; value_str = String(mydata[5]) + String(mydata[6]) + String(mydata[7]) + String(mydata[8] + String(mydata[9] + String(mydata[10]))) ; decimal = mydata[11]; units = mydata[12]; value_int = value_str.toInt(); if (decimal == 0) dpp = 1.0; if (decimal == 1) dpp = 10.0; if (decimal == 2) dpp = 100.0; if (decimal == 3) dpp = 1000.0; if (decimal == 4) dpp = 10000.0; if (decimal == 5) dpp = 100000.0; value = value_int / dpp; if (sign == 0) { Serial.println(value,decimal); } if (sign == 8) {Serial.print("-"); Serial.println(value,decimal);} digitalWrite(req,LOW); delay(100); } 但是在 Wemos D1R2 上使用草图时,出现如下“软 WDT 重置”错误: 代码:全选setup start Soft WDT reset ctx: cont sp: 3ffef200 end: 3ffef460 offset: 01b0 >>>stack>>> 3ffef3b0: feefeffe 3ffee32c 3ffee40c 40201f64 3ffef3c0: 0000001c 00000000 3ffee40c 40100574 3ffef3d0: feefeffe 00000001 3ffe84a1 40202d44 3ffef3e0: 00000000 00000008 3ffe844c 3ffee430 3ffef3f0: 3fffdad0 00000009 3ffee40c 402023c5 3ffef400: 3ffe84a0 3ffe8360 3ffee40c 402023c5 3ffef410: 3ffe8444 feefeffe 3ffee40c 402023f0 3ffef420: feefeffe feefeffe 3ffee40c 40202414 3ffef430: 3fffdad0 3ffe8360 3ffee40c 3ffee430 3ffef440: 3fffdad0 00000000 3ffee428 40202b44 3ffef450: feefeffe feefeffe 3ffee440 40100114 << |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
920 浏览 1 评论
552浏览 6评论
461浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
446浏览 5评论
446浏览 4评论
417浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 16:21 , Processed in 0.839734 second(s), Total 75, Slave 58 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号