B4R Question HC-05 example with UNO, serial communication


Licensed User
Longtime User
Is it not possible to use two serial connections ?????

only when i init a second serial communication in AppStart,
no data from Anroid-Device was received !!

#Region Project Attributes
   #AutoFlushLogs: True
   #CheckArrayBounds: True
   #StackBufferSize: 600
#End Region

Sub Process_Globals
   Public Serial1 As Serial
   Private SoftwareSerial1 As SoftwareSerial
   Private Stream1 As AsyncStreams
   Private SoftwareSerial2 As SoftwareSerial
   Private Stream2 As AsyncStreams
   Private leds(5) As Pin
   Private timer1 As Timer
End Sub

Private Sub AppStart
  leds(0).Initialize(leds(0).A0, leds(0).MODE_OUTPUT)
   SoftwareSerial1.Initialize(9600, 10, 11) 'software serial port on pins 10 and 11
   Stream1.Initialize(SoftwareSerial1.Stream, "Android_NewData", Null)
   SoftwareSerial2.Initialize(9600, 12, 13) 'software serial port on pins 12 and 13
   Stream2.Initialize(SoftwareSerial2.Stream, "Slave_NewData", Null)

  timer1.Initialize("timer1_Tick", 1000)
  timer1.Enabled = True
End Sub

Sub Timer1_Tick
  Log("Timer, send data to Android")
   Stream1.Write("Millis here: ".GetBytes)
   Stream1.Write(NumberFormat(Millis, 0, 0).GetBytes)
   Stream1.Write(Array As Byte(10)) 'end of line character. AsyncStreamsText will cut the message here
End Sub

Sub Android_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
     Log("Received from Android: ",ledNumber,", ",value)
     ' leds(ledNumber).DigitalWrite(value)
End Sub

Sub Slave_NewData (Buffer() As Byte)
   Log("Received vom Slave: ")
   For x =0 To Buffer.Length-1
End Sub