Hello fellow Pi enthusiasts :)
I am currently attempting to control a standard 16x2 character LCD display from the PI's GPIO pins from Java.
I downloaded Pi4J and wrote a small program to initialize the display. However, when I run the program with:
sudo java -jar gpioTest.jar #NB: the docs say you MUST run as root :\
Something very interesting happens. The LCD does in fact initialize properly, however, the entire USB bus dies when I run the program! The keyboard and mouse stop working, (no laser on the mouse) and my Wi-Fi dongle quits working too (the status icon on the taskbar changes to no connection).
Nevertheless, the Pi is not frozen in this state, as I can see the CPU monitor moving. But since neither the keyboard or mouse works, I am forced to pull the power.
I have tried this three times in a row, all with the same result, so it's not a fluke.
So then, why the heck does the USB bus die when running my program?
If it matters, I am running Raspian on a Pi 2B. Maybe someone can try to reproduce this issue?
Update:
By putting sysouts after every line, I have found that the USB bus dies after this line:
final GpioPinDigitalOutput D3 = gpio.provisionDigitalOutputPin(RaspiBcmPin.GPIO_20, "Data_3", PinState.LOW);
Update 2
By switching D3 to pin 16 (BCM scheme) , I have solved the freezing problem. The next question is, why does using GPIO pin 20 (BCM scheme) in Pi4J kill the USB bus, but it works just fine when using it in Python?
Here's the exact program:
import com.pi4j.io.gpio.*;
public class MainProgram
{
public static void main(String[] args) throws InterruptedException
{
GpioFactory.setDefaultProvider(new RaspiGpioProvider(RaspiPinNumberingScheme.BROADCOM_PIN_NUMBERING));
final GpioController gpio = GpioFactory.getInstance();
final GpioPinDigitalOutput RS = gpio.provisionDigitalOutputPin(RaspiBcmPin.GPIO_25, "RegisterSelect", PinState.LOW);
final GpioPinDigitalOutput EN = gpio.provisionDigitalOutputPin(RaspiBcmPin.GPIO_24, "Enable", PinState.LOW);
final GpioPinDigitalOutput D0 = gpio.provisionDigitalOutputPin(RaspiBcmPin.GPIO_13, "Data_0", PinState.LOW);
final GpioPinDigitalOutput D1 = gpio.provisionDigitalOutputPin(RaspiBcmPin.GPIO_19, "Data_1", PinState.LOW);
final GpioPinDigitalOutput D2 = gpio.provisionDigitalOutputPin(RaspiBcmPin.GPIO_26, "Data_2", PinState.LOW);
final GpioPinDigitalOutput D3 = gpio.provisionDigitalOutputPin(RaspiBcmPin.GPIO_20, "Data_3", PinState.LOW);
final GpioPinDigitalOutput D4 = gpio.provisionDigitalOutputPin(RaspiBcmPin.GPIO_23, "Data_4", PinState.LOW);
final GpioPinDigitalOutput D5 = gpio.provisionDigitalOutputPin(RaspiBcmPin.GPIO_17, "Data_5", PinState.LOW);
final GpioPinDigitalOutput D6 = gpio.provisionDigitalOutputPin(RaspiBcmPin.GPIO_21, "Data_6", PinState.LOW);
final GpioPinDigitalOutput D7 = gpio.provisionDigitalOutputPin(RaspiBcmPin.GPIO_22, "Data_7", PinState.LOW);
D0.high();
D1.high();
D2.high();
D3.high();
EN.high();
Thread.sleep(25);
EN.low();
gpio.shutdown();
}
}