LusoRobótica - Robótica em Português
Electrónica => Listas de componentes => Tópico iniciado por: LuísR.A. em 10 de Setembro de 2012, 14:38
-
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/ (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) << 8) + 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?
-
Apaga esta linha:
PORTC = (1 << PORTC4) | (1 << PORTC5);//enable pullups
E certifica-te que tens pull-ups externos nas linhas SDA e SCL.
-
tenho sim. uma resistencia 4k7 no sda e outra no scl. ambos para os 3.3v
agora mesmo metendo assim a serial port nao da nada:
void loop (){
Serial.print("inicio");
termico();
Serial.print("fim ");
}
-
Para o Mega eu coloquei o MLX90614 a funcionar com este código base:
#include <i2cmaster.h>
void setup(){
Serial.begin(9600);
Serial.println("Setup...");
i2c_init(); //Initialise the i2c bus
PORTD = (1 << PORTD0) | (1 << PORTD1);//enable pullups
}
void loop(){
int dev = 0x5A<<1;
int data_low = 0;
int data_high = 0;
int pec = 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) << 8) + data_low);
tempData = (tempData * tempFactor)-0.01;
float celcius = tempData - 273.15;
//float fahrenheit = (celcius*1.8) + 32;
Serial.print("Celcius: ");
Serial.println(celcius);
//Serial.print("Fahrenheit: ");
//sSerial.println(fahrenheit);
delay(100); // wait a second before printing again
}
É só ver as Port do Leonardo na datasheet...
No uno com este código que coloquei julgo que também funcionava, mas já não me recordo ao certo.
-
Para o Mega eu coloquei o MLX90614 a funcionar com este código base:
#include <i2cmaster.h>
void setup(){
Serial.begin(9600);
Serial.println("Setup...");
i2c_init(); //Initialise the i2c bus
PORTD = (1 << PORTD0) | (1 << PORTD1);//enable pullups
}
void loop(){
int dev = 0x5A<<1;
int data_low = 0;
int data_high = 0;
int pec = 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) << 8) + data_low);
tempData = (tempData * tempFactor)-0.01;
float celcius = tempData - 273.15;
//float fahrenheit = (celcius*1.8) + 32;
Serial.print("Celcius: ");
Serial.println(celcius);
//Serial.print("Fahrenheit: ");
//sSerial.println(fahrenheit);
delay(100); // wait a second before printing again
}
É só ver as Port do Leonardo na datasheet...
No uno com este código que coloquei julgo que também funcionava, mas já não me recordo ao certo.
parece ser igual ao meu excepto numa coisa que eu tentei fazer mas mal que eu nunca trabalhei com o arduino nem com esse tipo de linguagem.
tentei meter nos pullup D3 e D4 (ou que era agora nao me lembro de cor os numeros) em vez de PORT.
muito obrigado vou ver se testo
-
Ligar os pull-ups internos ou não, não fazem diferença, porque são fracos(na casa dos 50Kohms) e precisas de pull-ups de 10K ou menos para o i2c funcionar de maneira fiavel, logo não é por isso que não funciona.
-
mas no exemplo que vi tinha as resistencias e os pullups.
eu nem sei se é do sensor. de alguma forma o arduino nao faz nenhum print.
outra coisa eu tenho um diodo sem serie no negativo do sensor para impedir polaridade inversa. poderá isto fazer com que o sensor dê 30º a uma chama?
-
Eu não fazia isso, estás a levantar a referência de massa do sensor, assim quando o arduino poe um pino a zero o sensor vai ver pelo -0.7v o que muito provavelmente o vai queimar ou já queimou, se queres meter um diodo, metias no pino do vcc, mas acho isso desnecessário.
-
o problema é que agora nem sei o que se passa com o sensor. o arduino nao me da qualquer dado no monitor
eu meto no negativo porque se me enganar meto o 3.3V no ground
-
Então, tens de montar isso com atenção, porque se tens o diodo e lhe dás sinais negativos matas o sensor..
-
mas o diodo nao ira impedir a corrente se estiver oposta?
a queda de tensão do diodo pode fazer com que o sensor tenha falta de corrente?
-
Eu na altura lidei com esses sensores e eles são muito precisos por acaso...
Em relação a diodo não usei diodo nenhum, montei o esquema desse blog que foi mencionado por si...
Tem que ter em atenção a pinagem, na altura o que fiz para nao me enganar foi com uma caneta de acetatos (cd's) marcar na parte de traz do sensor o + e -....