Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //----------------------------------------------------------------------------------------
- //| AD7747 Capacitive Sensor |
- //| Based on code by MiG found at:http://forum.arduino.cc/index.php/topic,11882.0.html| |
- //| |
- //| Author: Aidan Williamson (although I didn't do much original work) |
- //| Written: 7/3/2014 |
- //| ad7747 datasheet:http://www.analog.com/static/imported-files/data_sheets/AD7747.pdf |
- //| |
- //| |
- //| |
- //| |
- //-----------------------------------------------------------------------------------------
- #include <Wire.h> //include the library for i2c communication
- int ready = 78; //ready pin will go low when conversion is complete
- void setup()
- {
- pinMode(ready, INPUT); //we will read the ready bit from pin 2
- Wire.begin(); //sets up i2c for operation
- Serial.begin(9600); // we will monitor this via serial cable
- Wire.beginTransmission(0x48); // begins write cycle
- Wire.write(0x07); //address pointer for cap setup register
- Wire.write(0xA0); //b'10100000' found from datasheet page 16
- Wire.endTransmission(); //ends write cycle
- delay(4);// Wait for data to clock out? I'm not 100% sure why this delay is here (or why it's 4ms)
- Wire.beginTransmission(0x48);//begins transmission again
- Wire.write(0x09); //address pointer for capacitive channel excitation register
- Wire.write(0x0F); //This will vary depending on your setup. See page 17 of datasheet
- Wire.endTransmission();
- delay(4);
- Wire.beginTransmission(0x48);
- Wire.write(0x0A); //address pointer for the configuration register
- Wire.write(0xA1); //b'00011001' for continuous conversion, arbitrary VTF setting, and mid-range capacitive conversion time
- Wire.endTransmission();
- }
- void loop() //set up for reading and transmitting data
- {
- int ready = digitalRead(ready); //sets up ready pin as digital input
- while (ready ==HIGH) //use digital pin 22 as interrupt pin
- {
- delay(1);//why not
- }; //do nothing at all!
- Wire.beginTransmission(0x48); //arduino asks for data from ad7747
- Wire.write(0x01); //set address point to capacitive DAC register 1
- Wire.endTransmission(); //pointer is set so now we can read the data
- Wire.requestFrom(0x48,3); //reads data from cap DAC registers 1-3
- while(Wire.available())
- {
- char capacitance = Wire.read();
- Serial.print(capacitance, DEC); //prints the capacitance data in decimal through serial port
- Serial.print(",");
- }
- Serial.println();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement