Cioa a tutti,
ho acquistato un sensore infrarosso che mi sembra ottimo … quando va
MI spiego : il sensore dovrebbe leggere la temperatura di una piastra senza appoggiarci le solite termocoppie e il suo lavoro lo fa egregiamente, ma mi sono accorto che non sempre legge.
Ho preso il programma di test e ho inserito un po di print ed ecco l’arcano: da spento spesso parte ma si blocca sul primo o secondo step, il collegamento è quanto di più semlice ci sia 5Vcc-GND (esterni GND collegate) SDA-A4, SCL-A5 resistenze di pull-up 4,7k
La risposta a volte è
Fine SETUP
dato : i2c_start_wait
a volte
Fine SETUP
dato : i2c_start_wait i2c_rep_start
e quando funziona
Fine SETUP
dato : i2c_start_wait i2c_rep_start i2c_readAck i2c_readNak i2c_stop sonda = 24
dato : i2c_start_wait i2c_rep_start i2c_readAck i2c_readNak i2c_stop sonda = 24
lo sketch:
//IR_termometro_MLX90614
#include <i2cmaster.h>
int t5;
int v = 0;
float Ctemp, Ftemp;
void setup() {
Serial.begin(9600);
while(!Serial);
i2c_init(); //Initialise the i2c bus
Serial.println("Fine SETUP");
}
void loop() {
{
int dev = 0x5A<<1;
int data_low = 0;
int data_high = 0;
int pec = 0;
Serial.print(" dato : ");
i2c_start_wait(dev+I2C_WRITE);
Serial.print(" i2c_start_wait ");
i2c_write(0x07);
// read
i2c_rep_start(dev+I2C_READ);
Serial.print(" i2c_rep_start ");
data_low = i2c_readAck(); //Read 1 byte and then send ack
data_high = i2c_readAck(); //Read 1 byte and then send ack
Serial.print(" i2c_readAck ");
pec = i2c_readNak();
Serial.print(" i2c_readNak ");
i2c_stop();
Serial.print(" 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 celsius = tempData - 273.15;
t5=celsius;
Serial.print("sonda = ");
Serial.println(t5);
delay(2000);
}
}
Devo dire che sono perplesso per il fatto che a volte va a volte no , senza toccare nulla.
Ringrazio anticipatamente quanti mi risponderanno