Pages: [1]   Go Down
Author Topic: Change Baud Rate of SoftwareSerial Communication after initial .begin  (Read 1550 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 31
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I've got a GPS device that does not remember its settings once switched off, and I can't keep it switched on all the time. Its default baud rate that it will always start at is therefore 9600. However, I can configure it through serial to go to a higher baud rate, which is required for a function I wish my program to have.

I can send the change baud signal fine, but then of course I need to change the baud rate of the arduino to match it, otherewise I just get meaningless squiggles.

Can anyone help?
In case that explanation is a bit confusing, here is what I (essentiallu) want to do in code:

Code:
mySerial.begin(9600);
mySerial.write("XXXXXXXX"); // string to send to change baud rate
  mySerial.write(13); // returns to accept change
  mySerial.write(10); // ^^^^^^^^^^^^^^^^^^^
mySerial.begin(38400) // ISSUE: How can I change the baud rate HERE!

Thanks everyone who took time to read this and especially anyone who can help!
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5255
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your issue isn't an issue, you should do it exactly as you're already doing it: by calling begin() again with the changed baud rate. There's no problem in calling the begin() method multiple times on the same object. Keep in mind that 38400 is the maximum baudrate that works with SoftwareSerial and this already will keep your Arduino quite busy if lots of data is transferred.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 644
Posts: 50524
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Keep in mind that 38400 is the maximum baudrate that works with SoftwareSerial
Where did that "fact" come from?
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5255
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Where did that "fact" come from?

Personal experience. I should have added "reliably" to my sentence. I never got 57600 baud running reliably with SoftwareSerial, although you could go up to 115200 baud theoretically. Maybe my serial devices were a bit picky about timing, have you got other experiences?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 644
Posts: 50524
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Maybe my serial devices were a bit picky about timing, have you got other experiences?
I've used it at 57600 to talk to XBees.

The NewSoftSerial web site says that it can work at 115200, but I was not successful transferring more than a few bytes at a time at that speed.
Logged

Washington
Offline Offline
God Member
*****
Karma: 39
Posts: 805
Firefox & Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I find 115200 works just find for transmitting on softserial. I never tried receiving greater then 9600.
Logged

Avoid throwing electronics out as you or someone else might need them for parts or use.
Solid state rectifiers are the only REAL rectifiers.
Resistors for LEDS!

Pages: [1]   Go Up
Jump to: