selectable baud rate

hi all,

Does anyone know if it's possible to have a switchable baud rate?
For example, having a switch which can switch between 9600 and 38400 baud.

Unfortunately, after many attempts I'm pretty convinced that it is not possible..
However, it'd would be really helpful to know if there is any workaround.. or if I have to give up :frowning:

If it helps, the Arduino will communicate with Max using the 'serial' object. All I need is to be able to change the baudrate from Arduino. Max is not a problem..

thanks
warp

ok, I think i found some kind of solution..

all I did was to use the serial.begin() function inside the main loop, rather than in the setup, and then an 'if' statement

void loop()
{
if (switch is on)
{
Serial.begin(31250);
}else
{
Serial.begin(57600);
}

my code...
}

seems to work ok. however I don't know how good idea is to use the Serial.begin() in my main loop...
I'm afraid I will have to stick on this 'trick' if nothing else suggested...

thanks,
warp

Ideally you should have some sort of basic state-machine.

int SerialSpeed;

void setup(){
  SerialSpeed = 0;
  Serial.begin(31250);
}

void loop()  
{
    if (switch is on && (SerialSpeed != 0))
      {
        Serial.begin(31250);
        SerialSpeed = 0;
      }else if(switch is off && (SerialSpeed != 1))
      {
          Serial.begin(57600);
          SerialSpeed = 1;
      }
 
your code...
}

Now you're only re-initializing the UART when you need to change speeds.

thanks spiffed,

I'll try that.. :slight_smile: