XBee currently uses the hardware UART and it is working fine.
The GPS module and the digital compass are both using Software Serial.
My problem is that if I instantiate both software serials, only the latest one will work.
Below is my sample code:
Code: Select all
void CSensor::initSensors()
{
//for gps
this->gpsSerial = new SoftwareSerial(2, 3);
this->gpsSerial->begin(9600);
//for digital compass
this->compassSerial = new SoftwareSerial(6, 7);
this->compassSerial->begin(9600);
}
gpsSerial is declared as a pointer member of CSensor class. -> SoftwareSerial* gpsSerial;
compassSerial is also declared the same -> SoftwareSerial* compassSerial;
In the above sample code, only the digital compass will work, the GPS will not work. But if I interchange the positions of the code such that it will look like this:
Code: Select all
void CSensor::initSensors()
{
//for digital compass
this->compassSerial = new SoftwareSerial(6, 7);
this->compassSerial->begin(9600);
//for gps
this->gpsSerial = new SoftwareSerial(2, 3);
this->gpsSerial->begin(9600);
}
The GPS will now work, but the digital compass won't. I assume Software Serial has a problem, what solution can I do? Also is there a limit to the number of software serial pins you could use?