User Tools

Site Tools


workshop:i2c

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
workshop:i2c [2012/08/13 14:06] – created dongheeworkshop:i2c [2018/07/18 14:10] (current) – external edit 127.0.0.1
Line 1: Line 1:
  
 ====== I2C ====== ====== I2C ======
 +
 I2C 직렬 컴퓨터 버스 주변기기를 연결하기 위해 사용된다. I2C 직렬 컴퓨터 버스 주변기기를 연결하기 위해 사용된다.
  
Line 15: Line 16:
 {{http://i.imgur.com/dgtdQ.png?300}} {{http://i.imgur.com/dgtdQ.png?300}}
  
-실제 실험 해보기 +===== 실제 실험 해보기 ===== 
-24LC256+
  
 arduino i2c 관련 핀 arduino i2c 관련 핀
Line 25: Line 26:
  
 {{http://i.imgur.com/VQtTJ.png?300}} {{http://i.imgur.com/VQtTJ.png?300}}
 +
 +==== 24LC256, EEPROM ====
  
 {{{ {{{
Line 69: Line 72:
   Wire.begin(); //Start I2C connections   Wire.begin(); //Start I2C connections
   Serial.begin(9600);   Serial.begin(9600);
-  i2c_eeprom_write_page(0x50, 0, (byte *)data, sizeof(data)); // write to EEPROM+  //i2c_eeprom_write_page(0x50, 0, (byte *)data, sizeof(data)); // write to EEPROM
  
   delay(10); //add a small delay   delay(10); //add a small delay
Line 98: Line 101:
  
 {{http://i.imgur.com/NE9xJ.png?300}} {{http://i.imgur.com/NE9xJ.png?300}}
 +
 +==== Tmp102 ====
 +{{{
 +
 +#include <Wire.h>
 +int tmp102Address = 0x48;
 +
 +void setup(){
 +  Serial.begin(9600);
 +  Wire.begin();
 +}
 +
 +void loop(){
 +
 +  float celsius = getTemperature();
 +  Serial.print("Celsius: ");
 +  Serial.println(celsius);
 +
 +  float fahrenheit = (1.8 * celsius) + 32;
 +  Serial.print("Fahrenheit: ");
 +  Serial.println(fahrenheit);
 +
 +  delay(200); //just here to slow down the output. You can remove this
 +}
 +
 +float getTemperature(){
 +  Wire.requestFrom(tmp102Address,2); 
 +
 +  byte MSB = Wire.read();
 +  byte LSB = Wire.read();
 +
 +  //it's a 12bit int, using two's compliment for negative
 +  int TemperatureSum = ((MSB << 8) | LSB) >> 4; 
 +
 +  float celsius = TemperatureSum*0.0625;
 +  return celsius;
 +}
 +}}}
workshop/i2c.1344866770.txt.gz · Last modified: 2018/07/18 14:09 (external edit)