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
SoftwareSerial Library
MODULE Bluetooth HC6
Rot : VCC > 5V
Black : GND > GND
Yellow : TXD > DIG 10
Green : RXD > DIG 11
LED : A0
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: