Grove BLE Bluetooth

Hi,

i recently bought the “Grove BLE” bluetooth.

I’m trying to make it work with the grovepi+.

I plugged it into the RPISER port since it is supposed to be serial stuff.

I can successfully connect to UART0 and i’m able to receive incoming bluetooth message (Read).

However, i have trouble sending AT commands or even answer (Write).

Anyone already tried this ?

Thanks, have a nice day !

Antony

Hi,

I forgot to mention, that i run a Raspberry Pi 2 on Win 10 IOT.

I will post my code soon.

Thanks,

Antony

Hey Antony, we haven’t tried the BLE sensor with WinIOT. It’s an interesting idea, but haven’t tried it yet. We’ll have to take a look, but you’re having trouble sending AT commands out of the serial, is that right?

Hi !

Yes that’s correct !

I can read successfully data received on my SerialDevice.InputStream, however, when i write something on SerialDevice.OutputStream using a DataWriter, nothing seems to happen… even if it’s not AT commands, nothing is received on the paired Bluetooth client.

I will post my code today :slight_smile:

Thanks a lot, have a nice day.

        string aqs = SerialDevice.GetDeviceSelector("UART0");
        var devices = await DeviceInformation.FindAllAsync(aqs);


        var dis = devices.FirstOrDefault();

        Serial = await SerialDevice.FromIdAsync(dis.Id);

        // Configure serial settings
        Serial.WriteTimeout = TimeSpan.FromMilliseconds(1000);
        Serial.ReadTimeout = TimeSpan.FromMilliseconds(1000);
        Serial.BaudRate = 9600;
        Serial.Parity = SerialParity.None;
        Serial.StopBits = SerialStopBitCount.One;
        Serial.DataBits = 8;
        Serial.Handshake = SerialHandshake.None;
        Serial.ErrorReceived += Serial_ErrorReceived;

DataReader reader = new DataReader(Serial.InputStream);

            while (true)
            {
                try
                {
                    reader.InputStreamOptions = InputStreamOptions.Partial;
                    uint bytesRead = await reader.LoadAsync(4096).AsTask();

                    if (bytesRead > 0)
                    {
                        string text = reader.ReadString(bytesRead);
                        Debug.WriteLine(text);
                    }
                }
                catch (Exception)
                {
                }
            }

/////////////////////////////////////////////////////////////////////////////////

Now the writing part :

    async Task WriteToSerial(string data)
    {
        // Create the DataWriter object and attach to OutputStream
        DataWriter dataWriteObject = new DataWriter(Serial.OutputStream);

        try
        {
            //Serial.OutputStream.AsStreamForWrite().Write(Encoding.ASCII.GetBytes(data), 0, Encoding.ASCII.GetBytes(data).Length);
            // Load the text from the sendText input text box to the dataWriter object
            dataWriteObject.WriteString(data);

            uint bytesWritten = await dataWriteObject.StoreAsync();

            if (bytesWritten > 0)
            {
                Debug.WriteLine(bytesWritten + " bytes written success");
            }
        }
        finally
        {
            dataWriteObject.DetachStream();
        }
    }