Greenberet
Posts: 2
Joined: Thu Apr 02, 2015 8:26 pm
Location: Austria

PI4J - pin.high() not working

Thu Apr 02, 2015 8:40 pm

Hello,

I'm trying to set the pin state of the gpio04 pin to high, but it will always be low =(.

in /sys/class/gpio a folder for gpio23 (which is 04) gets created correctly. However /sys/class/gpio/gpio23/value has always the value 0.
When I set it manually ( echo "1" > /sys/class/gpio/gpio23/value ) my led will glow correctly.

I'm using the following code as root:

Code: Select all

//...
    GpioController gpio = GpioFactory.getInstance();
    GpioPinDigitalOutput pin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_04, "MyLED", PinState.LOW);
//...
    pin.high() //  /sys/class/gpio/gpio23/value is still 0
Am I missing something?

User avatar
rpdom
Posts: 17275
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: PI4J - pin.high() not working

Fri Apr 03, 2015 12:05 pm

Which actual physical pin are you using?

The internal gpio 23 (Broadcom/BCM) is connected to Physical pin 16 on the P1 connector and in "wiringpi" terms is known as "GPIO. 4".

When using the /sys/class/gpio interface you are using the BCM numbers.

When connecting to the board you use the actual physical pin numbers.

The "wiringpi" numbers exist in a different universe.

User avatar
DougieLawson
Posts: 39303
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: PI4J - pin.high() not working

Fri Apr 03, 2015 12:20 pm

rpdom wrote: The "wiringpi" numbers exist in a different universe.
At least with wiringpi you can ask it to display all the possible names and numbers for the pins.

Code: Select all

pi@apollo:~$ gpio readall
 +-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 | ALT0 | 1 |  3 || 4  |   |      | 5V      |     |     |
 |   3 |   9 |   SCL.1 | ALT0 | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT0 | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | ALT0 | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI | ALT0 | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO | ALT0 | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK | ALT0 | 0 | 23 || 24 | 1 | ALT0 | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | ALT0 | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO.21 |   IN | 1 | 29 || 30 |   |      | 0v      |     |     |
 |   6 |  22 | GPIO.22 |   IN | 1 | 31 || 32 | 0 | IN   | GPIO.26 | 26  | 12  |
 |  13 |  23 | GPIO.23 |   IN | 0 | 33 || 34 |   |      | 0v      |     |     |
 |  19 |  24 | GPIO.24 |   IN | 0 | 35 || 36 | 0 | IN   | GPIO.27 | 27  | 16  |
 |  26 |  25 | GPIO.25 |   IN | 0 | 37 || 38 | 0 | IN   | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 0 | IN   | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+
pi@apollo:~$
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Greenberet
Posts: 2
Joined: Thu Apr 02, 2015 8:26 pm
Location: Austria

Re: PI4J - pin.high() not working

Mon Apr 06, 2015 5:53 pm

I know that they are different.

the GPIO_04 should match bcm-gpio23 which is fine. When I open the port the /sys/class/gpio23 folder gets created(no other gpio folders are visible) and I'm running a simple watch --interval=1 "cat /sys/class/gpio/gpio23/value" to check the result, and it is always 0. So it isn't a wiring problem.

Return to “Java”