Hi,
I'm working on a project involve controlling multiple MLX90614 from parallax. I've got one sensor worked thanks to TC_Chu's Point website
However, when i try to put on another one (pretty much copy and paste to new function). Sensors doesn't seem to read at all (nothing print out on command window). Could anyone give me some hint on where i could do things wrong?
Thank you so much
#include <NewSoftSerial.h>
NewSoftSerial Temp10(2, 3);
NewSoftSerial sensor2(4, 5);
int prevTemp1 = 0;
int prevTemp2 = 0;
void setup()
{
pinMode(13,OUTPUT);
Temp10.begin(4800);
sensor2.begin(4800);
Serial.begin(115200);
delay(100);
Temp10.print(0,BYTE);
Temp10.print("!TEMc");
Temp10.print(0x5A,BYTE);
Temp10.print(7,BYTE);
sensor2.print(0,BYTE);
sensor2.print("!TEMc");
sensor2.print(0x5A,BYTE);
sensor2.print(7,BYTE);
delay(1000);
pinMode(3,INPUT);
pinMode(5,INPUT);
}
void loop()
{
prevTemp1 = checkTemp();
// prevTemp2 = checkTemp2();
delay(500);
}
int checkTemp()
{
static char rByte[10] ;
char rChar;
static int Read = 0;
static int rcount=0;
int Temp1;
int Temp2;
int Temp3;
while (Temp10.available() > 0) {
rChar = Temp10.read();
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("Temperature1= ");
Serial.print(Temp3,DEC);
Serial.println(" Degrees Celsius");
rcount = 0;
Read = 0;
}
}
return Temp3;
}
int checkTemp2()
{
static char rByte2[10] ;
char rChar2;
static int Read2 = 0;
static int rcount2=0;
int Temp12;
int Temp22;
int Temp32;
while (sensor2.available() > 0) {
rChar2 = sensor2.read();
if (rChar2 == 'T') {
Read2 = 1;
rcount2 = 0;
}
if (Read2 == 1) {
rByte2[rcount2] = rChar2;
rcount2++;
}
}
if (rcount2 >= 6) {
if ((rByte2[0] == 'T') && (rByte2[1] == 'E') && (rByte2[2] == 'M')) {
Temp12 = rByte2[4] + rByte2[5]*256;
Temp22 = (Temp12/100);
if (Temp12*2 < 27315) {
Temp32 = ((27315-(Temp12*2))/100);
}
else
{
Temp32 = (Temp12/100*2)-273;
}
Serial.print("Temperature2= ");
Serial.print(Temp32,DEC);
Serial.println(" Degrees Celsius");
rcount2 = 0;
Read2 = 0;
}
}
return Temp32;
}
Luke