... motivated by developing Software Solutions and share as Open Source
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).
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.
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.
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.
The B4J-Bridge is very useful when working with the Raspberry Pi.
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.
The B4J-Bridge Terminal screen, displays (logs) information, like
pi@raspberrypi ~/b4j $ sudo java -jar b4j-bridge.jar
Waiting for connections (port=6790)...
My IP address is: 192.168.0.23
The B4J Application jar file is stored in a temp folder on the Raspberry Pi.
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
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
iface eth0 inet dhcp
iface eth0 inet static
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
$git pull origin
Check if GPIO is working by $gpio -v
List all GPIOs by $gpio readall
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.
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).
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
Start the Pi, open a terminal session and login as user Pi.
First time: create folder /home/pi/b4j/tempjars (used by the B4J Bridge) ($cd /home/pi/b4j, $mkdir tempjars).
Copy the www folder from the development device to the Pi folder /home/pi/b4j/tempjars/www.
Start the B4J Bridge $sudo java -jar b4j-bridge.jar and note the My IP address (like 192.168.0.21).
From B4J IDE connect to the B4J-Bridge via menu Tools > B4J Bridge > Connect (using My IP address, check bottom left staes connect).
Build the B4J Application.
Start the application (F5), connect via Browser http://ipaddress:port like 192.168.0.21:51042 (check output on the Pi terminal).
Note: The folder /home/pi/b4j/tempjars lists a file called AsynInput1 which is the application.
Note: If updates made to files in the www folder, do not forget to copy those to the Pi prior testing.