B4R Tutorials

Connecting two Arduinos with rSoftwareSerial library

SS-2016-04-13_15.50.49.png


With the rSoftwareSerial library you can turn regular pins to serial ports. This is useful as the hardware serial is used...
 

Attachments

  • rSoftwareSerial.zip
    1.7 KB · Views: 1,429

BLE (HM-10 module) - Broadcasting a single byte

SS-2016-04-13_17.54.33.jpg


In this example I'm using a BLE shield to broadcast the state of a connected button.

The byte is sent as part of...
 

Attachments

  • B4A_BLE_ButtonState.zip
    7.9 KB · Views: 1,258
  • B4i_BLE_ButtonState.zip
    2.9 KB · Views: 756

Ultrasonic Ranging module HC-SR04

Testing the HC-SR04 to measuring distances

ultrasonic_sensor_schema.jpg

physics info.png

The accuraccy of the sensor depends greatly on...
 
Last edited by a moderator:

Arduino + Raspberry Pi

SS-2016-04-14_14.54.06.jpg


In this tutorial we will create a currency converter solution that shows the conversion from USD to other currencies on...
 

Attachments

  • B4J_CurrencyConverter.zip
    1.5 KB · Views: 899
Last edited:

Connecting to Arduino with BLE (Bluetooth Low Energy)

Attachments

  • B4i_BLE.zip
    3.1 KB · Views: 1,194
  • B4A_BLE.zip
    8.5 KB · Views: 2,017
Last edited:

Stepper motor

Edit: see post #5 for an updated version.

This application is controlling a stepper motor which can be turned by a wanted angle and speed. I use this motor...
 
Last edited:

Analog Read Example using XBee Mesh Network

Attachments

  • B4RHowToTMP36XBee.zip
    4 KB · Views: 498

Inertial Measurements (MPU 6050) and Magnetometer (HMC5883L)

With big help from Erel here are two examples of connecting two boards by the I2C/TWI (A4 and A5 pins), using the rWire library.
Inertial Measurements (mpu6050) :
B4X:
' MPU 6050 board - Inertial...
 
Last edited:

Timers, Loopers and CallSubPlus

Arduino C example #1:
B4X:
void setup() {
  pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the...
 
Last edited:

SD cards

The rSD library allows reading and writing to SD cards. The Ethernet shield as well as other shields include a SD slot.

The steps required to work with files:
1. Initialize a SD object. You need...
 

Attachments

  • B4J_PrepareCurrencyFile.zip
    2.8 KB · Views: 943
  • SD_Example.zip
    1.1 KB · Views: 1,167

RGB Leds

RGB Leds are equivalent to three leds (red, green and blue) combined. This allows mixing the three colors which results in many different colors.

There are two types of RGB leds: common cathode...
 
Last edited:

Controlling an RGB Led from the PC

Attachments

  • B4J_ColorPicker.zip
    4 KB · Views: 696

Servo motor and Arduino

Thanks to @Erel and the new rservo library (Beta#7), we've access to servo motors.

Servos are a motor type that allows for precise control of angular or linear position, velocity and...
 
Last edited:

DHT11 & DHT22 temperature and humidity sensors ARDUINO UNO Code

This B4R example/library works with DHT11 and DHT22 temperature and humidity sensors:

This inexpensive device (DHT11) allows for measure temperature and humidity:
  • Very Low cost
  • 3...
 

Attachments

  • upload_2016-4-22_12-12-25.png
    upload_2016-4-22_12-12-25.png
    11.7 KB · Views: 1,310
  • DHTlib.zip
    10.1 KB · Views: 1,305
  • rDHTv2.zip
    1.2 KB · Views: 1,114
Last edited:

tone() function

Here is a tone function that does Arduino's tone()
The buzzer is connected between pin 6 and ground :
B4X:
Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    Delay( 1000)...
 
Last edited:

UDP Communication

rEthernet library v1.10 (included in v1.00 beta 9) includes a new type named EthernetUDP. It allows sending and receiving UDP packets.

UDP is simple to work with as it is a connection-less...
 

Attachments

  • B4A_UDP.zip
    8.1 KB · Views: 1,432

HC 05 Classic Bluetooth

SS-2016-05-08_17.39.25.jpg


SS-2016-05-08_17.39.57.png


In this example we will connect an Android...
 

Attachments

  • Adruino_Bluetooth_B4A.zip
    9.7 KB · Views: 2,648
Last edited:

Strings and Bytes

B4R strings are different than in other B4X tools. The reasons for these differences are:
1. Very limited memory.
2. Lack of Unicode encoders.

A String object in B4R is the same as C char*...
 
Last edited:

GSM / GPRS - Control the Arduino with SMS messages

SS-2016-05-11_13.27.00.jpg


The GSM shield allows the Arduino to connect to cellular networks. This opens the door for many interesting outdoor...
 

Attachments

  • GSM_Example.zip
    2.3 KB · Views: 1,473
Last edited:

B4A, B4i, B4J and B4r API documentation - B4X Object Browser

Top