Tell me more ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

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?

share|improve this question

1 Answer

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.

share|improve this answer
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.. – ppumkin Sep 18 '11 at 21:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.