[SOLVED, but discussion still welcome] Do baud rates always need to match...

Do baud rates always need to match, or will they need to be different sometimes?

I'm attempting to use the SoftModem library (SoftModem005) to demodulate some FSk. I don't know a lot about the library, I think the low frequency is a 1, and the high frequency is the 0, based on testing with a constant signal. In the .h file I have set the baud rate to 1200, low frequency to 1200, high frequency to 2200, and the buffer size to 32. I'm not exactly sure about what a change in buffer size does, but a tutorial I looked at suggests bigger is better.

I feed a 1200hz square wave into the modem's Rx input (digital pin 6 or pin 7) and I get 11111111 (in binary) repeating with an ocasional error, which definitely makes sense. What I'm confused by is my baud rates. They seem to be all over the place, but only work in this specific configuration.

My serial monitor is at 9600, the arduino is at 115200, and the modem is at 1200. I've tried other combinations and this seems to be the only configuration that delivers the correct output to the serial monitor. Why does it work with these baud rates and not others?

My understanding of baud rates is that they are simply the rate of data transfer, like a defined clock rate rather than an actual clock. They let the receiver know the difference between a 00000000 and just a really slow 0. If this is true, shouldn't they only work if the serial monitor and arduino have matching baud rates?

I haven't tested any other signals other than 00000000 or 11111111, I'm using my phone as a function generator, so that's all I have so far. I'm working out a way to use another arduino to send the data.

Code:

#include <SoftModem.h>        //Software Modem Library

SoftModem modem;              //Because SoftModem.begin wont work for some reason

int LED = 9;
int x;
void setup()
{
  pinMode(LED, OUTPUT);
  Serial.begin(115200);
  Serial.println("Start :"); //Doesn't work when the serial monitor is on 9600 baud
  modem.begin();
}

void loop() 
{
  while (modem.available ())  //Doesn't work when arduino is on 9600 baud
  {
    int c = modem.read ();    //1byte Lead
    if (isprint(c))
    {
      Serial.write ((char)c);
    }
    else
    {
      Serial.write (" ");     //Hex printable characters are displayed in
      Serial.write (c);
      x++;
      if (x == 40) {
        Serial.println();     //wrapping line
        x = 0;
      }
    }
  }
}

OK - back to basics.
Frequency doesn't come in to it at all. Think bps (bits per second).

YES, the sender and receiver must be operating at the same bit-rate (not baud rate - that's an old term!)

Serial 'console' monitoring is often set to 115200 - both in the Serial.begin(115200), and in Serial Monitor at the bottom RH corner (or other serial terminal program you may be using).
You can use any speed, as long as both ends are set to the same speed.
(Check the number of data bits, parity and stop-buts as well... typically 115200-8-n-1)

For the modem, you need to know the default (or previously configured by someone else?!) speed the modem is expecting.
It is often one of 4800, 9600, or 19200 - but could be anything. Check the modem datasheet, or walk through all of the speeds until you find an 'OK' response to Serial1.print("AT\r");

Let us know how you get on.

lastchancename:
For the modem, you need to know the default (or previously configured by someone else?!) speed the modem is expecting.
It is often one of 4800, 9600, or 19200 - but could be anything. Check the modem datasheet, or walk through all of the speeds until you find an 'OK' response to Serial1.print("AT\r");

I'm actually using a software modem, not a hardware modem. So, I can set the baud to anything I want. I chose 1200 because that's what's used for APRS.

Serial1.print("AT\r"); gives me an error before I can upload the code, I think because there's only 1 serial port, so it only needs Serial.print("AT\r");. Using that, I get AT on the monitor when the bauds match, and an unprintable character when not.

lastchancename:
(Check the number of data bits, parity and stop-buts as well... typically 115200-8-n-1)

I'm not exactly sure what you mean by parity bits (yes, i googled it, "a function whose being even (or odd) provides a check on a set of binary values."), but there are 8 data bits, 1 start-bit, and 1 stop-bit. So 10 in total. I can't verify this, but I'm pretty sure that's what it is. If you check the .ccp file you might find something that will tell you.

Update: I changed the baud on the serial monitor to match the arduino's baud. Before this would give me nothing or gibberish, but I changed Serial.write to Seria.print. Now it prints them as a hexadecimal 0.

Now when the baud doesn't match, I get the char value of (11111111). When they do match, I get the hex value of (00000000). If the low frequency is a binary 0, then this means it's working now, while it wasn't before.

Updated Code:

#include <SoftModem.h>        //Software Modem Library

SoftModem modem;              //Because SoftModem.begin wont work for some reason

int LED = 9;
int x;
void setup()
{
  pinMode(LED, OUTPUT);
  Serial.begin(115200);
  Serial.println("Start :"); //Doesn't work when the serial monitor is on 9600 baud
  modem.begin();
}

void loop()
{
  while (modem.available ())  //Doesn't work when arduino is on 9600 baud
  {
    int c = modem.read ();    //1 byte Lead
    if (isprint(c))
    {
      Serial.print ((char)c);
    }
    else
    {
      Serial.print (" ");     //Hex printable characters are displayed in
      Serial.print (c);
      x++;
      if (x == 40)
      {
        Serial.println();     //Wrapping line
        x = 0;
      }
    }
  }
}

This is what I have on my Serial monitor:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 237
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 216

The 0's stream in continuously as a 1200hz tone is played into the modem. The numbers 237 and 216 apear when I switch to a 2200hz tone, and do not stream continuously (likely because it never sees a stop bit). The spaces and line wrapping indicates that isprint(c) came up false.

I looked at some ascii signal figures and I figured out what the parity bit is. Again I have no way to verify this, but I think the modem is expecting a start bit, 7 bits, parity bit, then 2 stop bits. 10 in total.

I did a length post about serial comms on Stack Exchange, as well as this post.

What Arduino do you have?

My serial monitor is at 9600, the arduino is at 115200, and the modem is at 1200. I've tried other combinations and this seems to be the only configuration that delivers the correct output to the serial monitor.

This doesn't make any sense, unless you are using a Micro or something which converts serial into USB. The serial communication relies on an agreed-upon baud rate (bit rate) - it can't possibly work if you have widely different rates for each device, unless they are all doing something different. For example, I could talk to a GPS at 4800 baud, and send the results to the serial monitor at 115200 baud. That makes sense because they are two totally different data streams.

I have an arduino Nano. I'm using the on board serial to USB thing. The modem is signal is being read at 1200 baud, then sent to the computer at 115200 baud. Like if it were talking to a GPS.

The reason I was so confused is that it appeared to work with the vastly different rates. I wont know for sure until I get something working sending actual data rather than a continuous stream of either 1 or 0, but it appears to be working just right now with both arduino and serial monitor on 115200.

Thank you for those posts, I'll certainly be learning a lot more about serial comms tonight!

(not baud rate - that's an old term!)

In this case, baud rate and bit rate are the same. But baud rate is not an old term. It is the symbol rate in a communication system. (See, for example, Baud - Wikipedia)
In the OP's case, one tone represents a zero and the other tone represents a one. Thus, there are only two symbols and the baud rate and bit rate are equal. But in many modems and other encoding schemes there can be many different tones, each representing a specific bit sequence. A modem might, for example, send one of eight different tones each of which encodes one of the bit sequences 000, 001, ..., 111. If these tones are sent at a rate of 100 per second then the baud rate is 100 baud. But the bit rate is three times higher than that - 300 bits per second.

Pete