It is not often that I throw my hands up and stop trying to get something to work. This is one of those cases. The basic problem is that the GPIO chip changed between the Raspberry Pi 4 and Raspberry Pi 5. Given that my background was working for a large computer companies, Sun Microsystems/Oracle/IBM, and I have a Masters degree in Computer Engineering and another in Electrical Engineering, I am very unsettled that a simple chip change causes software to break between hardware releases. What should happen is that the operating system should hide these changes. A new device driver should be written to keep the user interfaces, both at the command line and libraries for various languages, the same and functional between chip changes.
Just to set this in time, it is the first of August in 2024 and I can not get Java libraries to work on the Raspberry Pi because pieces and components don’t exist to allow for a simple download. I can get both Eclipse and Microsoft Visual Studio working on a Raspberry Pi 5 but no Java libraries that work with the GPIO exist. I am struggling to get Studio to work properly on a Raspberry Pi 4 because there is not enough memory on the 2MB model that I have. The IDE loads and starts to run. When I try to install Java or C/C++ as a language extension the operating system “wedges” and stops working. The net result is that I can’t get an IDE, Java, and the GPIO libraries to work on a Raspberry Pi 4 or a Raspberry Pi 5.
The https://www.pi4j.com/ website says that the Java libraries on the site support the Raspberry Pi 5 but the libraries are dependent upon the http://wiringpi.com/ WiringPi interfaces. When you go to the WiringPi website it says that
“As of the end of 2023, you’ll not find anything here anymore. It’s gone.
Email if you want – if you know my email address. Work it out.
-Gordon
This is unfortunate and breaks the only Java GPIO library that states that it works with the Raspberry Pi 5.
In theory, you can download a fully baked operating system that contains an older version of the Pi4J library as well as the WiringPi interfaces but I am hesitant to download any code that no longer has support.
The fundamental problem is that not only has the chip changed but the numbering of the GPIO pins has changed. According to http://git.munts.com/muntsos/doc/AppNote11-link-gpiochip.pdf the basic problem is how the devices are presented from the operating system.
The Raspberry Pi 5 introduced an unfortunate breaking API change for manipulating GPIO pins. For all previous Raspberry Pi boards, you needed to use /dev/gpiochip0 to manipulate the expansion header GPIO pins. On the Raspberry Pi 5, the GPIO controllers enumerated differently, and you must now use /dev/gpiochip4. Furthermore, the
Raspberry Pi engineering staff have indicated that the enumeration order may change in the future as well. This change has broken many Raspberry Pi GPIO libraries…
Given that the way that the operating system presents the definition of the GPIO pins has changed and will probably change again, my recommendation is to use something else. If you have to use the GPIO pins, expect to change your code again in a year or two and know that at some point it will break again. Unfortunately, driving motors, LEDS, and meters are done easily using the GPIO pins. These changes not only effect the GPIO pins but the IC2 and other pins that can be used to drive input and output for the Raspberry Pi. I will continue to go through tutorials using Python, C/C++, and Java where it makes sense. Realize at some point these tutorials will break and the libraries that are used to show functionality will probably break and an alternate solution might be needed.
What we have that is working is as follows
Language | IDE | GPIO |
Command Line | No | Pi4 – gpio, raspi-gpio Pi5 – pinctl |
Python | Eclipse, Visual Studio | Pi5 with IDE Pi4 with no IDE |
C/C++ | Eclipse, Visual Studio | Pi5 with IDE Pi4 with no IDE |
Java | Eclipse, Visual Studio | Pi4 with no IDE |