通过地址接口DS18B20

时间:2018-11-29 10:47:59

标签: c arduino hex

我有一个有线设备DS18b20的地址,我想通过在数组中声明其地址来接口它,并且我想调用地址数组的初始化程序是onewire.select(array-Initializer),然后我要计算温度,但我正在获取数据= 0 0 0 0

#include <OneWire.h>
OneWire ds(10);
//byte address[8];
byte data[12];
//int a;
byte i;
byte address[]={0x28,0xFF,0x6C,0xEA,0x62,0x16,0x4,0xE7};  

void setup() {
    // put your setup code here, to run once:
    Serial.begin(9600);
}

void loop() {
    // put your main code here, to run repeatedly:
    ds.reset();
    ds.select(&address);
    ds.write(0x44);

    ds.reset();
    ds.select(address);
    ds.write(0xBE);

    Serial.print("DATA=");
    for (i=0;i<9;i++){
        Serial.print(" ");
        data[i]= ds.read();
        Serial.print(data[i],DEC);
        Serial.print(" ");
    }
    Serial.println();
    delay(1000);
} 

我也收到此错误:

no matching function for call to 'OneWire::select(byte (*)[8])

1 个答案:

答案 0 :(得分:0)

来自sources

void OneWire::select( uint8_t rom[8])

尝试:

uint8_t address[]={0x28,0xFF,0x6C,0xEA,0x62,0x16,0x4,0xE7};  
ds.select(address);

C ++知道变量类型。