Is it possible to communicate with two shields at different baud rates? I got GPS that streams data to softserial 4,5 and a GSM shield that uses softserial 2,3. The baud rate for the GPS is 38400. The GSM has a 9600 baud rate. Both shields work fine separately but trying to change the baud rate mid-program hasn't worked so far.
Each SoftSerial should be independent. Just create two instances of SoftSerial. However, only one can be listening at a time.
Not 100% sure but on the uno (which Arduino do you have) I understand that you can only have one instance of Software Serial
End of.
Mark
If you are having two serial streams, it may work better if you go for an Arduino or Arduino work-alike that has multiple hardware serial devices, rather than trying to use software serial. The Mega2560/Due have 4 hardware serial lines (0/1, 14/15, 16/17, and 18/19). The Teensy 3.0 has 3 (0/1, 7/8, 9/10).
johncurry:
trying to change the baud rate mid-program hasn't worked so far.
It should not be necessary to change the baud rate after the initial configuration. Can you post an example sketch that demonstrates the problem?
I am using the Uno. I tried changing the baud rate mid-program as my sketch below shows. The sketches work fine separately, but not when combined into the sketch below
#include "SIM900.h"
#include "sms.h"
#include <SoftwareSerial.h>
SMSGSM sms;
SoftwareSerial gpsserial = SoftwareSerial(4, 5);
SoftwareSerial gsmserial = SoftwareSerial(2, 3);
void setup()
{
}
void loop()
{
gpsserial.begin(38400);
while (gpsserial.available())
{
char c = gpsserial.read();
Serial.write(c);
}
gsmserial.begin(9600);
Serial.println("GSM Shield testing.");
sms.SendSMS("+449710489378", "text");
Serial.println("\nSMS sent OK");
}
If you have two separate software serial streams why not put the sss.begin(baudrate) in setup() where it will just be called once?
...R
You are not changing the baud rate, you are setting the baud rate of 2 separate instances of SoftwareSerial. As has been suggested this would normally be done in setup().
What you are not doing anywhere is setting the baud rate of the hardware serial that you try to print your "SMS sent OK" message to so that won't work.
I understand that you can only have one instance of Software Serial
Yes, you can have multiple softwareSerials. The first line of the docs is:
-If using multiple software serial ports, only one can receive data at a time.