Skip to content

Instantly share code, notes, and snippets.

@weldtype
Last active January 14, 2017 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weldtype/8414479840f4a79aa3d7bbce1950a4ad to your computer and use it in GitHub Desktop.
Save weldtype/8414479840f4a79aa3d7bbce1950a4ad to your computer and use it in GitHub Desktop.
// ControlEverything.comのスケッチを改造。
// 2017/01/11 edy
//
// Distributed with a free-will license.
// Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
// TMP007
// This code is designed to work with the TMP007_I2CS I2C Mini Module available from ControlEverything.com.
// https://www.controleverything.com/content/Temperature?sku=TMP007_I2CS#tabs-0-product_tabset-2
#include<Wire.h>
// TMP007 I2C address is 0x40(64)
#define I2CAddr 0x40
int delayMs=1000;
// read temp
float readTemp(int regAddr)
{
unsigned data[2];
Wire.beginTransmission(I2CAddr);// Start I2C Transmission
Wire.write(regAddr);// Select register
Wire.endTransmission();// Stop I2C Transmission
// delay(300);
Wire.requestFrom(I2CAddr, 2);// Request 2 bytes of data
//if (Wire.available() == 2)// Read 2 bytes of data
{
data[0] = Wire.read();
data[1] = Wire.read();
}
// Convert the data to 14-bits
int temp = (((data[0] * 256) + (data[1] & 0xFC)) / 4);
if (temp > 8191) {
temp -= 16384;
}
return temp * 0.03125;
}
void setup()
{
byte CR = 4; //Conversion Rate 1, 2, 4, 8, 16
Wire.begin();
Serial.begin(9600);
Wire.beginTransmission(I2CAddr);
Wire.write(0x02);// Select configuration register
// Send config command
switch (CR) {
case 1: Wire.write(0x11); delayMs = 300; break;
case 2: Wire.write(0x13); delayMs = 500; break;
case 4: Wire.write(0x15); delayMs = 1000; break;
case 8: Wire.write(0x17); delayMs = 2000; break;
case 16: Wire.write(0x19); delayMs = 4000; break;
default: Wire.write(0x15); delayMs = 1000; break;
}
Wire.write(0x40);//ALRTF=0,TC=1,INT/Comp=0
//Wire.write(0x00);//ALRTF=0,TC=0,INT/Comp=0
Wire.endTransmission();
//delay(100);
}
void loop()
{
float objTemp = readTemp(0x03);
float dieTemp = readTemp(0x01);
Serial.print(objTemp);
Serial.print(",");
Serial.println(dieTemp);
delay(delayMs);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment