/* ATtiny85 as an I2C Master Ex1 BroHogan 1/21/11 * I2C master reading DS1621 temperature sensor. (display with leds) * SETUP: * ATtiny Pin 1 = (RESET) N/U ATtiny Pin 2 = (D3) LED3 * ATtiny Pin 3 = (D4) to LED1 ATtiny Pin 4 = GND * ATtiny Pin 5 = SDA on DS1621 ATtiny Pin 6 = (D1) to LED2 * ATtiny Pin 7 = SCK on DS1621 ATtiny Pin 8 = VCC (2.7-5.5V) * NOTE! - It's very important to use pullups on the SDA & SCL lines! * DS1621 wired per data sheet. This ex assumes A0-A2 are set LOW for an addeess of 0x48 * TinyWireM USAGE & CREDITS: - see TinyWireM.h * NOTES: * The ATtiny85 + DS1621 draws 1.7mA @5V when leds are not on and not reading temp. * Using sleep mode, they draw .2 @5V @ idle - see http://brownsofa.org/blog/archives/261 */ #include // I2C Master lib for ATTinys which use USI #define ADDR 0x26 #define LED1_PIN 7 // ATtiny Pin 3 #define LED2_PIN 8 // ATtiny Pin 6 int rec=0; void setup(){ pinMode(LED1_PIN,OUTPUT); pinMode(LED2_PIN,OUTPUT); Wire.begin(); // initialize I2C lib Blink(LED1_PIN,2); // show it's alive delay (1000); } void loop(){ Wire.beginTransmission(ADDR); Wire.write(B00000001); // Send 1 byte Wire.endTransmission(); Blink(LED1_PIN,2); // show it's alive and sending delay (1000); // wait a few sec before next reading } void Blink(byte led, byte times){ // poor man's GUI for (byte i=0; i< times; i++){ digitalWrite(led,HIGH); delay (400); digitalWrite(led,LOW); delay (175); } }