B4R Tutorials

Blink Example

A simple example that uses a Timer to change the state of pin 13 (this is the pin connected to the built-in led):
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private Timer1 As Timer...
 

Button Example

SS-2016-04-11_11.44.41.png


B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private btn As Pin
   Private led As Pin
End Sub

Private Sub...
 

Traffic Light Example

Example of implementing a "traffic light" with 3 leds. There are four states: red, red + yellow, green and yellow.

It uses CallSubPlus to switch to the next state after the current state...
 

Ethernet / Network Tutorial

This example uses an Ethernet shield to connect to a server. In this case the server is implemented with B4J, though you can easily implement a similar server with B4A or B4i.

Whenever the user...
 

Attachments

  • EthernetExample.zip
    1.2 KB · Views: 1,175
Last edited:

Data types

The following data types are available in B4R:

Numeric types:

Byte: 0 - 255
Int (2 bytes): -32768 - 32768. Similar to Short type in other B4X tools.
UInt (2 bytes): 0 - 65535.
Long (4 bytes)...
 

MQTT

Memory, Variables and Objects

Memory is a big issue in Arduino.

1. The available RAM is very small compared to other platforms. For example the Uno has 2k of RAM.
2. There is no sophisticated heap management which means that...
 
Last edited:

B4R PIR (Passive Infrared Sensor) Example

Thanks to Erel for this great product !! (again)

Here's a PIR example (presence detection) with Arduino and B4R; the PIR sensor is the PIR HC-SR501...
 

Analog Read Example

Hi,

a simple analog read example which reads the temperature from sensor TMP36 and logs the result.
B4X:
Sub Process_Globals
    Public Serial1 As Serial
    Private TempSensorPin As Pin...
 

Show-Off your IoT boards ( uControler/shields )!!

There seem to be quite a few variants of the Arduino's Boards, So I thought, let's Show-Off our Boards and create a Listing, similar to the B4A devices Listing, so that when problems arises, we...
 

B4RHelp program

I've hacked my already hacky B4AHelp program to give tidier results when looking at B4R Xml files.

EDIT: Updated to v1.1 to overcome a change in the Xml format that I just noticed.
 

Attachments

  • B4RHelp1.1.zip
    75.8 KB · Views: 503
Last edited:

Writing and reading from the EEPROM

The EEPROM is in most cases the only persistent storage available. As a persistent storage we can use it to store data that will not be lost when the board is turned off.

The rEEPROM library...
 

Analog Read Example using Ethernet

Hi,

based on previous Analog Read Example extended the solution by using the Arduino Ethernet Shield to send temperature data to B4J server and receive confirmation.
Full project (with...
 

Attachments

  • B4RHowToTMP36Ethernet.zip
    4.6 KB · Views: 517

Inline C / C++

As in the other B4X tools you can embed C or C++ code in the project.

Example:
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private Result, N1, N2 As Int 'ignore
End Sub

Private Sub...
 

Analog Read Example using MQTT

Attachments

  • B4RHowToTMP36MQTT.zip
    4.5 KB · Views: 588
Last edited:

Creating libraries for B4R

Libraries are written in C++.
Libraries are made of a single h file and one or more cpp files. Libraries can also include other h files which will not be exposed.

All the files should be in the...
 

Attachments

  • B4Rh2xml.jar
    98 KB · Views: 1,367
Last edited:

[tool] External Serial Connector

SS-2016-04-12_15.23.57.png


This is a small B4J program that uses jSerial library to connect to an Arduino board.

To see it working start with this...
 

Attachments

  • B4R_Serial_Connector.zip
    7.2 KB · Views: 1,306
Last edited:

LCD Clock example

Arduino Uno with LCD shield:

SS-2016-04-12_15.47.51.jpg


Working with a LCD monitor:
1. Initialize the LiquidCrystal object and set the connected...
 

Attachments

  • B4J_SerialConnector.zip
    4.1 KB · Views: 850
  • B4R_LCD.zip
    987 bytes · Views: 1,030

Analog Read Example using LCD

Attachments

  • B4RHowToTMP36LCD.zip
    1.8 KB · Views: 603

Connecting two Arduinos with rWire library

SS-2016-04-12_16.46.55.png


The rWire supports communication with other I2C/TWI devices.

One device acts as the master and the other devices act as...
 
Top