workshop:i2c
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| workshop:i2c [2012/08/13 14:06] – created donghee | workshop: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:// | {{http:// | ||
| - | 실제 실험 해보기 | + | ===== 실제 실험 해보기 |
| - | 24LC256 | + | |
| arduino i2c 관련 핀 | arduino i2c 관련 핀 | ||
| Line 25: | Line 26: | ||
| {{http:// | {{http:// | ||
| + | |||
| + | ==== 24LC256, EEPROM ==== | ||
| {{{ | {{{ | ||
| Line 69: | Line 72: | ||
| Wire.begin(); | Wire.begin(); | ||
| Serial.begin(9600); | Serial.begin(9600); | ||
| - | i2c_eeprom_write_page(0x50, | + | |
| delay(10); //add a small delay | delay(10); //add a small delay | ||
| Line 98: | Line 101: | ||
| {{http:// | {{http:// | ||
| + | |||
| + | ==== Tmp102 ==== | ||
| + | {{{ | ||
| + | |||
| + | #include < | ||
| + | int tmp102Address = 0x48; | ||
| + | |||
| + | void setup(){ | ||
| + | Serial.begin(9600); | ||
| + | Wire.begin(); | ||
| + | } | ||
| + | |||
| + | void loop(){ | ||
| + | |||
| + | float celsius = getTemperature(); | ||
| + | Serial.print(" | ||
| + | Serial.println(celsius); | ||
| + | |||
| + | float fahrenheit = (1.8 * celsius) + 32; | ||
| + | Serial.print(" | ||
| + | Serial.println(fahrenheit); | ||
| + | |||
| + | delay(200); //just here to slow down the output. You can remove this | ||
| + | } | ||
| + | |||
| + | float getTemperature(){ | ||
| + | Wire.requestFrom(tmp102Address, | ||
| + | |||
| + | 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)