[SOLVED] Help with Parallax MLX90614

Hi, I'm using the Parallax MLX90614 temperature sensor for a project with an Arduino Uno, with connections as follows:
Uno - MLX90614
5V - 5V
GND - GND
2 & 3 - SIG
12 - RST
Here is the code I'm using, adapted from TC_Chu's Point: Arduino to MLX90614 Infrared Thermometer Modules

#include <SoftwareSerial.h>

SoftwareSerial Temp90(2, 3);

int LED = 13;
int RESET = 12;

void setup() 
{ 
  pinMode(LED,OUTPUT);
  pinMode(RESET,OUTPUT);
  
  digitalWrite(LED,HIGH);
  digitalWrite(RESET,LOW);
  delay(10);
  pinMode(RESET,INPUT);
  
  Temp90.begin(4800);
  Serial.begin(115200);
  delay(100); 
  
  Temp90.print((byte)0);
  Temp90.print("!TEMc");
  Temp90.print((byte)0x5A);
  Temp90.print((byte)7);
  delay(1000);
  digitalWrite(LED,LOW);
  pinMode(3,INPUT);
} 
 
void loop() 
{ 
  checkTemp();
} 

int checkTemp()
{
  static char rByte[10] ;
  char rChar;
  static int Read = 0;
  static int rcount=0;
  int Temp1;
  int Temp2;
  int Temp3;
  while (Temp90.available() > 0) {
    rChar = Temp90.read();
    if (rChar == 'T') {
      Read = 1;
      rcount = 0;
    }
    if (Read == 1) {
      rByte[rcount] = rChar;
      rcount++;
    }
  }
  
  if (rcount >= 6) {
    if ((rByte[0] == 'T') && (rByte[1] == 'E') && (rByte[2] == 'M')) {
      Temp1 = rByte[4] + rByte[5]*256;
      Temp2 = (Temp1/100);
      if (Temp1*2 < 27315) {
        Temp3 = ((27315-(Temp1*2))/100);
      }
      else
      {
        Temp3 = (Temp1/100*2)-273;
      }
      Serial.print(rcount);   Serial.print("/");
      Serial.print(Temp1,DEC);Serial.print(" ");
      Serial.print(Temp2,DEC);Serial.print(" ");
      Serial.println(Temp3,DEC);
      
      rcount = 0;
      Read = 0;
      digitalWrite(LED,HIGH);
      delay(500);
      digitalWrite(LED,LOW);
      delay(500);
    }
  }
}

(I have tested the code with the addresses 0x35 and 0x5A)
However, there is no output at all. Could someone with experience using this sensor help me find where I went wrong? Thank you very much.

Hi bfoong

Temp90.print((byte)0);

What happens if you change the print statements where you are sending binary values to write statements?

Temp90.write((byte)0);

Also, why are you setting the mode of one of the SoftwareSerial pins in loop()?

pinMode(3,INPUT);

Regards

Ray

Hackscribble:
What happens if you change the print statements where you are sending binary values to write statements?

Temp90.write((byte)0);

Thanks, that solved the problem. Would you mind explaining what this change does?

Sure.

The print method takes (in your example) a numeric value and prints it as a string of text characters.

For example:

Serial.print(123);

would print the three characters "123". In other words, it transmits three bytes, being the ASCII codes for "1", "2" and "3" respectively.

The write method takes the numeric value and transmits it as one byte.

For example:

Serial.write(123);

would transmit one byte with the decimal value 123, which is the same as hexadecimal 0x7B or binary 0b01111011.

Hope that helps

Ray