Code Monkey home page Code Monkey logo

pi4_java_relay_control's Introduction

About

This Java project enables the user to control relays via a graphical user intreface and have the state of the relays displayed. It is meant to be used on the Raspberry Pi 4, which is an SBC (Single Board Computer) made by the Raspberry Pi Foundation, based in England, Cambridge.

Setup

1. Necessary hardware

  • Raspberry Pi 4
  • Micro SD card, minimally 16Gb
  • Another computer to write the system image on the Micro SD card.
  • Power supply (5V, 3A - for Pi 4)
  • Monitor, keyboard, mouse
  • Waveshare 8 Channel Relay Expansion Board

2. Installing the OS

You can download the image yourself from the web and use any popular software (such as Win32DiskImager, Rufus, Balena Etcher, etc) to write it to the SD card. Or, you can use the official Pi Imager and you also have the possibility of setting up thigs such as WiFi, SSH, main user account right before starting. This is useful in case you need a fast deployment of your Pi and have no monitor at a moment's notice.

image
Source: https://www.raspberrypi.com/software/

In this project's case, make sure you are not running a headless version (that means not having any desktop environment installed).

2.1 Useful reads before moving to the next steps

3. Java

The most recent build of the RPi OS should already come wtih a Java Run-Time Environment preinstalled, make sure you have it installed by chekcing the version:

java -version

4. Make sure your system and apps are up to date

sudo apt update
sudo apt full-upgrade

5. Installating libraries

The main library we will need in order for this project to work is pi4j which is a "friendly object-oriented I/O API and implementation libraries for Java Programmers to access the full I/O capabilities of the Raspberry Pi platform".

pi4j-overview
Source: https://pi4j.com/

We have one dependecny to take care of which is WiringPi (it is a PIN based GPIO access library written in C). It should be preinstalled with the RPi OS, but if for whatever reason it is not, we use the following command to install it:

sudo apt-get install wiringpi

Installing pi4j:

curl -sSL https://pi4j.com/install | sudo bash
sudo apt-get install pi4j
sudo pi4j --update

6. Setting up the hardware

In case you want to connect remotely to the Pi and have some useful info on a physical display then the PiOled is a great addition. It requires Python, the pip manager and a package made by Adafruit.

image
Source: https://www.adafruit.com/product/3527

  • Install the OLED Package
sudo apt-get install python3-pip
sudo pip3 install adafruit-circuitpython-ssd1306
  • Enable I2C bus from the Configuration tab
  • Reboot
  • Check for the OLED on the I2C bus
sudo i2cdetect -y 1
  • To make the script from the package to run on startup:
sudo nano /etc/rc.local
  • Then add the line
sudo python3 /{folder_where_you_saved_the_script}/stats.py &
  • After setting up the Pi insert it into the Waveshare Relay Board and secure it with the included screws

  • Connect the power pins of the relay board to a regulated 5V 3A PSU (or the official USB C 5V 3A Pi power brick)

  • If you have only a 12V power supply at hand make sure to use a step down converter such as the LM2596 (supports 3A) to bring it down to 5V.

image

7. Using the app

  1. Open the terminal

  2. Compile the source in the direcory where you downloaded the file. This will create relay_GUI.class

javac relay_GUI.java
  1. Run the app with:
java relay_GUI
  1. All relays are off by default, turn them on by clicking the buttons, the state is displayed on the button. image IMG_0109

pi4_java_relay_control's People

Contributors

hansjohrend avatar

Watchers

 avatar

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.