isConnected was not declared in this scope error

I am using SparkFun device and the Actuator/Sensor would be MLX90640. I have installed the MLX90640 GitHub repos and trying to implement one of the given code sample and I have edited my c_cpp_properties.json file to add the files but I am unable to resolve the issue for isConnected().
#include “MLX90640_API.h”
#include “MLX90640_I2C_Driver.h”

So where is `isConnected()? implemented?

I am newbie programming the devices and not sure what exactly are you referring to . This is the example code for MLX90640 (SparkFun_MLX90640_Arduino_Example/Firmware/Example1_BasicReadings at master · sparkfun/SparkFun_MLX90640_Arduino_Example · GitHub)

It’s declared at the bottom of the .ino file. You’re attempting to compile a .ino file as a cpp file, but you have to do some conversion first. In C++, the prototypes of all functions must be known at the time they’re called, and the call to isConencted violates that. (Arduino auto-generates these protyptes for you). See the FAQ.

The corrected code is:

  Read the temperature pixels from the MLX90640 IR array
  By: Nathan Seidle
  SparkFun Electronics
  Date: May 22nd, 2018
  License: MIT. See license file for more information but you can
  basically do whatever you want with this code.

  Feel like supporting open source hardware?
  Buy a board from SparkFun!

  This example initializes the MLX90640 and outputs the 768 temperature values
  from the 768 pixels.

  This example will work with a Teensy 3.1 and above. The MLX90640 requires some
  hefty calculations and larger arrays. You will need a microcontroller with 20,000
  bytes or more of RAM.

  This relies on the driver written by Melexis and can be found at:

  Hardware Connections:
  Connect the SparkFun Qwiic Breadboard Jumper (
  to the Qwiic board
  Connect the male pins to the Teensy. The pinouts can be found here:
  Open the serial monitor at 9600 baud to see the output

#include <Wire.h>

#include "MLX90640_API.h"
#include "MLX90640_I2C_Driver.h"

const byte MLX90640_address = 0x33; //Default 7-bit unshifted address of the MLX90640

#define TA_SHIFT 8 //Default shift for MLX90640 in open air

static float mlx90640To[768];
paramsMLX90640 mlx90640;

//function prototypes
boolean isConnected();

void setup()
  Wire.setClock(400000); //Increase I2C clock speed to 400kHz

  while (!Serial); //Wait for user to open terminal
  Serial.println("MLX90640 IR Array Example");

  if (isConnected() == false)
    Serial.println("MLX90640 not detected at default I2C address. Please check wiring. Freezing.");
    while (1);
  Serial.println("MLX90640 online!");

  //Get device parameters - We only have to do this once
  int status;
  uint16_t eeMLX90640[832];
  status = MLX90640_DumpEE(MLX90640_address, eeMLX90640);
  if (status != 0)
    Serial.println("Failed to load system parameters");

  status = MLX90640_ExtractParameters(eeMLX90640, &mlx90640);
  if (status != 0)
    Serial.println("Parameter extraction failed");

  //Once params are extracted, we can release eeMLX90640 array

void loop()
  for (byte x = 0 ; x < 2 ; x++) //Read both subpages
    uint16_t mlx90640Frame[834];
    int status = MLX90640_GetFrameData(MLX90640_address, mlx90640Frame);
    if (status < 0)
      Serial.print("GetFrame Error: ");

    float vdd = MLX90640_GetVdd(mlx90640Frame, &mlx90640);
    float Ta = MLX90640_GetTa(mlx90640Frame, &mlx90640);

    float tr = Ta - TA_SHIFT; //Reflected temperature based on the sensor ambient temperature
    float emissivity = 0.95;

    MLX90640_CalculateTo(mlx90640Frame, &mlx90640, emissivity, tr, mlx90640To);

  for (int x = 0 ; x < 10 ; x++)
    Serial.print("Pixel ");
    Serial.print(": ");
    Serial.print(mlx90640To[x], 2);


//Returns true if the MLX90640 is detected on the I2C bus
boolean isConnected()
  if (Wire.endTransmission() != 0)
    return (false); //Sensor did not ACK
  return (true);

Btw you can also add it as a main.ino file and not as a main.cpp if you wish to keep using the Arduino-C++ style (but I would heavily recommend using the real C++).

Thank you so much. According to your suggestion I am running main.cpp with #include<Arduino.h> and not getting the error anymore but there is this other error Linking .pioenvs/esp32thing/firmware.elf

It’s implemented in MLX90640_API.cpp. You have the wrong firmware structure (but the library is pretty weirdly structured, too…). Basically PIO is not compiling in MLX90640_API.cpp and MLX90640_I2C.cpp etc because it’s in a folder named “Example…”. Usually these sources would be have to be under src/ with the examples being in folders under example/.

Can you try and copy the all the four MLX... files from the Example1 folder to your src/ where main.cpp is? Nothing else.

1 Like

Thank you. You just saved my couple of hours.:grinning::grin: