Red LED and two buttons

miker2069

Active Member
Licensed User
Longtime User
There are very hard limits on what can be done in less than 2000 bytes of RAM.
There is no magic.

Regex is out of the question.
B4R will not use dynamic memory at all. I will post more information about this when B4R will be released. However it means that lists and maps will also won't be implemented, at least not in the first version.

well - that makes sense, I got a little carried away :)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Another small example. Using XBee for wireless communication between a PC and an Arduino:

SS-2016-04-07_12.07.51.jpg


The left adapter is connected to the PC. It can also be connected to an Android or Raspberry Pi, such as in this example: https://www.b4x.com/android/forum/threads/62564/#content
It is very simple to configure and the distance can be 100 meters+.
Writing to the serial causes the XBee to transmit the data and everything received by the XBee is sent to the serial input.

The B4R code:
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private astream As AsyncStreams
   Private leds(2) As Pin
End Sub

Private Sub AppStart
   Serial1.Initialize(9600)
   Log("AppStart")
   leds(0).Initialize(11, leds(0).MODE_OUTPUT)   
   leds(1).Initialize(12, leds(0).MODE_OUTPUT)   
   astream.Initialize(Serial1.Stream, "astream_NewData", "Astream_error")
End Sub

Sub Astream_NewData (Buffer() As Byte)
   For i = 0 To Buffer.Length - 1 Step 2
     Dim ledIndex As Byte = Buffer(0)
     Dim ledStatus As Boolean
     If Buffer(1) = 1 Then ledStatus = True Else ledStatus = False
     leds(ledIndex).DigitalWrite(ledStatus)
   Next
End Sub

Sub Astream_Error
   Log("Error")
End Sub

B4J code:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private serial As Serial
   Private astream As AsyncStreams
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.SetFormStyle("UNIFIED")
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   serial.Initialize("serial")
   serial.Open("COM33")
   astream.Initialize(serial.GetInputStream, serial.GetOutputStream, "Astream")
   MainForm.Show
End Sub


Sub ToggleButton_SelectedChange(Selected As Boolean)
   Dim v As Node = Sender
   Dim ledIndex As Byte = v.Tag
   Dim ledStatus As Byte
   If Selected Then ledStatus = 1 Else ledStatus = 0
   astream.Write(Array As Byte(ledIndex, ledStatus))
End Sub
 

canalrun

Well-Known Member
Licensed User
Longtime User
I would love to see Z-Wave also.

There are Arduino plug-in modules that handle the radio frequency Z-Wave communication, but as far as I know they lack the software that handles the Z-Wave protocol.

Being able to use B4R to write code for the Arduino using a Z-Wave module and protocol software would allow one to develop a custom, fairly complex solution to use in Home Automation or IoT. You could create a device that integrates into the Z-Wave controller and performs a custom sensor or control function.

This would be neat!

Barry.
 

Toley

Active Member
Licensed User
Longtime User
I would love to see Z-Wave also.

There are Arduino plug-in modules that handle the radio frequency Z-Wave communication, but as far as I know they lack the software that handles the Z-Wave protocol.

Being able to use B4R to write code for the Arduino using a Z-Wave module and protocol software would allow one to develop a custom, fairly complex solution to use in Home Automation or IoT. You could create a device that integrates into the Z-Wave controller and performs a custom sensor or control function.

This would be neat!

Barry.
Erel has already stated that not all native Arduino libraries will be available at first release. But libraries can be wrapped by him or any user after.
If no Arduino library exist, then it will not be possible. It's important to understand that B4R will not be a compiler by itself. The basic program will be translated to C/C++ and then send to the Arduino(GCC) compiler.

BTW I think that using MQTT on a local WI-FI network based on ESP-8266 clients and a B4A/B4J Broker will be the best solution for IOT and home automation. And I have the feeling it's already spinning into Erel's mind.
 
Last edited:

mterveen

Member
Licensed User
Longtime User
Another small example. Using XBee for wireless communication between a PC and an Arduino:

SS-2016-04-07_12.07.51.jpg


The left adapter is connected to the PC. It can also be connected to an Android or Raspberry Pi, such as in this example: https://www.b4x.com/android/forum/threads/62564/#content
It is very simple to configure and the distance can be 100 meters+.
Writing to the serial causes the XBee to transmit the data and everything received by the XBee is sent to the serial input.

The B4R code:
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private astream As AsyncStreams
   Private leds(2) As Pin
End Sub

Private Sub AppStart
   Serial1.Initialize(9600)
   Log("AppStart")
   leds(0).Initialize(11, leds(0).MODE_OUTPUT) 
   leds(1).Initialize(12, leds(0).MODE_OUTPUT) 
   astream.Initialize(Serial1.Stream, "astream_NewData", "Astream_error")
End Sub

Sub Astream_NewData (Buffer() As Byte)
   For i = 0 To Buffer.Length - 1 Step 2
     Dim ledIndex As Byte = Buffer(0)
     Dim ledStatus As Boolean
     If Buffer(1) = 1 Then ledStatus = True Else ledStatus = False
     leds(ledIndex).DigitalWrite(ledStatus)
   Next
End Sub

Sub Astream_Error
   Log("Error")
End Sub

B4J code:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private serial As Serial
   Private astream As AsyncStreams
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.SetFormStyle("UNIFIED")
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   serial.Initialize("serial")
   serial.Open("COM33")
   astream.Initialize(serial.GetInputStream, serial.GetOutputStream, "Astream")
   MainForm.Show
End Sub


Sub ToggleButton_SelectedChange(Selected As Boolean)
   Dim v As Node = Sender
   Dim ledIndex As Byte = v.Tag
   Dim ledStatus As Byte
   If Selected Then ledStatus = 1 Else ledStatus = 0
   astream.Write(Array As Byte(ledIndex, ledStatus))
End Sub
Another small example. Using XBee for wireless communication between a PC and an Arduino:

SS-2016-04-07_12.07.51.jpg


The left adapter is connected to the PC. It can also be connected to an Android or Raspberry Pi, such as in this example: https://www.b4x.com/android/forum/threads/62564/#content
It is very simple to configure and the distance can be 100 meters+.
Writing to the serial causes the XBee to transmit the data and everything received by the XBee is sent to the serial input.

The B4R code:
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private astream As AsyncStreams
   Private leds(2) As Pin
End Sub

Private Sub AppStart
   Serial1.Initialize(9600)
   Log("AppStart")
   leds(0).Initialize(11, leds(0).MODE_OUTPUT)  
   leds(1).Initialize(12, leds(0).MODE_OUTPUT)  
   astream.Initialize(Serial1.Stream, "astream_NewData", "Astream_error")
End Sub

Sub Astream_NewData (Buffer() As Byte)
   For i = 0 To Buffer.Length - 1 Step 2
     Dim ledIndex As Byte = Buffer(0)
     Dim ledStatus As Boolean
     If Buffer(1) = 1 Then ledStatus = True Else ledStatus = False
     leds(ledIndex).DigitalWrite(ledStatus)
   Next
End Sub

Sub Astream_Error
   Log("Error")
End Sub

B4J code:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private serial As Serial
   Private astream As AsyncStreams
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.SetFormStyle("UNIFIED")
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   serial.Initialize("serial")
   serial.Open("COM33")
   astream.Initialize(serial.GetInputStream, serial.GetOutputStream, "Astream")
   MainForm.Show
End Sub


Sub ToggleButton_SelectedChange(Selected As Boolean)
   Dim v As Node = Sender
   Dim ledIndex As Byte = v.Tag
   Dim ledStatus As Byte
   If Selected Then ledStatus = 1 Else ledStatus = 0
   astream.Write(Array As Byte(ledIndex, ledStatus))
End Sub

Will b4r create a regular .ino file that could be separately edited using the arduino ide?
 

tufanv

Expert
Licensed User
Longtime User
what i do not understand is buying a xbee gives us opportunity to have wireless connection or do we have to buy another things for it ?
 

Cableguy

Expert
Licensed User
Longtime User
The XBee modules are RF-Tranceivers, that, thou working in a Major free Radio Freq (2.4GHz), are meant to communicate with other XBee's only.
They do not alow us to connect to any other Wi-Fi network... BUT they allow for a 1 to Several xBee's modules.

There are several serial RF Transceiver modules, working in several free Radio Frequencies, like 433KHz.
 

KY Leng

Member
Licensed User
Longtime User
I support Erel for B4R. However, if possible, let the user to configure the pin by them self for a custom made board.
 
Top