What is Raspberry PI
Raspberry PI was developed for low cost and to teach students about computers. But today, it can also be used for personal and daily use. You can create circuits and projects on it. It is an embedded Linux system that becomes more powerful with new versions.
You can build your own circuits on it, create servers and work on image processing. Raspberry takes its name from the name of the fruit and PI comes from Python, which belongs to RPI and also refers to the number PI.
As seen in Figure 1, Raspberry PI model 4b has 4 USB ports, 1 Gigabit internet port and 2 HDMI converter ports.
Raspberry PI as an Embedded System
Embedded systems can be defined as a combination of hardware and software such as memory, IO and CPU. Raspberry PI is a mini computer that can fit in our hands and we can think of it as an embedded system. A system can be obtained by combining hardware, and software is required for this system to perform certain functions. The software contains the commands for the hardware to perform its function, and the commands are converted into the language that the machine understands, that is, 0s and 1s. Instructions are executed on the processor. This logic also works in embedded systems, and we can write software containing commands and manage hardware on Raspberry PI.
Installing Apache Server on Raspberry PI
The application was made on a 4GB version of the Raspberry PI 4B model. There is an SD card slot on it. A 32GB SD card was used as storage.
In order to make any development, a Linux system must be installed. First of all, we make the SD card bootable. Operating system is a system software. Thanks to this software, we can manage the hardware. In addition, the operating system is a software and we can produce and run software through this software.
Linux-based Raspberry PI OS was installed on this computer. This operating system offers us GUI and you can also use the terminal so you can benefit from the services of the operating system.
After downloading the software here, it can be used with a laptop or another computer with SD card reader feature. With this program, you can easily install the operating system by choosing an operating system on your SD card. To get information about installation and more, you can visit their website [9].
You can use Raspberry PI on a display that supports HDMI. For this, you can connect your HDMI converter cable to the micro HDMI port to the monitor.
In the picture in Figure 5, 2 USBs were used for the keyboard and mouse and were powered by a power adapter. Raspberry PI is ready for use with a bootable SD card.
In Figure 6, you can go to the configuration settings and make keyboard settings and activate the SSH option. You can also access your computer’s command line remotely via SSH.
In Figure 8, we opened the terminal software and will operate on the command line. First of all, we can get the current version of our packages and new versions with update, and we can move the packages we have to the latest version with upgrade. If yes or no questions come up during the process and you want the default to be yes, you can add the -y argument.
You can easily install the Apache web server by entering the sudo apt-get install apache2 command.
You can find out whether the web server is active or not with sudo systemctl status apache2 command.
You can access your 32-bit address assigned to you on the local network with the hostname -I command. The web page was served by Apache via this address.
Apache http server is served at /var/www/html by default. For detailed information, you can visit [18][19]. It will contain an index.html file.
You can use the file content using nano or vim, whichever you prefer.
You can access the web page by typing the address you obtained with the hostname -I command into the URL section.
Raspberry PI Pigpio Usage and Java PI4J Distance Sensor Example
We can say that Pigpio is a tool that allows us to operate the pins on the Raspbery PI.
There is also a library that you can use with Java language. PI4J is an I/O library that allows us to develop with Raspberry PI. You can do various projects with this library.
Java is a powerful language that has a lot of support and you will not have any difficulty in searching for resources, and if you already have experience in this language, you will not have any difficulty. First of all, let’s give information about writing and reading values on some small pins with pigpio.
If the package is not installed, you can quickly install it with sudo apt-get pigpio command.
You can see the status of the package with sudo systemctl status pigpiod command.
pigs modes ‘pin code’ ‘mode (w)write or (r)read’
pigs modes 17 w
pigs modes 17 r
Pin 17 is set to read or write mode.
pigs w 17 1 with this command, high, i.e. 3.3v, was transmitted to pin 17.
At this stage, if an LED circuit is installed on the relevant pin, the LED will turn on. In this case, pigs w 17 0 will switch to the off state, that is, low. pigs r 17 checks whether there is voltage on pin 17 or not. If it exists, it returns 1, otherwise it returns 0.
Distance Sensor with Java PI4J Library
Let’s look at an example distance sensor application with the Java pi4j library. Pi4j library uses the pigpio package and you can check out the sources for detailed information [20].
In the application, 1 HC-SR04 distance sensor, 1 LED and 2 resistors were used. The red LED turns on when the distance between the sensor and the object is less than 10cm. GPIO 2 was connected to echo on the sensor and GPIO 3 was connected to trigg. 3.3v was used as voltage. GPIO 17 pin was used for the LED.
Github: https://github.com/gokhanergen-tech/pi4j-java-distance-sensor-and-vcore-raspberry-pi
As a result, Raspberry PI is a popular educational computer today. You can install a web server such as Apache on it or use it in your daily work. You can design circuits and make projects using sensors. You may not limit yourself to the programming language and you can choose other programming languages as needed. Within the scope of this article, examples of a library developed in Java language were shown.
Sources
1-https://www.researchgate.net/figure/The-structure-of-the-Raspberry-Pi-4B_fig1_370357718
2-https://www.deviceplus.com/raspberry-pi/the-history-of-raspberry-pi/
3-https://electronicguidebook.com/is-raspberry-pi-an-embedded-system%EF%BF%BC/
4-https://www.raspberrypi.com/software/
5-https://mediatrend.mediamarkt.com.tr/windows-10-bootable-usb-nasil-yapilir/
6-https://edu.gcfglobal.org/en/computerbasics/understanding-operating-systems/1/
7-https://www.freecodecamp.org/news/command-line-for-beginners/
8-https://www.prepbytes.com/blog/operating-system/operating-system-services
9- Raspberry Pi Documentation — Getting started
10-https://pimylifeup.com/raspberry-pi-apache/
11-https://linuxize.com/post/how-to-create-groups-in-linux/
12-https://www.freecodecamp.org/news/file-permissions-in-linux-chmod-command-explained/
13-https://devconnected.com/how-to-list-users-and-groups-on-linux/
14-https://www.geeksforgeeks.org/permissions-in-linux/
15-https://stackoverflow.com/questions/29475138/what-is-the-difference-between-update-and-upgrade
16-https://www.ihs.com.tr/blog/apache-nedir/
17-https://ubuntu.com/tutorials/install-and-configure-apache#3-creating-your-own-website
21-https://www.researchgate.net/figure/Raspberry-Pi-4-pin-details_fig4_352212777
22-https://kalitut.com/control-gpio-pigpiod-commands/
23-https://raspberrypi.stackexchange.com/questions/17121/ultrasonic-sensor-get-distance-with-java
24-https://github.com/gokhanergen-tech/pi4j-java-distance-sensor-and-vcore-raspberry-pi
^
Top comments (1)
great article, only issue for me is there are many alternatives I think better than java to use however for may java will be a good way into embedded