Created
February 9, 2015 20:01
-
-
Save Miceuz/8ace1cde27671e8e161d to your computer and use it in GitHub Desktop.
Chirp Arduino example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Chirp - arduino example | |
Connection | |
Chirp pin 1 - no connection | |
Chirp pin 2 - Arduino VCC | |
Chirp pin 3 - Arduino A5 | |
Chirp pin 4 - Arduino A4 | |
Chirp pin 5 - Arduino pin 2 | |
Chirp pin 6 - Arduino GND | |
*/ | |
#include <Wire.h> | |
void writeI2CRegister8bit(int addr, int value) { | |
Wire.beginTransmission(addr); | |
Wire.write(value); | |
Wire.endTransmission(); | |
} | |
unsigned int readI2CRegister16bit(int addr, int reg) { | |
Wire.beginTransmission(addr); | |
Wire.write(reg); | |
Wire.endTransmission(); | |
delay(1100); | |
Wire.requestFrom(addr, 2); | |
unsigned int t = Wire.read() << 8; | |
t = t | Wire.read(); | |
return t; | |
} | |
void setup() { | |
Wire.begin(); | |
Serial.begin(9600); | |
pinMode(2, OUTPUT); | |
digitalWrite(2, LOW); //Reset the Chirp | |
//delay(1); maybe allow some time for chirp to reset | |
digitalWrite(2, HIGH); //Go out from reset | |
writeI2CRegister8bit(0x20, 3); //send something on the I2C bus | |
delay(1000); //allow chirp to boot | |
} | |
void loop() { | |
Serial.println(readI2CRegister16bit(0x20, 0)); //read capacitance register | |
//writeI2CRegister8bit(0x20, 3); //request light measurement | |
//delay(9000); //this can take a while | |
//Serial.print(", "); | |
//Serial.println(readI2CRegister16bit(0x20, 4)); //read light register | |
delay(500); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment