I get several errors once I try to include these two libraries:

error: expected unqualified-id before '{' token #define DEBUG_PRINTLN(...) {}

#include <DHT.h>
#include <DGS.h>

void setup() {

void loop() {

Apparently DEBUG_PRINTLN is causing the problems, because it is defined as a private function in DGS.h and as a constant (#define) in DHT.h.

Including DGS.h before DHT.h does not throw errors. But is this a safe workaround or might I run into errors later? How can I deal with that, without modifying the libraries?


  DGS_25SEP17.h - Library for reading KWJ Engineering with SPEC Sensors on Digital SDK with firmware date 25SEP17.
  Created by David E. Peaslee, Mar 29, 2018.

#ifndef _DGS_h
#define _DGS_h

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#elif defined(SPARK)
//#include "application.h"
#include "WProgram.h"

#include "Stream.h"

class DGS
    Stream *_mySerial;
    long dataArray[11]; //Multipurpose array
    //void unlock(void);
    void DEBUG_PRINTLN(long x);
    void DEBUG_PRINTLN(float x);
    void DEBUG_PRINTLN(String x);
    void DEBUG_PRINT(long x);
    void DEBUG_PRINT(float x);
    void DEBUG_PRINT(String x);

    DGS(Stream &mySerial); //Class that represents DULP with Stream as class for Serial
    DGS(Stream *mySerial); //Class that represents DULP with Stream as class for Serial

    bool DEBUG;

    int setToff(float offset);  //Sets a temperature offset
    int setBC(String BC);  //Initializes DGS with all information from barcode, only way to set Span
    String getFW(void); //Returns the Firmware Date

    int getLMP(void); //Loads LMP[3] with register values from LMP91000
    int LMP[3];  //LMP Registers, needs to be loaded with getLMP
    int setLMP(int R1, int R2, int R3); //Sets new LMP registers and reintializes LMP

    int zero(void); //Zeros to current reading, Zero only in a clean air environment
    int setXSpan(float); //ReCalibrates device, only should be used after zero, and using a calibrated gas

    int getData(char c); //Gets the data and loads into variables
    long getConc(char x = 'p');  //Reads concentration from current data array 'p' ppb or 'c' counts
    long getTemp(char t = 'C');  //Reads temperature from current data array 'C' for Celsius or 'F' for Fahrenheit
    long getRh(char r = 'r'); //Reads Rh from current data array 'r' for Rh and 'c' for counts

    void getEEPROM(void); //Loads variables into EEPROM E[5] and e[14] arrays, outputs EEPROM if DEBUG is true
    String eepromStr[5]; //Stores the character based EEPROM data
    long eepromInt[13];  //Stores the integer based EEPROM data
    float Sensitivity_Code;  //Stores the sensitivity coefficient in nA/PPM



/* DHT library

MIT license
written by Adafruit Industries
#ifndef DHT_H
#define DHT_H

#if ARDUINO >= 100
 #include "Arduino.h"
 #include "WProgram.h"

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

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

// Setup debug printing macros.
#ifdef DHT_DEBUG
  #define DEBUG_PRINT(...) { DEBUG_PRINTER.print(__VA_ARGS__); }
  #define DEBUG_PRINTLN(...) { DEBUG_PRINTER.println(__VA_ARGS__); }
  #define DEBUG_PRINT(...) {}
  #define DEBUG_PRINTLN(...) {}

// Define types of sensors.
#define DHT11 11
#define DHT12 12
#define DHT22 22
#define DHT21 21
#define AM2301 21

class DHT {
   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);

  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;
  uint32_t _lastreadtime, _maxcycles;
  bool _lastresult;
  uint8_t pullTime; // Time (in usec) to pull up data line before reading

  uint32_t expectPulse(bool level);


class InterruptLock {
   InterruptLock() {
#if !defined(ARDUINO_ARCH_NRF52)  
   ~InterruptLock() {
#if !defined(ARDUINO_ARCH_NRF52)  


The DEBUG_ functions in the DGS class are private and used only in DGS.cpp. They will not collide with the macros from DHT.h

If DHT.h is included before DGS.h, the preprocessor replaces the DEBUG_ function names with the content of the macros from DHT.h and the result doesn't make sense for the compiler.

You could do #undef DEBUG_PRINT and #undef DEBUG_PRINTLN after DHT.h to undefine the macros for the rest of the sketch. DHT.cpp includes DHT.h and will have the macros defined.

| improve this answer | |
  • Thanks! I assume by 'GBS' you mean 'DGS'? – wheeler Jul 4 '19 at 6:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.