"Fatal Error: avr/pgmspace.h no such file or directory" error for ESP8266

Hi!

I am using Arduino IDE to program my NodeMCU module. I am trying to interface seven segment display using MAX7219 IC. FOr that I am using LedControl library from here. I have seen people using LedControl library with their ESP8266 but my IDE is refusing to compile it. One of the tutorials even said "Since the LedControl library does not utilize any hardware specific functions of Arduino platform, it is compatible with ESP8266"

My IDE throws the following error:

Arduino: 1.8.6 Hourly Build 2018/01/03 03:33 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, 4M (1M SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

In file included from G:\arduino-nightly\project\sketch_jul23a\sketch_jul23a.ino\sketch_jul23a.ino.ino:1:0:

C:\Users\HP\Documents\Arduino\libraries\LedControl\src/LedControl.h:30:26: fatal error: avr/pgmspace.h: No such file or directory

 #include <avr/pgmspace.h>

                          ^

compilation terminated.

exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).

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

One of the tutorials even said "Since the LedControl library does not utilize any hardware specific functions of Arduino platform, it is compatible with ESP8266"

Well, you know that EVERYTHING you read on the internet is the absolute truth, and nothing but the truth, you must be doing something wrong to get that compiler error.

Of course, there are two possibilities. One is that the author of that statement was using a different version of the library than you are using. The other is that the author was full of sh*t.

the esp8266 core really contains that file in the 2.4.1 git version

I found the answer. You can remove #include <avr/pgmspace> from the LedControl.h header file or just create the dir where it is looking for the file. I took the easy route.

GOOD LUCK!!

Juraj:
the esp8266 core really contains that file in the 2.4.1 version
Arduino/cores/esp8266/avr at master · esp8266/Arduino · GitHub

That change was actually made after the 2.4.1 release so the current code will not work with ESP8266 core 2.4.1. With 2.4.1 or earlier you would do something like this:

#if defined(AVR)
#include <avr/pgmspace.h>
#else  //defined(AVR)
#include <pgmspace.h>
#endif  //defined(AVR)

but it's interesting to see they did that. It's how Arduino SAMD Boards and Arduino SAM boards works too so it probably makes sense.

1 Like