User Tools

Site Tools


workshop:i2c

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
workshop:i2c [2012/08/14 08:47] dongheeworkshop: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://i.imgur.com/VQtTJ.png?300}} {{http://i.imgur.com/VQtTJ.png?300}}
 +
 +==== 24LC256, EEPROM ====
  
 {{{ {{{
Line 100: 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.1344934048.txt.gz · Last modified: 2018/07/18 14:09 (external edit)