B4R Question Send AT command to AT-09 BLE module ?

Discussion in 'B4R Questions' started by Cain Soft, Oct 15, 2018.

  1. Cain Soft

    Cain Soft Member Licensed User

    Hi All,
    How can I send AT command to AT-09 (HM-10 clone) BLE module ?
    The Arduino code is :
    Code:
    #include <SoftwareSerial.h>
    SoftwareSerial mySerial(
    23);
    void setup()
    {
      mySerial.begin(
    9600);
      
    Serial.begin(9600);
      delay(
    200);
      mySerial.println(
    "AT+NAMEdemoBleX");
      
    while (mySerial.available())
      {
        
    Serial.write(mySerial.read());
      
    }
      delay(200);
    }
    void loop()
    {
    }
    Bluetooth device name is changed successfully
    On B4R I tried these:
    Code:
    Private Sub AppStart
        Serial1.Initialize(
    115200)
        
    Log("appstart")
        softserial.Initialize(
    960023)
        astream.Initialize(softserial.Stream, 
    "astream_newdata"Null)
    'test 1  
        'astream.Write("AT+NAMEbleDemoBR".GetBytes) '-> receive ERR
        'astream.Write("AT+NAMEbleDemoBR") '-> receive ERR
        'astream.Write("AT+NAMEbleDemoBR\r\n".GetBytes) '-> receive ERR
    'test 2  
        'Dim message As String
        'message = "AT+NAMEbleDemoBR" + CRLF
        'astream.Write(message.GetBytes) '-> no answer, no change BLE name
    'test3  
        'astream.Write("AT+NAMEbleDemoBR".GetBytes)
        'astream.Write(Array As Byte(10))
        'astream.Write(Array As Byte(13)) '-> receive ERR
    'test4
        Dim buffer() As Byte
        
    Dim message As String
        message = 
    "AT+NAMEbleDemoBR"
        buffer = message.GetBytes
        astream.Write(buffer) 
    '-> receive ERR
      
        
    Log("AppStart End")
      
    End Sub
    Sub astream_NewData (Buffer() As Byte)
        
    Log("recieve: ", Buffer)
    End Sub
    An error message arrives "ERR" or nothing happens
    Thanks.
     
    Last edited: Oct 15, 2018
  2. Erel

    Erel Administrator Staff Member Licensed User

    Add astream.Write(CRLF)
     
    Cain Soft likes this.
  3. Cain Soft

    Cain Soft Member Licensed User

    Thanks Erel!
    It's working now (+ delay).
    Code:
    Sub Process_Globals
        
    Public Serial1 As Serial
        
    Private astream As AsyncStreams
        
    Private softserial As SoftwareSerial
        
    Private Timer1 As Timer
    End Sub
    Private Sub AppStart
        Serial1.Initialize(
    115200)
        
    Log("appstart")
        softserial.Initialize(
    960023)
        astream.Initialize(softserial.Stream, 
    "astream_newdata"Null)
        Timer1.Initialize(
    "Change_BLEname"200)
        Timer1.Enabled = 
    True
    End Sub
    Sub Change_BLEname
        astream.Write(
    "AT+NAMEbleDemoBRnewXX".GetBytes)
        astream.Write(
    CRLF)
        Timer1.Enabled = 
    False
    End Sub
    Sub astream_NewData (Buffer() As Byte)
        
    Log("recieve: ", Buffer)
    End Sub
     
    Erel likes this.
  4. Erel

    Erel Administrator Staff Member Licensed User

    Note that you can use CallSubPlus instead of the timer.
     
  5. Cain Soft

    Cain Soft Member Licensed User

    This is even better, thank you!
    Code:
    Sub Process_Globals
        
    Public Serial1 As Serial
        
    Private astream As AsyncStreams
        
    Private softserial As SoftwareSerial
    End Sub
    Private Sub AppStart
        Serial1.Initialize(
    115200)
        
    Log("appstart")
        softserial.Initialize(
    960023)
        astream.Initialize(softserial.Stream, 
    "astream_newdata"Null)
        CallSubPlus(
    "Change_BLEname"2000)
    End Sub
    Sub Change_BLEname(input As Byte)
        astream.Write(
    "AT+NAMEbleDemoBR_V2".GetBytes)
        astream.Write(
    CRLF)
    End Sub
    Sub astream_NewData (Buffer() As Byte)
        
    Log("recieve: ", Buffer)
    End Sub
     
    Erel likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice