Robs Homepage ... motivated by developing Software Solutions and share as Open Source

Purpose
The Experiments show how to develop simple solutions running on the Raspberry Pi.
Various hardware components are used, like LEDs, switches and sensors.
Each software solution runs as a server application on the Pi. The software is developed using B4J.
Access the server application via a browser using URL http://ipaddress:port (like http://192.168.0.57:51042).

Requirements
An up-and-running Pi and a B4J Development environment.
On the Pi, Java must be installed. Check out by running $java -version from the command line. The newest Raspberry Pi NOOBS should have Java pre-installed.
For the solutions usign the Pi GPIO, a T-Cobbler connected to a breadboard is used.

Application Structure
Each application has a B4J project file (.b4j), a Websocket Class (.bas) and additional classes (.bas) or code helpers (like webutils.bas).
B4J generates a the application a Java JAR file.
Some of the applications run also on other environments (Windows etc.).
The application is accessed via an HTML file (index.html) stored in the www folder (projectfolder/objects/www). The B4J WebSockets client library b4j_ws.js is also required.
This means a typical application has following files: project.b4j, projectwebsocket.bas, webutils.bas, objects/www/index.html, objects/www/b4j_ws.js.
Of course, depending on the project additionals files are used.
For the solutions using the Pi GPIO, the jPi4J Libary (Raspberry Pi GPIO controller) is required.

Development Tools used
  • B4J on Windows.
  • PuTTY is a free implementation of Telnet and SSH for Windows and Unix platforms, along with an xterm terminal emulator.
  • WinSCP Free SFTP, SCP and FTP client for Windows
  • Remote Desktop xrdp
  • Install on RPi: $sudo apt-get install xrdp, No further setup required. Note: Ensure SSH on the RPi is turned on (use $sudo raspi-config, select advanced options SSH). Install on Windows: No installation required as using the standard Windows Programm Remote Desktop.

B4J-Bridge
The B4J-Bridge is very useful when working with the Raspberry Pi.

Install

Create a folder /home/pi/b4j and move to this new folder
Download the B4J Bridge to the Pi by either running command:
$wget http://www.b4x.com/b4j/files/b4j-bridge.jar OR copy the b4j_bridge.jar from the Development Device to the Pi in folder /home/pi/b4j.
To run the B4J Bridge as root when logged in as user Pi:
$sudo -jar b4j-bridge.jar
If the path to java is set, then call direct $sudo java -jar b4j-bridge.
It is useful to run the B4J-Bridge from a dedicated terminal, like f.e. from the development device using Putty.
When doing so, the output of the running application can be watched.

Logging

The B4J-Bridge Terminal screen, displays (logs) information, like
pi@raspberrypi ~/b4j $ sudo java -jar b4j-bridge.jar
B4J-Bridge v1.00
Waiting for connections (port=6790)...
My IP address is: 192.168.0.23
Connected!
Starting program
ProcessCompleted
Starting program

Temp File

The B4J Application jar file is stored in a temp folder on the Raspberry Pi.
Example: \home\pi\b4j\tempjars\AsyncInput2.
Hint: When testing various B4J apps, ensure to cleanup this folder from time-to-time.

Keep the Pi current
Login as User Pi and regular run
  • $sudo apt-get update && sudo apt-get upgrade
  • $sudo apt-get autoremove
  • $sudo rpi-update
  • $sudo reboot

Give the Pi a fix IP address
Login as User Pi
Obtain Gateway Address by invoking command $netstat -r -n
Set fix ip address by editing the interfaces file:
$sudo nano /etc/network/interfaces
Replace
iface eth0 inet dhcp
By
iface eth0 inet static
address 192.168.nnn.nnn
netmask 255.255.255.0
gateway 192.168.nnn.nnn

Wiring Pi Libary
WiringPi is a GPIO access library written in C for the BCM2835 used in the Raspberry Pi.
Go here for information about installing wiringPi, but in a nutshell:
  • $sudo apt-get update
  • $sudo apt-get upgrade
  • $sudo apt-get install git-core
  • $git clone git://git.drogon.net/wiringPi
  • $cd wiringPi
  • $git pull origin
  • $./build
  • Check if GPIO is working by $gpio -v
  • List all GPIOs by $gpio readall

  • Pi4J Libary

    The Pi4J is a object-oriented I/O API and implementation libraries for Java Programmers to access the full I/O capabilities of the Raspberry Pi platform.
    Information about the Pi4J Library and learn the Pi4J API.
    Raspberry Pi GPIO Pin Wiring
    Find the Mapping of the GPIO Pins to WiringPi.
    Note that the Pin numbering could be confusing. Look closely at the mapping.
    Another good overview, is to run on the Raspberry Pi the command $gpio readall.
    Example: A LED is connected to the Raspberry Pi GPIO Physical Pin number 12 = BCM 18 = wPi 1 = Name GPIO.1.
    For usage with B4J, Pin GPIO.1 = wPi Pin1 = Pin1 used in the example below.
    B4J Setup
    A wrapper, jPi4J, is available for the Pi4J Library. Summary of the Libraries required. In the B4J additional library folder, following files should be listed:
    jPi4J.jar, jPi4J.xml,pi4j-core.jar, pi4j-device.jar, pi4j-gpio-extension.jar
    IMPORTANT ON UPDATES
    As the Raspberry Pi is being developed further, ensure to use the latest Pi4J Library files. Download the latest jar files from http://pi4j.com/download.html#Direct_Download to the PC. Copy following jar files to the B4J additional library folder: pi4j-core, pi4j-device, pi4j-gpio-extension
    A new jPi4J library is not required. Use the one provided in jpi4j.zip (see link above). Ensure
    • the jPi4J.jar and jPi4J.xml are stored in the B4J additional library folder
    • the jPi4J library is selected in the B4J IDE (Libs Tab)
    Information about the Pin Numbering using wiringPi can be found here.

Quickstart building Pi B4J server app and run
Using the B4J Bridge