I'm working programming a Leonardo board and I have a MCP9801 attached to a shield I have been given for this project.
int I2C_address = 0b1001000 // define address of bus
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
Wire.beginTransmission(I2C_address); // transmit to I2C
Wire.write(0b00000000); // sends one byte
Wire.endTransmission(); // stop transmitting
Wire.requestFrom(I2C_address, 2); // request 2 bytes from address.
while(Wire.available()) // slave may send less than requested
int temp1 = Wire.read(); // receive a byte as character
int temp2 = Wire.read(); // receive a byte as character
Serial.println(temp); // print the character
1) I know what register the ambient temperature is on on the sensor but where in this code do I need to use this information
2) My lecturer talked about taking two bytes from the sensor and bit shifting to get 9 bit from the sensor, Why would I do that? and indeed what's the best way?
3) Finally there's some simple maths to perform on the output to convert it from Raw data to a temperature as defined in the data sheet for the temp sensor, What would be the best way to do this?
Thank you for your help, I hope this is clear