查看: 296|回复: 1
打印 上一主题 下一主题

【Seeed开发板试用体验】远程红外测距

[复制链接] qrcode

31

主题

33

帖子

100

积分

注册会员

Rank: 2

积分
100
楼主
跳转到指定楼层
发表于 2016-1-3 10:19 AM | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

纪念yeelink,那些年你很棒

本想用seeeduino配合yeelink玩一下,但是最近yeelink老出故障,下面的作品是之前用uno完成的,大家可以直接移植到seeeduino,无需修改。

接上一篇帖子http://bbs.ickey.cn/group-topic-id-63268.html

硬件:seeeduino V4,GP2D12、W5100


1W5100扩展版对应安插在Arduino上,参考

 http://bbs.ickey.cn/group-topic-id-62818.html

2. 按下图连接线路(传感器脚图中接ARDUINO A0脚),需要进行模数转换。DA转换原理不再赘述。arduino的AD引脚是10位的采样精度。即范围0-1023,。



3. USB数据线将Arduino与电脑连接起来

4. 用网线将W5100连接到路由器
5. 将准备好的程序传输到Arduino开发板上


主程序


void sendData(int thisData) {
  // if there\'s a successful connection:
  if (client.connect(server, 80)) {
    Serial.println("connecting...");
    // send the HTTP PUT request:
    client.print("POST /v1.0/device/");
    client.print(DEVICEID);
    client.print("/sensor/");
    client.print(SENSORID);
    client.print("/datapoints");
    client.println(" HTTP/1.1");
    client.println("Host: api.yeelink.net");
    client.print("Accept: *");
    client.print("/");
    client.println("*");
    client.print("U-ApiKey: ");
    client.println(APIKEY);
    client.print("Content-Length: ");
    
    
    int thisLength = 10 + getLength(thisData);
    client.println(thisLength);
    client.println();
    // here\'s the actual content of the PUT request:
    client.print("{"value":");
    client.print(thisData);
    client.println("}");
  }
  else {
    // if you couldn\'t make a connection:
    Serial.println("connection failed");
   
    Serial.println("disconnecting.");
    client.stop();
  }
   // note the time that the connection was made or attempted:
  lastConnectionTime = millis();
}

// This method calculates the number of digits in the
// sensor reading.  Since each digit of the ASCII decimal
// representation is a byte, the number of digits equals
// the number of bytes:

  // return the number of digits:
 int getLength(int someValue)
{
  // there\'s at least one byte:
  int digits = 1;
  // continually divide the value by ten,
  // adding one to the digit count for each
  // time you divide, until you\'re at 0:
  int dividend = someValue /10;
  while (dividend > 0)
  {
    dividend = dividend /10;
    digits++;
  }
  // return the number of digits:
  return digits;
}

客户端




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

0

主题

84

帖子

26

积分

新手上路

Rank: 1

积分
26
沙发
发表于 2016-1-3 10:22 AM | 只看该作者

以上为部分程序

 换算关系:val(传感器数据端口电压) = val1(模拟采样值)*5/1024

然后由端口电压与距离关系推算出物体距离

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表