Library error on NodeMCU which I don't understand.

I have a "NodeMCU" board.

I have a sketch which uses a DHT sensor to detect temperature/humidity.
I have also the pub/sub library loaded.

Anyway, cutting to the chase:
The code complies ok with a few deprecated errors for some names used. But it compiles and works.

(From another thread)
I got an "SPI display" module.

After messing around I resolved to use these pins for the SPI bus:

#define MAX7219DIN D1   // GPIO5
#define MAX7219CS  D2   // GPIO4
#define MAX7219CLK D3   // GPIO0
#define brightness 15

I got this from an example sketch which works on an UNO (different pins) but it WORKS.

The display is lit, numbers are displayed and no errors.

So, I hope the chosen pins are "ok" but from what I can determine they shouldn't cause any problems.

I compile the code and get all these weird errors about the DHT sensor library.

In file included from /home/me/Arduino/libraries/DHT_sensor_library/DHT_U.cpp:22:0:
/home/me/Arduino/libraries/DHT_sensor_library/DHT_U.h:35:46: error: expected class-name before '{' token
   class Temperature : public Adafruit_Sensor {

                                              ^
/home/me/Arduino/libraries/DHT_sensor_library/DHT_U.h:38:19: error: 'sensors_event_t' has not been declared
     bool getEvent(sensors_event_t* event);

                   ^
/home/me/Arduino/libraries/DHT_sensor_library/DHT_U.h:39:20: error: 'sensor_t' has not been declared
     void getSensor(sensor_t* sensor);

                    ^
/home/me/Arduino/libraries/DHT_sensor_library/DHT_U.h:47:43: error: expected class-name before '{' token
   class Humidity : public Adafruit_Sensor {

                                           ^
/home/me/Arduino/libraries/DHT_sensor_library/DHT_U.h:50:19: error: 'sensors_event_t' has not been declared
     bool getEvent(sensors_event_t* event);

                   ^
/home/me/Arduino/libraries/DHT_sensor_library/DHT_U.h:51:20: error: 'sensor_t' has not been declared
     void getSensor(sensor_t* sensor);

                    ^
/home/me/Arduino/libraries/DHT_sensor_library/DHT_U.h:73:16: error: 'sensor_t' has not been declared
   void setName(sensor_t* sensor);

                ^
/home/me/Arduino/libraries/DHT_sensor_library/DHT_U.h:74:20: error: 'sensor_t' has not been declared
   void setMinDelay(sensor_t* sensor);

                    ^
/home/me/Arduino/libraries/DHT_sensor_library/DHT_U.cpp:35:27: error: variable or field 'setName' declared void
 void DHT_Unified::setName(sensor_t* sensor) {
                           ^
/home/me/Arduino/libraries/DHT_sensor_library/DHT_U.cpp:35:27: error: 'sensor_t' was not declared in this scope
/home/me/Arduino/libraries/DHT_sensor_library/DHT_U.cpp:35:37: error: 'sensor' was not declared in this scope
 void DHT_Unified::setName(sensor_t* sensor) {
                                     ^

But if I comment out the lines shown above, it compiles ok with no errors.

Yeah, I am doing something wrong.

But as I don't "get" what I am doing wrong, I don't see how I can learn what it is I am doing wrong.

As I see it:
The code works. No errors.
I add those #define lines and suddenly I am getting errors in another library which did work before.

Please post your full sketch. So far, I couldn't manage to reproduce the issue.

My general advice is to avoid using #define (and the preprocessor in general) unless absolutely necessary (which I doubt it is in this case). #define can result in some very confusing bugs. When you use real variables, the compiler is typically able to give you nicer error messages.

const byte MAX7219DIN = D1;   // GPIO5
const byte MAX7219CS = D2;   // GPIO4
const byte MAX7219CLK = D3;  // GPIO0
const byte brightness = 15;

Thanks.

That hasn't been explained/mentioned to me - to my memory.

What I have (since) discovered:
I "rolled back" my DHT library 1 level.

Now it works.

So there is some difference between DHT 1.3.0 and 1.3.1 (adafruit)

1.3.1 gives the error. 1.3.0 doesn't.

On what you said:

const byte MAX7219DIN = D1;   // GPIO5

(Though it is a 'D', to me byte didn't allow letters.)

D being valid in hex notation.

Ok, I just tried some of the stuff you offered:

#define MAX7219DIN D1   // GPIO5

Changed to:

const char* MAX7219DIN = D1;   // GPIO5

I get:

invalid conversion from 'uint8_t {aka unsigned char}' to 'const char*' [-fpermissive]

I admit I am stupid.

But as I don't "get" the subtle differences, I can't use what you suggested.

Probably to my detriment.

lost_and_confused:
(Though it is a 'D', to me byte didn't allow letters.)

D being valid in hex notation.

D1, etc. are variables defined in the ESP8266 hardware package's NodeMCU variant file:

static const uint8_t D0   = 16;
static const uint8_t D1   = 5;
static const uint8_t D2   = 4;
static const uint8_t D3   = 0;
static const uint8_t D4   = 2;
static const uint8_t D5   = 14;
static const uint8_t D6   = 12;
static const uint8_t D7   = 13;
static const uint8_t D8   = 15;
static const uint8_t D9   = 3;
static const uint8_t D10  = 1;

They translate between the markings on the NodeMCU board's silkscreen and the ESP8266 GPIO numbers. This means:

const byte MAX7219DIN = D1;   // GPIO5

is equivalent to:

const byte MAX7219DIN = 5;   // GPIO5

Thanks.

I am slowly getting to understand this "layout".

You're welcome. I'm glad if I was able to be of assistance. Enjoy!
Per