I have started using arduino recently. I was given a sketch to read the data from MLX90614 IR sensor. Until now everything work but something happen the serial data does not display anymore.
I have tried sample sketch from arduino forum and this display accordingly for example "hello world" etc.
The sketch below does not even display "Hello"
Any suggestion of how to rectify this?
Below is the sketch that has been working so far.
#include <i2cmaster.h>
void setup()
{
Serial.begin(9600);
Serial.println("Hello!");
i2c_init(); //Initialise the i2c bus
Serial.println("Return from i2c_init");
PORTC = (1 << PORTC4) | (1 << PORTC5);//enable pullups
}
void loop()
{
int dev1 = 0x50<<1; //Address must be bit shifted left, library does not automatically do it
int data_low1 = 0;
int data_high1 = 0;
int pec1 = 0;
int devres_low1 =0; // device response address
int devres_high1 =0; // device response address
int dev2 = 0x5A<<1; //Address must be bit shifted left, library does not automatically do it
int data_low2 = 0;
int data_high2 = 0;
int pec2 = 0;
int devres_low2 =0; // device response address
int devres_high2 =0; // device response address
i2c_start_wait(dev1+I2C_WRITE); //send start condition and write bit
//Function issues a start condition and sends address and transfer direction.
i2c_write(0x07); //send command for device to action
i2c_rep_start(dev1+I2C_READ); // Function issues a repeated start condition
//and sends address and transfer direction
//device will ack
data_low1 = i2c_readAck(); //Read 1 byte and then send ack
data_high1 = i2c_readAck(); //Read 1 byte and then send ack
pec1 = i2c_readNak(); //Read error check byte and send Nack to tell device to stop
i2c_stop(); //Release bus, end transaction
//Read address
i2c_start_wait(dev1+I2C_WRITE); //send start condition and write bit
//Function issues a start condition and sends address and transfer direction.
i2c_write(0x2D); //send command for device to return address
i2c_rep_start(dev1+I2C_READ); // Function issues a repeated start condition
//and sends address and transfer direction
//device will ack
devres_low1 = i2c_readAck()>>1; //Read 1 byte and then send ack
devres_high1 = i2c_readAck()>>1; //Read 1 byte and then send ack
pec1 = i2c_readNak(); //Read error check byte and send Nack to tell device to stop
i2c_stop(); //Release bus, end transaction
//second device
i2c_start_wait(dev2+I2C_WRITE); //send start condition and write bit
//Function issues a start condition and sends address and transfer direction.
i2c_write(0x07); //send command for device to action
i2c_rep_start(dev2+I2C_READ); // Function issues a repeated start condition
//and sends address and transfer direction
//device will ack
data_low2 = i2c_readAck(); //Read 1 byte and then send ack
data_high2 = i2c_readAck(); //Read 1 byte and then send ack
pec2 = i2c_readNak(); //Read error check byte and send Nack to tell device to stop
i2c_stop(); //Release bus, end transaction
//Read address
i2c_start_wait(dev2+I2C_WRITE); //send start condition and write bit
//Function issues a start condition and sends address and transfer direction.
i2c_write(0x2D); //send command for device to return address
i2c_rep_start(dev2+I2C_READ); // Function issues a repeated start condition
//and sends address and transfer direction
//device will ack
devres_low2 = i2c_readAck()>>1; //Read 1 byte and then send ack
devres_high2 = i2c_readAck()>>1; //Read 1 byte and then send ack
pec2 = i2c_readNak(); //Read error check byte and send Nack to tell device to stop
i2c_stop(); //Release bus, end transaction
//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
double tempData = 0x0000;
int frac;
// This masks off the error bit of the high byte, then moves it left 8 bits and adds the low byte.
tempData = (double)(((data_high1 & 0x007F) << 8) + data_low1);
tempData = (tempData * tempFactor)-0.01;
tempData = tempData - 273.15;
Serial.print("Temeperature from Sensor A");
Serial.print(devres_high1);
Serial.print(devres_low1);
Serial.print(" is = ");
Serial.print((int)tempData); //Print temp in degrees C to serial
Serial.print(".");
tempData=tempData-(int)tempData;
frac=tempData*100;
Serial.print(frac);
Serial.print(" and B");
tempData = (double)(((data_high2 & 0x007F) << 8) + data_low2);
tempData = (tempData * tempFactor)-0.01;
tempData = tempData - 273.15;
Serial.print(devres_high2);
Serial.print(devres_low2);
Serial.print(" is ");
Serial.print((int)tempData); //Print temp in degrees C to serial
Serial.print(".");
tempData=tempData-(int)tempData;
frac=tempData*100;
Serial.println(frac);
delay(1000);
}