查看: 7207|回复: 21

【Z】

[复制链接]

该用户从未签到

发表于 2014-8-9 10:19 | 显示全部楼层 |阅读模式
本帖最后由 Zzz 于 2017-4-25 10:56 编辑

111
图片1.jpg
图片2.png
图片3.png
图片4.jpg
图片5.jpg
图片6.jpg
图片7.png
图片8.png
图片9.png
图片10.jpg
图片11.png
图片12.jpg
图片13.jpg
图片14.jpg
图片15.jpg
图片16.png
图片17.png
图片18.png
图片19.png

该用户从未签到

 楼主| 发表于 2014-8-9 11:03 | 显示全部楼层
图片集:
QQ截图20140809105955.bmp

QQ截图20140809110052.bmp

QQ截图20140809110058.bmp

QQ截图20140809110103.bmp

QQ截图20140809110109.bmp

QQ截图20140809110116.bmp

QQ截图20140809110121.bmp

QQ截图20140809110150.bmp



该用户从未签到

 楼主| 发表于 2014-8-9 10:57 | 显示全部楼层
以下是各个部分的程序内容~
无线传感网络终端Yeelink联网部分
[mw_shl_code=c,true]#include <Wire.h>
#include <Ethernet.h>
#include <WiFi.h>
#include <SPI.h>
#include <yl_data_point.h>
#include <yl_device.h>
#include <yl_w5100_client.h>
#include <yl_wifi_client.h>
#include <yl_messenger.h>
#include <yl_sensor.h>
#include <yl_value_data_point.h>
#include <yl_sensor.h>

yl_device ardu(11260);  
yl_sensor therm(18633, &ardu);
yl_sensor pr(18635, &ardu);
yl_sensor d(18637, &ardu);
//replace first param value with ur u-apikey
yl_w5100_client client;
yl_messenger messenger(&client, "ed27f020ba253e9af28fea516a1b1056", "api.yeelink.net");   //此处替换为你自己的API KEY

#define BMP085_ADDRESS 0x77  // I2C address of BMP085

const unsigned char OSS = 0;  // Oversampling Setting

// Calibration values
int ac1;
int ac2;
int ac3;
unsigned int ac4;
unsigned int ac5;
unsigned int ac6;
int b1;
int b2;
int mb;
int mc;
int md;

// b5 is calculated in bmp085GetTemperature(...), this variable is also used in bmp085GetPressure(...)
// so ...Temperature(...) must be called before ...Pressure(...).
long b5;

short temperature;
long pressure;

void setup()
{
  Serial.begin(9600);
  Wire.begin();
  bmp085Calibration();
  byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xAA};
  Ethernet.begin(mac);
}

void loop()
{
  int val;
  val=analogRead(0);
  temperature = bmp085GetTemperature(bmp085ReadUT());
  pressure = bmp085GetPressure(bmp085ReadUP());
  

  Serial.print(11);
  Serial.print(",");
  Serial.print(temperature);
  Serial.print(",");
  Serial.print(pressure/10);
  
  yl_value_data_point d1(temperature*0.1);
  therm.single_post(messenger, d1);
  
  yl_value_data_point d2(pressure/10);
  pr.single_post(messenger, d2);
  
  yl_value_data_point d3(val/10);
  d.single_post(messenger, d3);
  
  delay(2000);
}

// Stores all of the bmp085's calibration values into global variables
// Calibration values are required to calculate temp and pressure
// This function should be called at the beginning of the program
void bmp085Calibration()
{
  ac1 = bmp085ReadInt(0xAA);
  ac2 = bmp085ReadInt(0xAC);
  ac3 = bmp085ReadInt(0xAE);
  ac4 = bmp085ReadInt(0xB0);
  ac5 = bmp085ReadInt(0xB2);
  ac6 = bmp085ReadInt(0xB4);
  b1 = bmp085ReadInt(0xB6);
  b2 = bmp085ReadInt(0xB8);
  mb = bmp085ReadInt(0xBA);
  mc = bmp085ReadInt(0xBC);
  md = bmp085ReadInt(0xBE);
}

// Calculate temperature given ut.
// Value returned will be in units of 0.1 deg C
short bmp085GetTemperature(unsigned int ut)
{
  long x1, x2;
  
  x1 = (((long)ut - (long)ac6)*(long)ac5) >> 15;
  x2 = ((long)mc << 11)/(x1 + md);
  b5 = x1 + x2;

  return ((b5 + 8)>>4);  
}

// Calculate pressure given up
// calibration values must be known
// b5 is also required so bmp085GetTemperature(...) must be called first.
// Value returned will be pressure in units of Pa.
long bmp085GetPressure(unsigned long up)
{
  long x1, x2, x3, b3, b6, p;
  unsigned long b4, b7;
  
  b6 = b5 - 4000;
  // Calculate B3
  x1 = (b2 * (b6 * b6)>>12)>>11;
  x2 = (ac2 * b6)>>11;
  x3 = x1 + x2;
  b3 = (((((long)ac1)*4 + x3)<<OSS) + 2)>>2;
  
  // Calculate B4
  x1 = (ac3 * b6)>>13;
  x2 = (b1 * ((b6 * b6)>>12))>>16;
  x3 = ((x1 + x2) + 2)>>2;
  b4 = (ac4 * (unsigned long)(x3 + 32768))>>15;
  
  b7 = ((unsigned long)(up - b3) * (50000>>OSS));
  if (b7 < 0x80000000)
    p = (b7<<1)/b4;
  else
    p = (b7/b4)<<1;
   
  x1 = (p>>8) * (p>>8);
  x1 = (x1 * 3038)>>16;
  x2 = (-7357 * p)>>16;
  p += (x1 + x2 + 3791)>>4;
  
  return p;
}

// Read 1 byte from the BMP085 at 'address'
char bmp085Read(unsigned char address)
{
  unsigned char data;
  
  Wire.beginTransmission(BMP085_ADDRESS);
  Wire.write(address);
  Wire.endTransmission();
  
  Wire.requestFrom(BMP085_ADDRESS, 1);
  while(!Wire.available())
    ;
   
  return Wire.read();
}

// Read 2 bytes from the BMP085
// First byte will be from 'address'
// Second byte will be from 'address'+1
int bmp085ReadInt(unsigned char address)
{
  unsigned char msb, lsb;
  
  Wire.beginTransmission(BMP085_ADDRESS);
  Wire.write(address);
  Wire.endTransmission();
  
  Wire.requestFrom(BMP085_ADDRESS, 2);
  while(Wire.available()<2)
    ;
  msb = Wire.read();
  lsb = Wire.read();
  
  return (int) msb<<8 | lsb;
}

// Read the uncompensated temperature value
unsigned int bmp085ReadUT()
{
  unsigned int ut;
  
  // Write 0x2E into Register 0xF4
  // This requests a temperature reading
  Wire.beginTransmission(BMP085_ADDRESS);
  Wire.write(0xF4);
  Wire.write(0x2E);
  Wire.endTransmission();
  
  // Wait at least 4.5ms
  delay(5);
  
  // Read two bytes from registers 0xF6 and 0xF7
  ut = bmp085ReadInt(0xF6);
  return ut;
}

// Read the uncompensated pressure value
unsigned long bmp085ReadUP()
{
  unsigned char msb, lsb, xlsb;
  unsigned long up = 0;
  
  // Write 0x34+(OSS<<6) into register 0xF4
  // Request a pressure reading w/ oversampling setting
  Wire.beginTransmission(BMP085_ADDRESS);
  Wire.write(0xF4);
  Wire.write(0x34 + (OSS<<6));
  Wire.endTransmission();
  
  // Wait for conversion, delay time dependent on OSS
  delay(2 + (3<<OSS));
  
  // Read register 0xF6 (MSB), 0xF7 (LSB), and 0xF8 (XLSB)
  Wire.beginTransmission(BMP085_ADDRESS);
  Wire.write(0xF6);
  Wire.endTransmission();
  Wire.requestFrom(BMP085_ADDRESS, 3);
  
  // Wait for data to become available
  while(Wire.available() < 3)
    ;
  msb = Wire.read();
  lsb = Wire.read();
  xlsb = Wire.read();
  
  up = (((unsigned long) msb << 16) | ((unsigned long) lsb << 8) | (unsigned long) xlsb) >> (8-OSS);
  
  return up;
}
[/mw_shl_code]


无线传感网络TFT监视终端部分
[mw_shl_code=c,true]#include <ITDB02_Graph16.h>

extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];

ITDB02 myGLCD(38,39,40,41);

int r;
int g;
int b;

String comdata = "";
int numdata[3] = {0}, mark = 0;

void setup()
{
  Serial.begin(9600);
  Serial3.begin(9600);
  myGLCD.InitLCD(LANDSCAPE);
  myGLCD.clrScr();
  myGLCD.setFont(BigFont);
  
    myGLCD.print("MegaLink Terminal", 0, 0);
    myGLCD.setColor(0, 0, 255);
    myGLCD.print("Normal operation", 0,220);
   
    myGLCD.setColor(255, 255, 255);
    myGLCD.print("T1:       D1:", 0,40);
    myGLCD.print("T2:       D2:", 0,80);
    myGLCD.print("T3:       D3:", 0,120);
    myGLCD.print("TM:       AT:", 0,160);

    //myGLCD.setFont(SevenSegNumFont);
    myGLCD.setColor(0, 255, 0);
    int a=0;
    myGLCD.printNumI(a, 50, 40);
    myGLCD.printNumI(a, 50, 80);
    myGLCD.printNumI(a, 50, 120);
    myGLCD.printNumI(a, 50, 160);
   
    myGLCD.printNumI(a, 210, 40);
    myGLCD.printNumI(a, 210, 80);
    myGLCD.printNumI(a, 210, 120);
    myGLCD.printNumI(a, 210, 160);
}

void loop()
{
  

if (Serial3.available())
  {
    while(Serial3.available())
    {
      SerialReadVal(3);
    }
  }
}

void SerialReadVal(unsigned int comdata_digit)
{
  String comdata = "";  //串口字符串传递变量
  char comdata_mark = ','; //字符串分段标志,可更改
  int comdata_mark_count = 0; //分段标志数量
  unsigned int comdata_mark_list[63]; //分段标志位置列表,最大63+1段,此三项可视实际情况增减
  unsigned int comdata_val_long[64]; //每段字串长度列表,最大64段
  String comdata_val[64]; //分段字符串列表,最大64段数据,此数组可在程序开始定义为全局变量,用于返回数据,数据可继续进行深加工

  //读入串口数据并赋值给传递变量
  while (Serial3.available() > 0)
  {
    comdata += char(Serial3.read());
    delay(2);
  }
  Serial.println(comdata);
  //确定分段标志位置,并判断输入段数是否符合给定值
  for (int i = 0; i < comdata.length(); i++)
  {
    if (comdata.charAt(i) == comdata_mark)
    {
      comdata_mark_list[comdata_mark_count] = i;
      comdata_mark_count++;
    }
  }
  for (int i = 0; i <= comdata_mark_count; i++)
  {
    if (i == 0) comdata_val_long[0] = comdata_mark_list[0];
    else if (i == comdata_mark_count) comdata_val_long = comdata.length() - comdata_mark_list[i-1] - 1;
    else comdata_val_long = comdata_mark_list - comdata_mark_list[i-1] - 1;
  }

  if (comdata_mark_count < (comdata_digit - 1)) return;

  //按给定的段数分段
  for (int i = 0; i < comdata_digit; i++)
  {
    if (i == 0)
    {
      for (int ii = 0; ii < comdata_val_long[0]; ii++) comdata_val += comdata.charAt(ii);
    }
    else
    {
      for (int ii = 0; ii < comdata_val_long; ii++) comdata_val += comdata.charAt(comdata_mark_list[i-1]+1+ii);
    }
  }
  for (int i = 0; i < comdata_digit; i++); //Serial.println(comdata_val); // 串口监视程序运行
  b=comdata_val[2].toInt() ;
  g=comdata_val[1].toInt() ;
  r=comdata_val[0].toInt() ;
  show(r,g,b);
}

void show(int r,int g,int b){
  if(r==10){
    myGLCD.print("    ", 50, 40);
    myGLCD.print("    ", 210, 40);
    myGLCD.printNumI(b, 50, 40);
    myGLCD.printNumI(g, 210, 40);
  }
  
  if(r==12){
    myGLCD.print("    ", 50, 80);
    myGLCD.print("    ", 210, 80);
    myGLCD.printNumI(b, 50, 80);
    myGLCD.printNumI(g, 210, 80);
  }
  
  if(r==13){
    myGLCD.print("    ", 50, 120);
    myGLCD.print("    ", 210, 120);
    myGLCD.printNumI(b, 50, 120);
    myGLCD.printNumI(g, 210, 120);
  }
  
  if(r==11){
    myGLCD.print("    ", 50, 160);
    myGLCD.print("    ", 210, 160);
    myGLCD.printNumI(g/10, 50, 160);
    myGLCD.printNumI(b, 210, 160);
  }
}[/mw_shl_code]


中转器部分
[mw_shl_code=c,true]#include <dht11.h>
#include <ZigduinoRadio.h>

dht11 DHT11;
#define DHT11PIN 7 //DHT11 PIN 3 连接UNO 3

void setup()
{
  Serial.begin(9600);
  Serial1.begin(9600);
  ZigduinoRadio.begin(11);
}

void loop()
{
  if (ZigduinoRadio.available())
  {
    while(ZigduinoRadio.available())
    Serial1.write((int)ZigduinoRadio.read());
    delay(1000);
   
    int i;
    DHT11.read(DHT11PIN);
    Serial1.print("12,");
    Serial1.print((float)DHT11.humidity, 0);
    Serial1.print(",");
    Serial1.print((float)DHT11.temperature-2, 0);
  
  }
  
  
  delay(100);

}
[/mw_shl_code]


节点部分
[mw_shl_code=c,true]#include <dht11.h>
#include <ZigduinoRadio.h>

dht11 DHT11;
#define DHT11PIN 7 //DHT11 PIN 3 连接UNO 3

void setup()
{
  Serial.begin(9600);
  ZigduinoRadio.begin(11);
}

char* itostr(char *str, int i)
{
    sprintf(str, "%d", i);
    return str;
}


void loop()
{
   ZigduinoRadio.beginTransmission();

    DHT11.read(DHT11PIN);
    ZigduinoRadio.write("13,");
    int a=(float)DHT11.humidity;
    int b=(float)DHT11.temperature-2;
   
    Serial.println(a);
    Serial.println(b);
   
    char c[10],d[10];
   
    itostr(c,a);
    itostr(d,b);
   
    ZigduinoRadio.write(c);
    ZigduinoRadio.write(",");
    ZigduinoRadio.write(d);
   
   ZigduinoRadio.endTransmission();
   
  delay(3000);
  }

[/mw_shl_code]


调试部分

[mw_shl_code=c,true]/*
翻译:swim
时间:2013年5月27日
发表地址:www.geek-workshop.com
程序说明:无线串口通信
*/
#include <ZigduinoRadio.h>

void setup()
{
//初始化Zigbee,定义通道
  ZigduinoRadio.begin(11);
  Serial.begin(9600);
  Serial1.begin(9600);
//这两个函数是检测数据是否成功发送
  ZigduinoRadio.attachError(errHandle);
  ZigduinoRadio.attachTxDone(onXmitDone);
}

void loop()
{
//串口接收到数据,通过Zigbee发送;Zigbee接收到数据,通过串口打出
  if (Serial1.available())
  {
    ZigduinoRadio.beginTransmission();
    while(Serial1.available())
    {
      char c = Serial1.read();
      ZigduinoRadio.write(c);
    }
    ZigduinoRadio.endTransmission();
  }

  if (ZigduinoRadio.available())
  {
    while(ZigduinoRadio.available())
      Serial1.write((int)ZigduinoRadio.read());
/*
    Serial.println();
    Serial.print("LQI: ");
    Serial.print(ZigduinoRadio.getLqi(), 10);
    Serial.print(", RSSI: ");
    Serial.print(ZigduinoRadio.getLastRssi(), 10);
    Serial.print(" dBm, ED: ");
    Serial.print(ZigduinoRadio.getLastEd(), 10);
    Serial.println("dBm");
    */
  }

  delay(100);
}

void errHandle(radio_error_t err)
{
  Serial.println();
  Serial.print("Error: ");
  Serial.print((uint8_t)err, 10);
  Serial.println();
}

void onXmitDone(radio_tx_done_t x)
{
  Serial.println();
  Serial.print("TxDone: ");
  Serial.print((uint8_t)x, 10);

  Serial.println();
}
[/mw_shl_code]


该用户从未签到

发表于 2014-8-9 11:09 | 显示全部楼层
深深被楼主的豪气震伤

评分

参与人数 1金币 +9 收起 理由
Zzz + 9 这样我都不加钱太不厚道~

查看全部评分

该用户从未签到

发表于 2014-8-9 11:13 | 显示全部楼层
楼主还有几条大腿?
我想抱一条

该用户从未签到

发表于 2014-8-9 11:13 | 显示全部楼层
深深被大神所折服啊~

点评

Zzz
奔跑大神别黑我........  发表于 2014-8-9 11:16

该用户从未签到

发表于 2014-8-9 18:22 | 显示全部楼层
{:soso_e179:}大腿求抱

该用户从未签到

发表于 2014-8-10 00:13 | 显示全部楼层
厉害啊z神~被深深地折服了~

该用户从未签到

发表于 2014-8-10 21:37 | 显示全部楼层
被z折服了~祝成功,z神

评分

参与人数 1贡献 +3 收起 理由
Zzz + 3

查看全部评分

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

本版积分规则

热门推荐

arduinoT12焊台 控制器 炫酷UI
arduinoT12焊台 控制器 炫
*声明:本项目源于https://github.com/wagiminator/ATmega-Soldering-Station 采用CC3
arduino uno 读取不了DHT11数据,求助大佬!!!
arduino uno 读取不了DHT1
整了两天了,还是没整出来,换了线,换了传感器都不行!就差换板子了。求助各位大佬。
Arduino引脚图
Arduino引脚图
Arduino UNO R3 (CH340G)引脚 持续更新中·····
ESP8266/RJ45网口CH9121/POE供电/USB转TTL口网络继电器开发板
ESP8266/RJ45网口CH9121/P
四路继电器控制板带RJ45网口CH9121,POE供电,USB转TTL口,Type-C接口,STC单片机冷启E
Arduino物联网开发实例教程
Arduino物联网开发实例教
[md] **blinker用户交流群 301438087 (仅限github已Star的用户加群)** ## bli
Copyright   ©2015-2016  Arduino中文社区  Powered by©Discuz!   
快速回复 返回顶部 返回列表