아두이노 응용 15 : I2C 센서와 대화 방법
목적 :
아두이노가 여러개 I2C( TWI ) 센서 와 데이터를 주고 받는 방법
TC74XX 시리즈 온도센서
진행순서 :
1) I2C 센서 설명
2) 회로 연결
3) 스케치
4) 작동 확인

// TC74A0~A2 I2C communication #includeint address1 =72 ; int address2 =73 ; int address3 =74 ; void setup() { Serial.begin(9600) ; Wire.begin() ; // for I2C } void loop() { int T1 = read_temp(address1); int T2 = read_temp(address2); int T3 = read_temp(address3); Serial.print("TC74A0: "); Serial.print(T1); Serial.print("C | "); Serial.print("TC74A1: "); Serial.print(T2); Serial.print("C | "); Serial.print("TC74A2: "); Serial.print(T3); Serial.println("C"); delay(500); } int read_temp(int address) { Wire.beginTransmission(address); Wire.write(0); //ask for register zero Wire.endTransmission(); Wire.requestFrom(address, 1); //request 1 byte while(Wire.available() == 0); //wait for response int T = Wire.read(); //put temperature in T return T; }