#22803
I just got Bluno Beetle V1.1 and I am trying to make it talk via Bluetooth to Android. I can connect but when I Send Data "123" I get back garbled characters (not random), why? Is it some encoding problem? How do I fix that?
Code: Select all
I/System.out: onCharacteristicWrite success:12345
I/System.out: onCharacteristicChanged  022&�

When I connect to the device in Serial Monitor, there are no issues (sending 123 gives me back newline separated numbers)

My environment:

On Bluno I run - from Ubuntu snap install of the IDE (snap install arduino-mhall119 --classic):
Code: Select all
void setup() {
  Serial.begin(115200);               //initialize the Serial
}

void loop() {
    if(Serial.available())
    {
        Serial.write(Serial.read());    //send what has been received
        Serial.println();
    }
}
I built BlunoBasicDemo with only one change compileSDK 27 and buildToolsVersion "26.0.3". Android log is:
Code: Select all
I/System.out: BluetoothGattCallback----onConnectionStateChange2
I/System.out: mGattUpdateReceiver->onReceive->action=com.example.bluetooth.le.ACTION_GATT_CONNECTED
I/BluetoothLeService: Connected to GATT server.
I/BluetoothLeService: Attempting to start service discovery:
I/System.out: onServicesDiscovered 0
I/System.out: mGattUpdateReceiver->onReceive->action=com.example.bluetooth.le.ACTION_GATT_SERVICES_DISCOVERED
    ACTION_GATT_SERVICES_DISCOVERED  00001800-0000-1000-8000-00805f9b34fb
    ACTION_GATT_SERVICES_DISCOVERED  00001801-0000-1000-8000-00805f9b34fb
    ACTION_GATT_SERVICES_DISCOVERED  0000180a-0000-1000-8000-00805f9b34fb
    ACTION_GATT_SERVICES_DISCOVERED  0000dfb0-0000-1000-8000-00805f9b34fb
    displayGattServices + uuid=00001800-0000-1000-8000-00805f9b34fb
    displayGattServices + uuid=00001801-0000-1000-8000-00805f9b34fb
    displayGattServices + uuid=0000180a-0000-1000-8000-00805f9b34fb
    mModelNumberCharacteristic  00002a24-0000-1000-8000-00805f9b34fb
    displayGattServices + uuid=0000dfb0-0000-1000-8000-00805f9b34fb
    mSerialPortCharacteristic  0000dfb1-0000-1000-8000-00805f9b34fb
    mSerialPortCharacteristic  0000dfb1-0000-1000-8000-00805f9b34fb
I/System.out: onCharacteristicRead  00002a24-0000-1000-8000-00805f9b34fb
    BluetoothLeService broadcastUpdate
I/System.out: mGattUpdateReceiver->onReceive->action=com.example.bluetooth.le.ACTION_DATA_AVAILABLE
I/System.out: allwriteCharacteristicString:AT+PASSWOR=DFRobot
I/System.out: mCharacteristicRingBufferlength:1
I/System.out: writeCharacteristic init AT+PASSWOR=DFRobo:success
I/System.out: onCharacteristicWrite success:AT+PASSWOR=DFRobo
I/System.out: allwriteCharacteristicString:AT+CURRUART=115200
    mCharacteristicRingBufferlength:2
I/System.out: writeCharacteristic init t
    :success
    onCharacteristicWrite success:t
    writeCharacteristic init AT+CURRUART=11520:success
I/System.out: onCharacteristicWrite success:AT+CURRUART=11520
I/System.out: writeCharacteristic init 0
    :success
    onCharacteristicWrite success:0
I/System.out: displayData DF Bluno
I/System.out: allwriteCharacteristicString:12345
    mCharacteristicRingBufferlength:1
    writeCharacteristic init 12345:success
I/System.out: onCharacteristicWrite success:12345
I/System.out: onCharacteristicChanged  022&�
    BluetoothLeService broadcastUpdate
I/System.out: mGattUpdateReceiver->onReceive->action=com.example.bluetooth.le.ACTION_DATA_AVAILABLE
    displayData 022&�
Michal
By dewe
#23021
Getting that quick achievement is not possible for any normal human being as they are the most luckiest ones who get what they expect from them and in the end get as well because they have their hard work behind them and this helps them in getting the right direction!
#25763
Hi michalp, did you find a solution already?
I'm having similar issues on a Bluno Nano BLE with Firmware 1.97 :|

My goal is to select a color on the android phone (using "ColorPickerDialog" by "margaritov") and send the HEX-value of the color to the Bluno to control the color of LED-strips. 8-)
Therefore I edited the BlunoBasicDemo, including 3 buttons to show up the ColorPickerDialog for 3 different LED-strips.
Image
Depending on which button I press, my phone will add a "v", "o" or "u" in front of the HEX-value to determine the LED-strip...
Code: Select all
        @Override
        public void onClick (View v){
            switch (v.getId()) {
                case R.id.bn_bluetooth:
                    if (bluetoothAdapter == null) {
                        Toast.makeText(this, "Bluetooth nicht verfügbar", Toast.LENGTH_LONG).show();
                        finish();
                        //	bluetoothStatus();
                    } else {
                        Intent intentRequestEnabled = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                        startActivityForResult(intentRequestEnabled, REQUEST_ENABLED);
                        //  Intent intentOpenBluetoothSettings = new Intent();
                        //  intentOpenBluetoothSettings.setAction(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS);
                        //  startActivity(intentOpenBluetoothSettings);
                    }
                    break;
                case R.id.buttonSerialSend:
                    serialSend(serialSendText.getText().toString());                //send the data to the BLUNO
                    break;
                case R.id.buttonScan:
                    buttonScanOnClickProcess();                                        //Alert Dialog for selecting the BLE device
                    break;
                case R.id.bn_vorne:
                    colorPickerVorne = new ColorPickerDialog(MainActivity.this, farbe_vorne);
                    colorPickerVorne.setAlphaSliderVisible(true);
                    colorPickerVorne.setHexValueEnabled(false);
                    colorPickerVorne.setTitle("Vorne");
                    colorPickerVorne.setOnColorChangedListener(new ColorPickerDialog.OnColorChangedListener() {
                        @Override
                        public void onColorChanged(int color) {
                            farbe_vorne = color;
                            bn_vorne.setBackgroundColor(farbe_vorne);
                            serialSend("v" + toHexString(farbe_vorne));
                        }
                    });
                    colorPickerVorne.show();
                    break;
                case R.id.bn_oben:
                    colorPickerOben = new ColorPickerDialog(MainActivity.this, farbe_oben);
                    colorPickerOben.setAlphaSliderVisible(true);
                    colorPickerOben.setHexValueEnabled(false);
                    colorPickerOben.setTitle("Oben");
                    colorPickerOben.setOnColorChangedListener(new ColorPickerDialog.OnColorChangedListener() {
                        @Override
                        public void onColorChanged(int color) {
                            farbe_oben = color;
                            bn_oben.setBackgroundColor(farbe_oben);
                            serialSend("o" + toHexString(farbe_oben));
                        }
                    });
                    colorPickerOben.show();
                    break;
                case R.id.bn_unten:
                    colorPickerUnten = new ColorPickerDialog(MainActivity.this, farbe_unten);
                    colorPickerUnten.setAlphaSliderVisible(true);
                    colorPickerUnten.setHexValueEnabled(false);
                    colorPickerUnten.setTitle("Unten");
                    colorPickerUnten.setOnColorChangedListener(new ColorPickerDialog.OnColorChangedListener() {
                        @Override
                        public void onColorChanged(int color) {
                            farbe_unten = color;
                            bn_unten.setBackgroundColor(farbe_unten);
                            serialSend("u" + toHexString(farbe_unten));
                        }
                    });
                    colorPickerUnten.show();
                    break;
                default:
                    break;
            }
        }


The Bluno should receive the string, look for the first letter and cut it off. Then send an answer back to the phone (received string, cut string and string length) and safe the HEX-value on its ROM.
:arrow: Later on it will also control 3 RGB-LED-Strips by using a seperate PWM-board (i2c)...
Code: Select all
void loop() {
  while (!Serial.available()){
    
  }
  // Seriell als String einlesen
  while (Serial.available()){
    SerialEingabe = Serial.readStringUntil('\r');
Serial.println(SerialEingabe);

    if (SerialEingabe.startsWith("v")){
      FarbeVorne = SerialEingabe.substring(1, SerialEingabe.length());
Serial.println(FarbeVorne);
//Serial.println(sizeof(FarbeVorne));
      EEPROM.put(AdrFarbeVorne, FarbeVorne);
    }
    
    if (SerialEingabe.startsWith("o")){
      FarbeOben = SerialEingabe.substring(1, SerialEingabe.length());
Serial.println(FarbeOben);
//Serial.println(sizeof(FarbeOben));
      EEPROM.put(AdrFarbeOben, FarbeOben);
    }
    
    if (SerialEingabe.startsWith("u")){
      FarbeUnten = SerialEingabe.substring(1, SerialEingabe.length());
Serial.println(FarbeUnten);
//Serial.println(sizeof(FarbeUnten));
      EEPROM.put(AdrFarbeUnten, FarbeUnten);
    }
  }
}

I started with a baud-rate of 115200, since that's the default value. I also tried using 57600 and 9600.
The slower the baud, the worse the result!
Image
Note that even some characters got lost in between.

Strange thing:
The first button works best, but far from good/reliable. The second button results in these strange characters immediately and the third one usually freezes the Bluno right away. The code for all 3 buttons are exactly the same (except for the "v", "o" or "u"). Both in Android and the Arduino IDE (1.8.7)


By the way:
How to use images on this board?? Neither image, nor Link seems to work