workshop:i2c
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| workshop:i2c [2012/08/14 08:47] – donghee | workshop:i2c [2018/07/18 14:10] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 18: | Line 18: | ||
| ===== 실제 실험 해보기 ===== | ===== 실제 실험 해보기 ===== | ||
| - | 24LC256, EEPROM | ||
| arduino i2c 관련 핀 | arduino i2c 관련 핀 | ||
| Line 27: | Line 26: | ||
| {{http:// | {{http:// | ||
| + | |||
| + | ==== 24LC256, EEPROM ==== | ||
| {{{ | {{{ | ||
| Line 100: | 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.1344934048.txt.gz · Last modified: 2018/07/18 14:09 (external edit)