Getting error 'Serial' was not declared in this scope


#1

I was adding dust sensor to my project, so I decided to keep the dust sensor code to begin with in separate cpp library.

but I get the errr saying

'Serial' was not declared in this scope
'Serial1' was not declared in this scope

'DEBUG' was not declared in this scope

'DEC' was not declared in this scope

How in cpp can I have serial being used in different cpp file ?


Getting error cannot call member function
#2

@seaurchin, do you have a #include "Particle.h" line at the top of your .cpp file? The Serial (and many other) objects and definitions are part of the Particle DeviceOS.


#3

Yes, what peekay123 said.

One difference between .ino files and .cpp files is that the .ino files transparently include particle.h for you.

The other difference is that .ino files generate forward declarations for you. This is necessary when you’ve implemented a function later in the file than when you’ve first used it. For example, if you pass the function to something like Particle.subscribe in setup() but you’ve implemented it farther down the file.


#4

Now that this problem is solved I have landed to new problem: Getting error cannot call member function