B4R Tutorial Connecting ESP8266 and Arduino with rSoftwareSerial library

An example of connecting an ESP8266 (NodeMCU used for this experiment) and an Arduino MEGA.
The Arduino runs B4R and the ESP8266 runs ESP8266 Basic.
Note 1: Using ESP8266 Basic is for the time being = awaiting for B4R to run on ESP8266 BUT it shows the integration between B4R and other languages.
Note 2: When using higher baud rates, then in cases characters are missing or changed.

Pin Wiring
ESP8266 --- Arduino
GND ------- GND
1 TX ------ 10 RX
3 RX ------ 11 TX

B4R 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
  'RX=10, TX=11
  softserial.Initialize(9600, 10, 11)
  astream.Initialize(softserial.Stream, "astream_newdata", Null)
  Timer1.Initialize("Timer1_Tick", 2000)
  Timer1.Enabled = True
End Sub

'Send a string to the ESP
Sub timer1_tick
   Dim str As String = "Hello"
End Sub

'Handle data received from the ESP
Sub astream_newdata (Buffer() As Byte)
   Log("NewData from ESP:",Buffer)
End Sub

ESP8266 Basic Code
'Set the connection
'serial2begin {baudrate},{TX_pin},{RX_pin}
serial2begin 9600, 1, 3

'Set the branch handling serial input
serial2branch [serial2in]

serial2input zz$
serial2println "ESP confirms:" & zz$

Logs (Note: in above code took out some log writing code)
Last edited: