Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By szpapas
#16413 Here is the Sketch file, it works, Using ESP12 to read the infra sensor.

SDA --- GPIO4
SCL --- GPIO5

#include <Wire.h>

#define MLX90614_TA 0x06
#define MLX90614_TOBJ1 0x07

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Wire.pins(4,5);
Wire.setClock(100000);
}


uint16_t read16(uint8_t addr, uint8_t i2c_addr){
uint16_t ret;

Wire.beginTransmission(i2c_addr); // start transmission to device
Wire.write(addr); // sends register address to read from
Wire.endTransmission(false); // end transmission

Wire.requestFrom(i2c_addr, (uint8_t)3);// send data n-bytes read
ret = Wire.read(); // receive DATA
ret |= Wire.read() << 8; // receive DATA

uint8_t pec = Wire.read();

return ret;
}


float readTemp(uint8_t reg, uint8_t i2c_addr) {
float temp;

temp = read16(reg, i2c_addr);
temp *= .02;
temp -= 273.15;
return temp;

}

double readObjectTempC(uint8_t i2c_addr) {
return readTemp(MLX90614_TOBJ1, i2c_addr);
}


double readAmbientTempC(uint8_t i2c_addr) {
return readTemp(MLX90614_TA, i2c_addr);
}

void loop() {
// put your main code here, to run repeatedly:
Serial.print("Ambient = "); Serial.print(readAmbientTempC(0x5A));
Serial.print("*C\tObject = "); Serial.print(readObjectTempC(0x5A)); Serial.println("*C");

Serial.println();
delay(1000);
}

屏幕快照 2015-05-04 上午9.23.45.png


Snip20150504_2.png
You do not have the required permissions to view the files attached to this post.
User avatar
By martinayotte
#29273
fish wrote:wire.begin(4,5) instead of wire.pins.


That's because the library has changed a lot since these days...
In the past, it was really wire.pins() , although it should still compile, but will display a "deprecated" warning message during compile.