I wrote a wrapper class for a serial lcd screen for 4dulcd - and i want to be able to pass which serial i am using to communicate with it
I have these in my code myClass.h
#include <HardwareSerial.h>
public:
uint8_t Init(long BaudRate, HardwareSerial *serial);
private:
HardwareSerial *_HardSerial;
in myClass.cpp
uint8_t myClass::Init(long BaudRate, HardwareSerial *serial){
_HardSerial(serial);
...
}
In my sketch
#include <myClass.h>
myClass lcd;
void setup()
{
Serial1.begin(9600); // <- Error here?!
//lcd.Init(115000,&Serial1);
...
So the error is
sketch_sep17a.cpp: In function 'void setup()': sketch_sep17a:16: error: 'Serial1' was not declared in this scope
If i remove the myClass.h header than the Serial1 works... i Include it and it throws this error that makes no sense to-
I tried to include the hardwareserial in my sketch and make an instance of it but it requires all sorts of construction properties that i have no idea what they mean. And i would not even want to release my lib to do this as it is inconvenient for the normal end user.
I tried both references and pointers- same error.
Can any body help?
1 Answer 1
I might be missing something here, but where is Serial1 instantiated?
If there is no Serial1 object created then unless the begin function is static it won't work.
-
\$\begingroup\$ Serial1 is auto instantiated in the Harwarewareserial.cpp ... which by default is loaded in the Arduino IDE. somehow by including the hwserial.h header in my Lib-- it no longer knows what Serial1 is anymore..?but it should.. \$\endgroup\$Piotr Kula– Piotr Kula2011年09月18日 21:54:29 +00:00Commented Sep 18, 2011 at 21:54