Can anyone help me to create a program?

we're planning to display the output of MLX90614 IR sensor to TFT LCD Shield 2.4". I try to search for a code online but I can't find anything. hoping to get something here. anything will do. thanks in advance

Have you tested your sensor with an example sketch from the sensor library?

Have you tested your display with an example sketch for the display library?

If so, post both sketches here. Don't post code without code tags please!

/***************************************************
MLX90614 IR sensor
 ****************************************************/

#include <Adafruit_MLX90614.h>

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

void setup() {
  Serial.begin(9600);
  while (!Serial);

  Serial.println("Adafruit MLX90614 test");

  if (!mlx.begin()) {
    Serial.println("Error connecting to MLX sensor. Check wiring.");
    while (1);
  };

  Serial.print("Emissivity = "); Serial.println(mlx.readEmissivity());
  Serial.println("================================================");
}

void loop() {
  Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC());
  Serial.print("*C\tObject = "); Serial.print(mlx.readObjectTempC()); Serial.println("*C");
  Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempF());
  Serial.print("*F\tObject = "); Serial.print(mlx.readObjectTempF()); Serial.println("*F");

  Serial.println();
  delay(500);
}
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>

#define BLACK   0x0000
#define RED     0xF800
#define WHITE   0xFFFF

MCUFRIEND_kbv tft;

void setup() {
  // put your setup code here, to run once:
  uint16_t ID = tft.readID();
  tft.begin(ID);
  tft.fillScreen(BLACK);
  tft.setCursor(0,0);
  tft.setTextSize(3);
  tft.setTextColor(WHITE);
  tft.print("my first project with tft -");

}

void loop() {
  // put your main code here, to run repeatedly:
  tft.setCursor(0,70);
  tft.setTextSize(2);
  tft.setTextColor(RED);
  tft.print("welcome!");

}

You didn't say anything about the results of testing those.... two questions were asked, above.

Thanks for using code tags.

There is something missing from that display sketch. I don't see loop() defined?

I already edited the display sample sketch.

I tested those 2 and it works fine with the sensor and display shield

Okay, merge the two sketches. In setup(), the code from both. In loop(), change the print statements to go to the TFT instead of serial. Compile it, and post here.

#include <U8glib.h>
#include <Adafruit_MLX90614.h>
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>

#define BLACK   0x0000
#define RED     0xF800
#define WHITE   0xFFFF

MCUFRIEND_kbv tft;

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

void setup() {
  Serial.begin(9600);
  while (!Serial);

  Serial.println("Adafruit MLX90614 test");

  if (!mlx.begin()) {
    Serial.println("Error connecting to MLX sensor. Check wiring.");
    while (1);
  };

  Serial.print("Emissivity = "); Serial.println(mlx.readEmissivity());
  Serial.println("================================================");
}

 // put your setup code here, to run once:
  uint16_t ID = tft.readID();
  tft.begin(ID);
  tft.fillScreen(BLACK);
  tft.setCursor(0,0);
  tft.setTextSize(1);
  tft.setTextColor(WHITE);
  tft.print("my first project with tft -");

}

void loop() {
  tft.setCursor(0,70);
  tft.setTextSize(2);
  tft.setTextColor(WHITE);
  tft.print("*C\tObject = "); tft.print(mlx.readObjectTempC()); tft.println("*C");


  tft.println();
  delay(5000);
  
}

this is the error

*Arduino: 1.8.19 (Windows 10), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

*The sketch name had to be modified.
*Sketch names must start with a letter or number, followed by letters,
*numbers, dashes, dots and underscores. Maximum length is 63 characters.

*wala_lang:31:3: error: 'tft' does not name a type

  • tft.begin(ID);
  • ^~~

*wala_lang:32:3: error: 'tft' does not name a type

  • tft.fillScreen(BLACK);
  • ^~~

*wala_lang:33:3: error: 'tft' does not name a type

  • tft.setCursor(0,0);
  • ^~~

*wala_lang:34:3: error: 'tft' does not name a type

  • tft.setTextSize(1);
  • ^~~

*wala_lang:35:3: error: 'tft' does not name a type

  • tft.setTextColor(WHITE);
  • ^~~

*wala_lang:36:3: error: 'tft' does not name a type

  • tft.print("my first project with tft -");
  • ^~~

*wala_lang:38:1: error: expected declaration before '}' token

  • }
  • ^

*exit status 1

*'tft' does not name a type

*This report would have more information with
*"Show verbose output during compilation"
*option enabled in File -> Preferences.

When you auto format the code, you can see the misplaced {} brace:

#include <U8glib.h>
#include <Adafruit_MLX90614.h>
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>

#define BLACK   0x0000
#define RED     0xF800
#define WHITE   0xFFFF

MCUFRIEND_kbv tft;

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

void setup() {
  Serial.begin(9600);
  while (!Serial);

  Serial.println("Adafruit MLX90614 test");

  if (!mlx.begin()) {
    Serial.println("Error connecting to MLX sensor. Check wiring.");
    while (1);
  };

  Serial.print("Emissivity = "); Serial.println(mlx.readEmissivity());
  Serial.println("================================================");
}

// put your setup code here, to run once:
uint16_t ID = tft.readID();
tft.begin(ID);
tft.fillScreen(BLACK);
tft.setCursor(0, 0);
tft.setTextSize(1);
tft.setTextColor(WHITE);
tft.print("my first project with tft -");

}

void loop() {
  tft.setCursor(0, 70);
  tft.setTextSize(2);
  tft.setTextColor(WHITE);
  tft.print("*C\tObject = "); tft.print(mlx.readObjectTempC()); tft.println("*C");


  tft.println();
  delay(5000);

}

That places code outside of any code block, producing those errors.

1 Like

thanks for the help, sir!!! :innocent:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.