Hi all
Im trying to get the hang of the I2C port on the arduino UNO
i followed this tutorial:
however when i try to implement the code my serial monitor remains blank.
Oddly enough though if i change this line
to while(Wire.available() == 1){};
i get readings to my serial monitor however it is only ever -1C and never changes
the full code is shown below.
any help would be much appreciated
}
Im trying to get the hang of the I2C port on the arduino UNO
i followed this tutorial:
however when i try to implement the code my serial monitor remains blank.
Oddly enough though if i change this line
Code:
while(Wire.available() == 0){};
//get the temp
int c = Wire.read();
to while(Wire.available() == 1){};
i get readings to my serial monitor however it is only ever -1C and never changes
the full code is shown below.
any help would be much appreciated
Code:
//include i2c library
#include <Wire.h>
int temp_address = 72;
void setup()
{
Serial.begin(9600);
Wire.begin(); // initialize listening on I2C bus
}
void loop()
{
//send a request
//start talking
Wire.beginTransmission(temp_address);
// ask for register zero
Wire.write(0);
// complete transmission
Wire.endTransmission();
// request 1 byte
Wire.requestFrom(temp_address,1);
// wait for response
while(Wire.available() == 0){};
//get the temp
int c = Wire.read();
//convert celcius to farenheit
int f = round(c*9.0/5.0+32.0);
//print the results
Serial.print(c);
Serial.print("C,");
Serial.print(f);
Serial.println("F");
// delay, then repeat
delay(500);
}