2

I am using the mega 2560. When I just use .ino and .h files, if I use Serial, it works fine, without even using:

#include <SoftwareSerial.h>

However, when I add a .cpp file I start getting 2 errors, one is solved by adding the aforementioned include, the second one, after adding it, is :

'Serial' was not declared in this scope

I know I can declare it manually and use the RX/TX pins, but I would like to be able to use the default Serial so that I don't have to occupy more pins. Especially since it works file w/o the .cpp file. Can anyone explain to me why this happens? Is it because I specify a C++ file so the compiler changes?

3

A CPP file isn't an Arduino file. It doesn't know about anything Arduino-esque unless you tell it about it.

The simplest way is to just add, at the top of the file:

#include <Arduino.h>
| improve this answer | |
  • Ah, damn once you say it it becomes so obvious, thank you. – Bbit Jul 4 at 15:01

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.