Hi everyone! I’m new on this forum but I have some time working with Arduino and other stuff.
Well my problem starts because I’m building a custom library to comunicate with a XBee module. It’s based on the library that we can found on the “libraries page”, but I’m changing some functionalities according to my project. My specific problem is with a HardwareSerial pointer that I’m declaring in order to get the Arduino’s Serial Port. My class looks something like this:
myOwnClass.h
#ifndef myOwnClass_h
#define myOwnClass_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <inttypes.h>
class myOwnClass {
public:
myOwnClass();
void begin(long baudRate);
private:
HardwareSerial *_serial;
}
#endif
myOwnClass.cpp
#include "myOwnClass.h"
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
myOwnClass::myOwnClass(){
}
void myOwnClass::begin(long baudRate){
_serial->begin(baudRate);
_serial->println("Initializing Serial Port ....");
}
Then my sketch is something like this:
#include <myOwnClass.h>
myOwnClass _testMyOwnClass = myOwnClass();
int ledPIN = 13;
void setup(){
_testMyOwnClass .begin(9600);
pinMode(ledPIN, OUTPUT);
}
void loop(){
//Just to do something ...
digitalWrite(ledPIN, HIGH);
delay(1000);
digitalWrite(ledPIN, LOW);
delay(1000);
}
Well, of course it has a lot of more coding … methods, attributes and so on. But my specific problem is with these lines. According to me! this should be sending a message to the serial monitor of the IDE, where I could see “Initializing Serial Port …”
Unfortunately it’s doesn’t do anything … not even the LED blinking … … It’s important to say that the code always compiles and that I can always upload the code to my Arduino, but as I said it doesn’t do anything.
What I have done to solve this issue is to replace the “begin” method on the class definition, and use something like this:
void myOwnClass::begin(long baudRate){
Serial.begin(baudRate);
Serial.println("Initializing Serial Port ....");
}
What am I missing? Is it something related to the HardwareSerial pointer? I almost forgot how to program with pointers … Do I need to do this “Serial handle” always like in the code above?
Please try someboy to send me an advice.
Best regards!