3

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?

asked May 15, 2015 at 18:12

1 Answer 1

3

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.

answered May 15, 2015 at 18:46
2
  • I'm actually using the Arduino IDE. :\ Commented May 16, 2015 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. Commented May 16, 2015 at 8:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.