FDC1004是Ti出的 I2C 電容測量ADC,使用起來滿方便的,體積也很小
之後應該會拿來做一些Project
電路方面很簡單,I2C和電源(3.3V)接起來就好
我現在的設定是200 sample/s , 4ch , continuous sampling , no offset/gain
Code 如下:
#include <Wire.h>
int FDAddress = B1010000;
void setup()
{
Serial.begin(115200);
Wire.begin();
initFD();
Serial.println("Setup");
}
void loop()
{
Serial.println(" ===========================================");
for(int i=0; i<4; i++){
uint32_t cap = ((read2byte(0x00+i*2)<<16)+read2byte(0x01+i*2))>>8;
Serial.print("Input ");
Serial.print(i);
Serial.print(" ==> ");
Serial.print(cap,HEX);
Serial.print(" ==> ");
Serial.print(cap/65536.0,5);
Serial.println(" pf");
}
Serial.println(" ===========================================");
delay(1000);
}
void initFD(){
for(int i=0; i<4; i++){
write2byte(0x08+i,0x1C00+0x2000*i);
}
write2byte(0x0c,0x5F0); //All enable rate = 100
}
uint16_t read2byte(uint8_t address) {
Wire.beginTransmission(FDAddress);
Wire.write(address);
Wire.endTransmission();
Wire.requestFrom(FDAddress, 2);
uint16_t data = Wire.read();
data = (data<<8)+Wire.read();
return data;
}
void write2byte(uint8_t address,uint16_t data) {
Wire.beginTransmission(FDAddress);
Wire.write(address);
Wire.write(data>>8);
Wire.write(data);
Wire.endTransmission();
}