B4R Question Problem with HC6 Bluetooth Module

WebQuest

Active Member
Licensed User
Hi I have a problem with the Bluetooth module, I followed the community tutorial but the problem persists. After connecting all the pins according to the diagram attached in the tutorial for HC6, when the input is sent via mobile phone, the LED does not light up. I have tried various solutions but nothing. I have tested the components and they are all working individually. What could be the problem?


MODULE Bluetooth HC6

Rot : VCC > 5V
Black : GND > GND
Yellow : TXD > DIG 10
Green : RXD > DIG 11

LED : A0
Module Bluethoot Schema.png

SoftwareSerial Library

B4R CODE:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

Sub Process_Globals
    Public Serial1 As Serial
    Private SoftwareSerial1 As SoftwareSerial
    Private astream As AsyncStreams
    Private leds(1) As Pin
    Private timer1 As Timer
  
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    leds(0).Initialize(leds(0).A0, leds(0).MODE_OUTPUT)
    SoftwareSerial1.Initialize(9600, 10, 11) 'software serial port on pins 10 and 11
    astream.Initialize(SoftwareSerial1.Stream, "AStream_NewData", Null)
    timer1.Initialize("timer1_Tick", 1000)

    timer1.Enabled = True
    'leds(0).DigitalWrite(True)
  
End Sub

Sub Timer1_Tick
    astream.Write("Millis here: ".GetBytes)
    astream.Write(NumberFormat(Millis, 0, 0).GetBytes)
    astream.Write(Array As Byte(10)) 'end of line character. AsyncStreamsText will cut the message here
End Sub

Sub AStream_NewData (Buffer() As Byte)
    For i = 0 To Buffer.Length - 2 Step 2
        Dim ledNumber As Byte = Buffer(i)
        Dim value As Boolean = Buffer(i + 1) = 1
        leds(ledNumber).DigitalWrite(value)
        Log(ledNumber)
    Next
End Sub


B4A CODE:
Region  Project Attributes
    #ApplicationLabel:  Example
    #VersionCode: 2
    #VersionName: 1
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private rp As RuntimePermissions
End Sub

Sub Globals
    Private Switch1 As Switch
    Private lblStatus As Label
    Private btnConnect As Button
    Private lblMessage As Label
    Private ProgressBar1 As ProgressBar
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
End Sub

Sub Activity_Resume
    SetState
End Sub

Public Sub SetState
    Switch1.Enabled = Starter.connected
    btnConnect.Enabled = Not(Starter.connected)
    ProgressBar1.Visible = Starter.connecting
    Dim status As String
    If Starter.connected Then
        status = "connected"
    else if Starter.connecting Then
        status = "trying to connect..."
    Else
        status = "disconnected"
    End If
    lblStatus.Text = $"Status: ${status}"$
End Sub

Public Sub MessageFromDevice(msg As String)
    lblMessage.Text = msg
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Switch1_CheckedChange(Checked As Boolean)
    Dim b As Byte
    If Checked Then b = 1 Else b = 0
    CallSub2(Starter, "SendMessage", Array As Byte(0, b))
End Sub

Sub btnConnect_Click
    rp.CheckAndRequest(rp.PERMISSION_ACCESS_COARSE_LOCATION)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result Then
        CallSub(Starter, "Connect")
    Else
        ToastMessageShow("No permission", True)
    End If
End Sub

Sub lblStatus_Click
    
End Sub
 
Last edited:

janderkan

Well-Known Member
Licensed User
Longtime User
Where does it fail, do you send anything, do you receive anything, can you blink the led, what is happening in starter, is the buffer empty, are the events triggered ?
 
Upvote 0

WebQuest

Active Member
Licensed User
All works only that the LED does not turn on, the millis walk then I set in the starter in the sendMessage 'try' with a thoastmessage and at the click of the switch the event works but the LED continues to not respond.
 
Upvote 0

WebQuest

Active Member
Licensed User
I was wondering where the subAStream_NewData (Buffer () As Byte) should be inserted. also the newdata log does not respond at this point it happens that the sub does not receive any data.
 
Upvote 0
Top