arranjei um sensor termico MLX90614 mas não estou a conseguir mete-lo a funcionar.
tentei com i2c como diz neste blog
http://bildr.org/2011/02/mlx90614-arduino/ mas o codigo tem um erro:
MLX90614.cpp: In function 'void setup()':
MLX90614:10: error: 'PORTC4' was not declared in this scope
MLX90614:10: error: 'PORTC5' was not declared in this scope
tentei substituir isso por "SCL" e "SDA" ou simplesmente tirar essa parte do codigo o que resultou mais ao menos mas ao aponta-lo para um isqueiro deu-me 30ºC.
e agora nem da nada a serial port por alguma razão
o codigo é este:
#include <i2cmaster.h>
unsigned int chama = 0;
unsigned int apagar = 0;
void setup(){
Serial.begin(9600);
Serial.println("Setup...");
i2c_init(); //Initialise the i2c bus
PORTC = (1 << PORTC4) | (1 << PORTC5);//enable pullups
}
void loop (){
termico();
}
void termico(){
int dev = 0x5A<<1;
int data_low = 0;
int data_high = 0;
int pec = 0;
chama=0;
apagar=0;
i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x07);
// read
i2c_rep_start(dev+I2C_READ);
data_low = i2c_readAck(); //Read 1 byte and then send ack
data_high = i2c_readAck(); //Read 1 byte and then send ack
pec = i2c_readNak();
i2c_stop();
//This converts high and low bytes together and processes temperature, MSB is a error bit and is ignored for temps
double tempFactor = 0.02; // 0.02 degrees per LSB (measurement resolution of the MLX90614)
double tempData = 0x0000; // zero out the data
int frac; // data past the decimal point
// This masks off the error bit of the high byte, then moves it left 8 bits and adds the low byte.
tempData = (double)(((data_high & 0x007F) <<
+ data_low);
tempData = (tempData * tempFactor)-0.01;
float celcius = tempData - 273.15;
Serial.print("Celcius: ");
Serial.println(celcius);
delay(1000); // wait a second before printing again
if (celcius > 50){
chama=1;
}
}
tambem ha um modo de PWM neste sensor mas não sei como usar.
alguem me pode ajudar?