#define DEBUG_PRINT(...)

I am currently doing a Gas detector system using MQ2 sensor and humidity sensor, when i verify the code, it shows the error as shown below:

In file included from C:\Desktop\Smart_Gas_Detector\Smart_Gas_Detector.ino:19:
C:\Arduino library\libraries\DHT_sensor_library/DHT.h:37: warning: "DEBUG_PRINT" redefined
   37 | #define DEBUG_PRINT(...)                                                       \
      | 
In file included from C:\Desktop\Smart_Gas_Detector\BlynkEdgent.h:9,
                 from C:\Desktop\Smart_Gas_Detector\Smart_Gas_Detector.ino:18:
C:\Desktop\Smart_Gas_Detector\Settings.h:95: note: this is the location of the previous definition
   95 |   #define DEBUG_PRINT(...)  BLYNK_LOG1(__VA_ARGS__)

what should I do to solve it? Thanks

You are redefining DEBUG_PRINT(...).

Dear Larry

Before I add the DHT library, this error does not occur, it happens after I add the DHT library. Is it possible to do something with the library to solve it? Or any changes needed to solve it?

Thanks

Best
John

Is no an error, it's a warning. It is perfectly legal to redefine a macro if this kind, but you are just warned to be aware that you have done and consider the implications.

I wrote the above some time ago, now I wonder if you did define a DEBUG_PRINT yourself.

If it is your macro, you can just tweak the name to be different.

If it is a macro two libraries happen to define, it may or not be a problem. At worst it turns out to be some kind of show stopper, then you'd have to find your library copy for one of the libraries and modify it the same way - change the name, which might be easier doing in one library rather than the other. It just depends on how scattered the use of the macro is in each.

It may be possible that the definitions are identical, then the warning could be ignored.

a7

Dear A7

If one of the lib is more scattered, while dht lib is the only possible lib to change the name, and below is the dht.h file code from the DHT_sensor_library. What should I change?

/*!
 *  @file DHT.h
 *
 *  This is a library for DHT series of low cost temperature/humidity sensors.
 *
 *  You must have Adafruit Unified Sensor Library library installed to use this
 * class.
 *
 *  Adafruit invests time and resources providing this open source code,
 *  please support Adafruit andopen-source hardware by purchasing products
 *  from Adafruit!
 *
 *  Written by Adafruit Industries.
 *
 *  MIT license, all text above must be included in any redistribution
 */

#ifndef DHT_H
#define DHT_H

#include "Arduino.h"

/* Uncomment to enable printing out nice debug messages. */
//#define DHT_DEBUG

#define DEBUG_PRINTER                                                          \
  Serial /**< Define where debug output will be printed.                       \
          */

/* Setup debug printing macros. */
#ifdef DHT_DEBUG
#define DEBUG_PRINT(...)                                                       \
  { DEBUG_PRINTER.print(__VA_ARGS__); }
#define DEBUG_PRINTLN(...)                                                     \
  { DEBUG_PRINTER.println(__VA_ARGS__); }
#else
#define DEBUG_PRINT(...)                                                       \
  {} /**< Debug Print Placeholder if Debug is disabled */
#define DEBUG_PRINTLN(...)                                                     \
  {} /**< Debug Print Line Placeholder if Debug is disabled */
#endif 

/* Define types of sensors. */
static const uint8_t DHT11{11};  /**< DHT TYPE 11 */
static const uint8_t DHT12{12};  /**< DHY TYPE 12 */
static const uint8_t DHT21{21};  /**< DHT TYPE 21 */
static const uint8_t DHT22{22};  /**< DHT TYPE 22 */
static const uint8_t AM2301{21}; /**< AM2301 */

#if defined(TARGET_NAME) && (TARGET_NAME == ARDUINO_NANO33BLE)
#ifndef microsecondsToClockCycles
/*!
 * As of 7 Sep 2020 the Arduino Nano 33 BLE boards do not have
 * microsecondsToClockCycles defined.
 */
#define microsecondsToClockCycles(a) ((a) * (SystemCoreClock / 1000000L))
#endif
#endif

/*!
 *  @brief  Class that stores state and functions for DHT
 */
class DHT {
public:
  DHT(uint8_t pin, uint8_t type, uint8_t count = 6);
  void begin(uint8_t usec = 55);
  float readTemperature(bool S = false, bool force = false);
  float convertCtoF(float);
  float convertFtoC(float);
  float computeHeatIndex(bool isFahrenheit = true);
  float computeHeatIndex(float temperature, float percentHumidity,
                         bool isFahrenheit = true);
  float readHumidity(bool force = false);
  bool read(bool force = false);

private:
  uint8_t data[5];
  uint8_t _pin, _type;
#ifdef __AVR
  // Use direct GPIO access on an 8-bit AVR so keep track of the port and
  // bitmask for the digital pin connected to the DHT.  Other platforms will use
  // digitalRead.
  uint8_t _bit, _port;
#endif
  uint32_t _lastreadtime, _maxcycles;
  bool _lastresult;
  uint8_t pullTime; // Time (in usec) to pull up data line before reading

  uint32_t expectPulse(bool level);
};

/*!
 *  @brief  Class that defines Interrupt Lock Avaiability
 */
class InterruptLock {
public:
  InterruptLock() {
#if !defined(ARDUINO_ARCH_NRF52)
    noInterrupts();
#endif
  }
  ~InterruptLock() {
#if !defined(ARDUINO_ARCH_NRF52)
    interrupts();
#endif
  }
};

#endif

Besides, in the DHT_sensor_library includes those files as in the attached image.
image

Thank you

John

Only the *.cpp and *.h files need be looked at. They are all that gets pulled in when your sketch code is verified or uploaded.

The identifiers

DEBUG_PRINT
DEBUG_PRINTLN

need to be changed everywhere they appear in all four files. A text editor you are familiar with will be your friend here.

You can change them to anything you want. Just make it unique, like

xxDEBUG_PRINT
xxDEBUG_PRINTLN

I post this considering that there is perhaps a better way to get past the warning, and that by supplying a bad answer I will be rapidly slam/corrected with a better one by some kind fellow traveller if so.

The warning is only helpful advice. If your code compiles and functions, this may be one of those cases where it's easier to just ignore the red ink…

HTH

a7

Thank you a7

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