2

I'm trying to convert a class header file from another c++ project to arduino, which in my mind involves replacing cout with Serial.println.

When I try to recomplile with all of these changes, I get this error from the compiler:

error: 'Serial' was not declared in this scope
     Serial.print(p[i]);

Can someone explain this to me?

4

You have to #include <Arduino.h>, or compile with the -include Arduino.h flag. The Arduino IDE normally does that for you, but you have to do it yourself if you are working outside the IDE.

There are a couple of Arduino Makefiles floating around the Web which, just like the IDE, take care of this for you.

  • I'm actually using the Arduino IDE. :\ – Preston Shumway May 16 '15 at 1:59
  • Are you compiling a .ino or a .cpp? If it's a .cpp, the IDE is probably not adding the #include. If it's a .ino, it may just have messed your code. In the IDE options, you can ask to see all the compile-time messages. This will show the g++ command-line and tell you if it's compiling your original source or a modified version. You will also see the paths of the temporary cpp files it's creating, check their contents, and see if it has broken something. – Edgar Bonet May 16 '15 at 8:18

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.