Serial baud test code

Hey guys!

I’m just practicing my coding and at the same time preparing to test the Serial2 feature.

Just wondering if i got it correct for the switching of baud rate. I think it’s ok but it’s weird cos CoolTerm seems to have auto baud detection (no?).

It disconnects at the end and all i do it hit connect without changing the baud.

So i’m suspecting i didn’t get it right :smiley:

I was trying to do something the other day using arduino terminal, i had the spark set for 9600 and the terminal set for 57600. the funny thing was the terminal has no issues reading from the spark, everything displayed as expected. but nothing from the terminal was going to the spark… then i noticed and changed the baudrate and it worked normal. maybe worth trying to go the other way? get the user to input something like a string and then make sure it displays the same string?

I also had some buffering issues when transferring long strings (RTTTL songs) anything over about 50 or 60 bytes. adding 100ms delays after that fixed it but really really slowed things down. i guess because im reading it faster than it can come in… I tried a single delay without luck and had to do it on every read to make it work, then after 100bytes it messed up again so had to add even more of a delay! I guess there is a better way to do it and do some calcs with baudrates and stuff but i only used it for transferring tunes to test them before setting them as a doorbell so not really too fussed.

void readString(char *ptr, int length) {

    int pos = 0;

    while (!Serial.available()) SPARK_WLAN_Loop(); //wait for serial data to come in 
    active = millis();
    while (Serial.available()) {

        inChar =;
        if (inChar == 0x0A || inChar == 0x0D)
        ptr[pos] = inChar;
        if (pos >= 50) delay(100);
        if (pos >= 100) delay(50);

        if (pos >= length - 1)
    ptr[pos] = '\0';

    while (Serial.available())
        (void); //throw it away

1 Like

That’s a good point!

Maybe i should do a loop back test instead and see how things go.

This is going to help a lot with testing Serial2. I know it should well work but just in case :smiley: