最近Ti 出了一堆種類的ADC,從Capacitor 到 Inductor 到 Humidity sensor
上圖就是Humidity + Temperature Sensor HDC1000
原本是想要搞個pcb在用個熱風槍或啥的焊接,不過有點懶得在eagle做library所以就變成上圖那樣了....
還滿難搞的,尤其是第一隻腳,因為IC很難固定的住,黏上高溫膠帶之類的也只有一點幫助
線是從多心線拆下來的,手邊那麼細的線大概就只有這個了
總之接上Arduino 後(注意3.3V)
以下code
#include <Wire.h>
#define addr 0x41
uint16_t readingT,readingH;
void setup()
{
Wire.begin();
Serial.begin(9600);
Serial.println("HDC1000 Test");
sethdc();
}
void loop()
{
readhdc();
delay(1000);
}
void sethdc(){
Wire.beginTransmission(addr);
Wire.write(0x02);
Wire.write(0x10); //14 bit 14bit config MSB
Wire.write(0x00); //14 bit 14bit config LSB
Wire.endTransmission();
Wire.beginTransmission(addr) ; //check write success or not
Wire.write(0x02);
Wire.endTransmission();
Wire.requestFrom(addr, 2);
if(2 <= Wire.available())
{
readingT=0;
readingT = Wire.read();
readingT = readingT << 8;
Serial.print(" Config:");
Serial.println(readingT,BIN);
}
Wire.beginTransmission(addr); //read ID
Wire.write(0xFB);
Wire.endTransmission();
Wire.requestFrom(addr, 3);
if(3 <= Wire.available())
{
readingT=0;
readingT = Wire.read();
readingT = readingT << 8;
Serial.print(" ID:");
Serial.print(readingT,BIN);
Serial.println( Wire.read(),BIN);
}
}
void readhdc(){
Wire.beginTransmission(addr);
Wire.write(0x00);
Wire.write(0x00);
Wire.endTransmission();
delay(20);
Wire.requestFrom(addr, 4);
if(4 <= Wire.available())
{ readingT=0;
readingH = 0;
readingT = (Wire.read()<<8);
readingT+=Wire.read();
readingH = (Wire.read()<<8);
readingH+=Wire.read();
Serial.print(" Temp:");
Serial.print(readingT);
Serial.print(" =>");
Serial.print(readingT/65536.0*165.0-40.0);
Serial.print(" RH:");
Serial.print(readingH);
Serial.print(" =>");
Serial.println(readingH/65536.0*100.0);
}
}
不好意思!我有兩個問題想請教:
回覆刪除1.請問
Wire.beginTransmission(addr);
Wire.write(0x02);
Wire.endTransmission();
Wire.requestFrom(addr, 2);
if(2 <= Wire.available())
{ readingT=0;
readingT = Wire.read();
readingT = readingT << 8;
Serial.print(" Config:");
Serial.println(readingT,BIN);
}
Wire.beginTransmission(addr);
Wire.write(0xFB);
Wire.endTransmission();
Wire.requestFrom(addr, 3);
if(3 <= Wire.available())
{ readingT=0;
readingT = Wire.read();
readingT = readingT << 8;
Serial.print(" ID:");
Serial.print(readingT,BIN);
Serial.println( Wire.read(),BIN);
}
這段程式的功用是單純只看HDC的config數跟它的ID號碼嗎?
還是會對之後的readhdc()造成影響?
2.請問在readhdc()裡面,要加兩個 " Wire.write(0x00); "指令?
謝謝分享!
1.這段程式碼之前的是設定Config,像是解析度等等的,為了確定我有寫進去,所以把他讀出來確認用而已,ID也只是讀出來看看長啥樣子XD
刪除2.詳見Trigger Humidity/Temperature Measurement
感謝will先生回答!
刪除我很像把步驟2搞錯了!XDD
感謝指點迷津!