Uno to ESP32 port: digitalRead, LOW, HIGH "not declared in this scope"

I'm porting an Uno project to the ESP32. It compiles and runs fine as an Uno project but throws lots of errors when I try to compile it for the EPS32. I'm addressing these one by one, from the top of the list down, until I can get the sketch to compile.

I'm currently scratching my head over things like this:

ePaper_CFAP122250A00213.cpp:27:34: error: 'digitalRead' was not declared in this scope

   while(0 != digitalRead(EPD_BUSY));

ePaper_CFAP122250A00213.cpp:16:45: error: 'LOW' was not declared in this scope

 #define ePaper_CS_0   (digitalWrite(EPD_CS, LOW))

ePaper_CFAP122250A00213.cpp:16:48: error: 'digitalWrite' was not declared in this scope

 #define ePaper_CS_0   (digitalWrite(EPD_CS, LOW))

At the risk of stating the obvious, here's what's odd about these errors (there are many more just like them):

  • As I said before, this stuff compiles fine for the Uno.
  • Why should standard Arduino key words like digitalWrite, LOW, and HIGH be unrecognized "in this scope?"
  • Why are the last two errors being called out in #define statements? I thought the compiler just does a dumb search-and-replace for those, then evaluates the line where they appear. Shouldn't that be where the error gets thrown?
  • I have digitalWrite, LOW, and HIGH in my .ino and they don't throw any errors.
  • The standard Blink example sketch has digitalWrite, LOW, and HIGH in it and compiles and executes fine on my h/w.

Can this have something to do with the .cpp library file (I've confirmed it's in the same folder as the other files in this project)? Compatibility between C++ and ESP32? Any thoughts appreciated.

With the ESP32 try #include "Arduino.h"

1 Like

Woohoo! That did it. Well, I used #include <Arduino.h>, but that cleared everything up. Thanks. I had a bunch of PROGMEMs I removed based on other errors (and advice) I was getting. Could I have left those in if I'd included Arduino.h?