Code Monkey home page Code Monkey logo

pi4j-example-crowpi's Introduction

Pi4J V2 :: CrowPi Examples

Code Build Status Docs Build Status Contributors License

This project contains both example applications and ready-made component classes for interacting with the CrowPi using the Pi4J (V2) library. You can easily get started with electronics programming by testing and modifying the bundled examples or even write your own application.

COMPONENTS

The provided component classes as part of this library provide an implementation for every available component of the CrowPi. The following table provides an overview of all supported components with a link to their implementation and example app:

Component Example App Implementation
Button ButtonApp.java ButtonComponent.java
ButtonMatrix ButtonMatrixApp.java ButtonMatrixComponent.java
Buzzer BuzzerApp.java BuzzerComponent.java
Humidity/Temperature Sensor HumiTempApp.java HumiTempComponent.java
IR Receiver IrReceiverApp.java IrReceiverComponent.java
LCD Display LcdDisplayApp.java LCDDisplayComponent.java
LED Matrix LedMatrixApp.java LedMatrixComponent.java
Light Sensor LightSensorApp.java LightSensorComponent.java
PIR Motion Sensor PirMotionSensorApp.java PirMotionSensorComponent.java
Relay RelayApp.java RelayComponent.java
RFID RfidApp.java RfidComponent.java
Servo Motor ServoMotorApp.java ServoMotorComponent.java
Seven Segment Display SevenSegmentApp.java SevenSegmentComponent.java
Step Motor StepMotorApp.java StepMotorComponent.java
Tilt Sensor TiltSensorApp.java TiltSensorComponent.java
Touch Sensor TouchSensorApp.java TouchSensorComponent.java
Ultrasonic Distance Sensor UltrasonicDistanceSensorApp.java UltrasonicDistanceSensorComponent.java
Vibration Motor VibrationMotorApp.java VibrationMotorComponent.java

Due to very tight timing constraints, two of the components had to use an alternative implementation without relying on Java. This could be improved in the future by moving this logic into native code using JNI or putting these components behind a dedicated microcontroller:

  • IR Receiver: This component relies on the mode2 binary for retrieving the signal pulses, provided as part of the LIRC software bundle. While all parsing and logic has been implemented in Java, measuring the pulses accurately enough was not possible.
  • Humidity/Temperature Sensor: Due to being based on a DHT11 sensor, this component requires an extreme amount of precision in terms of timing, resulting in measurement failures even when running as native code on a Raspberry Pi. To still provide some support for this component, it requires setting up the dht11 kernel module which is part of Linux Industrial I/O.

The CrowPi OS image mentioned further down below supports both workarounds out of the box without further configuration.

CUSTOM OS IMAGE

The Pi4J-team provides several pre-built custom OS images. It's highly recommended to use the so called Pi4J CrowPi OS for your CrowPi experiments to get the following set of benefits:

  • Preconfigured locale (en_US), keyboard (US) and timezone (Europe/Zurich)
  • Preconfigured wireless country (Switzerland) by default
  • Remote management via SSH and VNC possible without configuration
  • Preinstalled OpenJDK 17 and JavaFX to get quickly started
  • Preconfigured /boot/config.txt which supports all components out of the box
  • Dynamic wallpaper which shows Ethernet/WLAN address and hostname
  • Comes with lirc preinstalled to run the IR receiver component

Prepare CrowPi

  • download the latest Pi4J-CrowPi-OS image
  • extract the ZIP File
  • Use Raspberry Pi Imager
    • Specify a new user pi with password pi4j in preferences of Imager.
    • Write the image to an SD-Card.
  • Start the CrowPi with this SD-Card.

FRAMEWORK

To simplify adding and launching new applications, a custom launcher has been built using PicoCLI. The Launcher.java class contains a static list of available targets called APPLICATIONS which has to be adjusted when adding new applications to the project.

By default, an interactive menu gets shown which allows selecting a single target to launch. After executing this target, the application will automatically end. You may optionally specify the name of an application as the first argument, i.e. BuzzerApp, to directly launch this specific application.

If you want to comfortably test all supported components at once, you may specify the flag --demo which will return to the interactive launcher menu once a target has been executed.

Creating your own applications is as simple as implementing the provided Application.java interface, which only requires a single void execute(Context pi4j) method.

BUILD SYSTEM

This project uses Maven for building, testing and running the various applications. While it can be used directly on a Raspberry Pi / CrowPi, it's recommended to use a separate developer machine and deploy the artifacts to the CrowPi and running them remotely. The following set of Maven properties can be set for remote deployments:

  • crowpi.hostname : Hostname of the CrowPi, defaults to crowpi is displayed as part of the wallpaper if you use Pi4J-CrowPi-OS Image
  • crowpi.ipnumber : Current IP address of the CrowPi, e.g. 192.168.1.2, used for SCP/SSH, also shown as part of the wallpaper
  • crowpi.port: Port to use for SCP/SSH communication, defaults to 22
  • crowpi.username : Username to use for SCP/SSH, defaults to pi
  • crowpi.password : Password to use for SCP/SSH, defaults to pi4j
  • crowpi.deploydirectory : Default directory to temporarily store built artifacts, defaults to /home/pi/deploy
  • crowpi.jvmOptions : Additional JVM options, defaults to an empty string

In case of a remote deployment, the artifacts get pushed via SCP and will be automatically executed using SSH. Please note that any existing files in the deployment folder are being automatically overwritten.

Regardless of which deployment mode you have chosen, the property launcher.args can be set to specify which arguments should be passed as-is when running the launcher. This can be used for launching demo mode or directly executing a single application.

SYSTEM REQUIREMENTS

You may skip this section when using the pre-built Pi4J-CrowPi-OS image.

Should you choose to run your own image instead, you will need to ensure that the following lines are present in your /boot/config.txt:

[all]
# Enable X with 128MB GPU memory and support the custom resolution of the CrowPi LCD panel
start_x = 1
gpu_mem = 128
hdmi_cvt 1024 600 60 6 0 0 0

# Enable I2C and SPI
dtparam = i2c_arm=on
dtparam = spi=on

# Enable audio
dtparam = audio=on

# Enable GPIO-IR
dtoverlay = gpio-ir,gpio_pin=20

# Enable DHT11
dtoverlay = dht11,gpiopin=4

# Enable DRM VC4 V3D with up to 2 frame buffers
dtoverlay = vc4-fkms-v3d
max_framebuffers = 2

If you want to use the IR receiver and/or humidity/temperature sensor component, you will have to ensure that the required dependencies mentioned in the "COMPONENTS" section of this README have also been fulfilled.

RUNTIME DEPENDENCIES

This project has the following runtime dependency requirements:

BUILD AND RUN ON RASPBERRY PI

Although not recommended, you can build and run this project on your CrowPi without using a separate developer machine.

$ git clone https://github.com/Pi4J/pi4j-example-crowpi.git
$ cd pi4j-example-crowpi
$ mvn package
$ cd target/distribution/
$ sudo java --module-path . --module com.pi4j.crowpi/com.pi4j.crowpi.Launcher $@

> No application has been specified, defaulting to interactive selection
> Run this launcher with --help for further information
[main] INFO com.pi4j.Pi4J - New context builder
[main] INFO com.pi4j.platform.impl.DefaultRuntimePlatforms - adding platform to managed platform map [id=raspberrypi; name=RaspberryPi Platform; priority=5; class=com.pi4j.crowpi.helpers.CrowPiPlatform]
> The following launch targets are available:
1) Exit launcher without running application
2) ButtonApp (com.pi4j.crowpi.applications.ButtonApp)
3) ButtonMatrixApp (com.pi4j.crowpi.applications.ButtonMatrixApp)
4) BuzzerApp (com.pi4j.crowpi.applications.BuzzerApp)
5) ExampleApp (com.pi4j.crowpi.applications.ExampleApp)
6) HumiTempApp (com.pi4j.crowpi.applications.HumiTempApp)
7) IrReceiverApp (com.pi4j.crowpi.applications.IrReceiverApp)
8) LcdDisplayApp (com.pi4j.crowpi.applications.LcdDisplayApp)
9) LedMatrixApp (com.pi4j.crowpi.applications.LedMatrixApp)
10) LightSensorApp (com.pi4j.crowpi.applications.LightSensorApp)
11) RfidApp (com.pi4j.crowpi.applications.RfidApp)
12) PirMotionSensorApp (com.pi4j.crowpi.applications.PirMotionSensorApp)
13) RelayApp (com.pi4j.crowpi.applications.RelayApp)
14) ServoMotorApp (com.pi4j.crowpi.applications.ServoMotorApp)
15) SevenSegmentApp (com.pi4j.crowpi.applications.SevenSegmentApp)
16) SoundSensorApp (com.pi4j.crowpi.applications.SoundSensorApp)
17) StepMotorApp (com.pi4j.crowpi.applications.StepMotorApp)
18) TiltSensorApp (com.pi4j.crowpi.applications.TiltSensorApp)
19) TouchSensorApp (com.pi4j.crowpi.applications.TouchSensorApp)
20) UltrasonicDistanceSensorApp (com.pi4j.crowpi.applications.UltrasonicDistanceSensorApp)
21) VibrationMotorApp (com.pi4j.crowpi.applications.VibrationMotorApp)
> Please choose your desired launch target by typing its number:

LICENSE

This repository is licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

pi4j-example-crowpi's People

Contributors

dieterholz avatar eitch avatar fdelporte avatar ppmathis avatar tobiassiegrist avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pi4j-example-crowpi's Issues

Create new LauncherFX

The idea of this launcher would be to create buttons to perform the same actions which is already available in the normal Launcher class

Running multiple examples causes errors

When multiple people run an example from their system, then initialization of the pigpio library can fail, if the JVM which initialized the library is still running.

We should have a semaphore to check that only one JVM at a time can initialize the pigpio library, i.e. only instance of the example app is running at the same time.

Switch to AsciiDoc

ToDo
Students at FHNW are supposed to use AsciiDoc for documentation.

CrowPi examples should go ahead in this area as well.

Done

  • README is available as AsciiDoc document

Concrete implementation of SLF4J to write to file instead of console

Hi all,

I am trying to get the SLF4J Log to be written to file with no success in the given example Applications. Does anyone have an example implementation for SLF4J in the Pi4J project where logs are written to file (i.e xxx.log) instead of console? also where are the properties of such implementation described? in the POM file? or somewhere else?

Any guidelines would is highly appreciated.

Best regards

Provide minimal JavaFX example

ToDo
With CrowPi we have everything we need to show how to integrate JavaFX and Pi4J.

The minimal example should introduce the concept of Physical User Interface (PUI) and how to combine it with a GUI (G/PUI) via PresentationModel

For example

GUI
TextField, Button, Label

PUI
LCD, TouchSensor, DistanceSensor

pom.xml must be updated for JavaFX usage

Done

  • at least one CodeReview
  • consensus that it is a "good solution" and shows a example how to build G/PUIs
  • app can be started from IDE in X11-Mode and DRM
  • README mentions the JavaFX application

Remove image directory

Todo
Generation of CrowPi image has been moved to separate repository.

It can be removed here

Done

  • all image related artifacts are removed
  • documentation updated and refers to new repository for image generation, especially README is updated

Not able to get Servo to work

I am trying to move my servo on BCM PIN 25. I have a Spring Boot REST webapp and when submitting an angle, the servo doesnt move.

I have initialized the PI4J Context and passed into the ServoComponent, and added a new constructor for flexibility on changing the PIN value.

I have my servo connected to a power supply and rPi GND PIN to the GND of the Power Supply.
Using java 17.

Build Fail

I had the same problem in my project, which has many changes, But I see that the same problem exists on Pi with everything standard as described in the repo main(No changes were made):

Is the upgrade to 17 being tested on the latest image for CrowPi?

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 49.152 s
[INFO] Finished at: 2022-09-18T16:41:08+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project crowpi-examples: Fatal error compiling: error: release version 17 not supported -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.