Just trying to read a simply character via Bluetooth


#1

I have created an app on my Windows phone to send a message to my Makeblock Ultimate Kit via Bluetooth…

My code to send the message is very simple:

        public async Task<uint> SendMessageAsync(string message)
        {
            uint sentMessageSize = 0;
            if (writer != null)
            {
                uint messageSize = writer.MeasureString(message);
                writer.WriteByte((byte)messageSize);
                writer.WriteString(message);
                await writer.StoreAsync();

                sentMessageSize = 1;
            }
            return sentMessageSize;
        }

Where the message is a string in the form of “a” or “b”

I have created the following code for reading the character…

if(bluetooth.available())
{
delay(10);
inDat = bluetooth.read();
Serial.println(inDat);
if (inDat == ‘a’)
{
motor3.run(motorSpeed);
motor4.run(motorSpeed);
}
else if(inDat = ‘b’)
{
motor3.stop();
motor4.stop();
}
}

When I look at the serial print out, I see strange characters like a y with two dots above it or a crazy looking q.

Any help?


#2

println adds a carriage return and newline so you might be getting more than you wanted. What are you using to see the serial printout?


#3

I am using the serial viewer from the IDE of the arduino…


#4

The same problem was discussed here:


#5

@Michal_Benes Thanks for the information… I will try that later today.


#6

@Michal_Benes I changed my baud rate to 115200 and everything is working now. Thanks!


#7