6

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();
    }
}
3
  • so does your program work when not using pin 20? Commented Jul 14, 2017 at 3:18
  • 1
    @MohammadAli Yup. But once again, it works fine using pin 20 in Python... Commented Jul 14, 2017 at 11:31
  • Somehow both answers overlooked that comment above: if it were a misconfiguration problem, Python would not work either. Commented Dec 7, 2020 at 14:24

2 Answers 2

-1

I am thinking you may have SPI enabled and that pin is the SPI master out.

When enabled you should see the device /dev/spidev0.0 if so use raspi-config to disable SPI and see how you get on.

-1

You need to check the multiple functionalities of each pin, which is controlled elsewhere. AFAICR, one pin can have up to 4 different functions. In addition you are not telling us which Rpi you have. RPi3 does not have the same GPIO pin mapping as Pi1/2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.