1

I'm trying to write a simple program which uses the GPIO pins of the Raspberry Pi 3B.

When I run the following program, only the LED on pin 17 flashes. Pin 27 doesn't blink and doesn't get set to OUT.

I don't get any error messages.

int main(){
if (wiringPiSetupSys() == -1){
        std::cout << "wiringpsetup failed\n";
        exit(1);
}

auto pin = 17;
auto pin1 = 27;
pinMode(pin, OUTPUT);
pinMode(pin1, OUTPUT);

for (auto i = 0; i < 8; ++i)
{
    digitalWrite(pin, HIGH);
    digitalWrite(pin1, HIGH);
    delay(500);
    std::cout << "high\n";
    digitalWrite(pin, LOW);
    digitalWrite(pin1, LOW);
    delay(500);
    std::cout << "low\n";
}
}

However, I can make the LED on pin 27 blink by executing the following commands in the terminal:

gpio -g mode 27 out
gpio -g write 27 0
gpio -g write 27 1
gpio -g write 27 0

Consequently, the LED is properly connected and not broken.

A little additional information:

pi@raspberrypi:~$ gpio -g readall
 +-----+-----+---------+------+---+---Pi 3B--+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 |   IN | 1 |  3 || 4  |   |      | 5v      |     |     |
 |   3 |   9 |   SCL.1 |   IN | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 0 | IN   | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | IN   | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |  OUT | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |  OUT | 1 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | OUT  | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI |   IN | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO |   IN | 0 | 21 || 22 | 1 | OUT  | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK |   IN | 0 | 23 || 24 | 1 | IN   | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | IN   | 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 |
 +-----+-----+---------+------+---+---Pi 3B--+---+------+---------+-----+-----+
Addi873
  • 85
  • 5
  • Some pins can be multiplexed. You'll have to search the data sheets and documentation on how to convert the pin to GPIO. – Thomas Matthews Jun 04 '21 at 16:40
  • @ThomasMatthews What do you mean with "multiplexed"? By the way, i also tried to set all pins to OUT with a loop from 0 to 30. But it has not changed anything – Addi873 Jun 04 '21 at 16:47
  • Multiplexed means the pin can serve multiple purposes. Common combinations are GPIO and Address. On some chips, the High Order address lines can be multiplexed as GPIO, so if you don't need the address range, you can have more I/O pins. – Thomas Matthews Jun 04 '21 at 16:49
  • When you wrote "pin 17" in your question, did you mean CPU pin 17, PI pin 17, or GPIO 17? – Ben Voigt Jun 04 '21 at 19:46
  • @BenVoigt I ment BCM pin 17 – Addi873 Jun 05 '21 at 09:08

1 Answers1

0

I still don't know why it doesn't work in the example, but I found another solution:

Instead of wiringPiSetupSys() I use now the function wiringPiSetupPhys() and accordingly the correct pins (13 and 15).

If someone knows a solution with wiringPiSetupSys(), I would still be glad about an answer...

Addi873
  • 85
  • 5
  • Try `wiringPiSetupSys` with the GPIO numbers (column with title `wPi`), not the CPU pin numbers (column with title `BCM`). – Ben Voigt Jun 06 '21 at 00:37