User avatar
dentex
Posts: 180
Joined: Sun May 20, 2012 7:58 am
Location: Italy
Contact: Website

GPIO strange behaviour at boot

Thu Sep 22, 2016 4:33 pm

Hello guys, I'm facing a very strange behaviour (at least for what I understand) in regards to how the GPIO on my RPi work after boot up. I'm using a RPi 3 model B and Debian Jessie, all up to date, including the firmware via rpi-update.

I even bought another RPi, thinking I fried some GPIO pins (I needed it anyway...) just to find that with the new one it was exactly the same. Consider anyway that I simply moved Sdcard and USB (with the system on it) between the two RPi; so they did run from the exact same system.

This is how to reproduce the problem (I discovered it playing around with a couple of switches and LEDs):

After boot, I do:

Code: Select all

~$ for p in 17 27 22 10 9 11 0 5 6 13 19 26 14 15 18 23 24 25 8 7 1 12 16 20 21; do gpio export $p out; done
~$ for p in 17 27 22 10 9 11 0 5 6 13 19 26 14 15 23 24 25 8 7 1 12 16 20 21; do gpio -g write $p 1; done
to have every GPIO as output and high.

But, this is what `gpio readall` gives:

Code: Select all

+-----+-----+---------+------+---+---Pi 3---+---+------+---------+-----+-----+
 | 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 | OUT  | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | OUT  | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |  OUT | 0 | 11 || 12 | 0 | OUT  | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |  OUT | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |  OUT | 0 | 15 || 16 | 0 | OUT  | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | OUT  | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI |  OUT | 1 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO |  OUT | 1 | 21 || 22 | 0 | OUT  | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK |  OUT | 1 | 23 || 24 | 1 | OUT  | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | OUT  | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |  OUT | 1 | 27 || 28 | 1 | OUT  | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO.21 |  OUT | 1 | 29 || 30 |   |      | 0v      |     |     |
 |   6 |  22 | GPIO.22 |  OUT | 1 | 31 || 32 | 1 | OUT  | GPIO.26 | 26  | 12  |
 |  13 |  23 | GPIO.23 |  OUT | 1 | 33 || 34 |   |      | 0v      |     |     |
 |  19 |  24 | GPIO.24 |  OUT | 1 | 35 || 36 | 1 | OUT  | GPIO.27 | 27  | 16  |
 |  26 |  25 | GPIO.25 |  OUT | 1 | 37 || 38 | 1 | OUT  | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 1 | OUT  | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+---Pi 3---+---+------+---------+-----+-----+
As you can notice, BCM pins 17, 27, 22, 18, 23, 24 and 25 don't go high. If I measure their voltage with a meter they are at 0V.

...and neither works a simple python script as

Code: Select all

#!/usr/bin/python

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.OUT)

GPIO.output(23, 1)
time.sleep(1)
GPIO.output(23, 0)

GPIO.cleanup()
**Here is where I bought the other RPi** :evil:

I use the awesome servoblaster to generate accurate PWM from the GPIO pins.
I came across this by chance: if a configure even only one of the failing pins (servoblaster uses physical numeration), i.e.

Code: Select all

sudo servod --p1pins=15 --cycle-time=5000us --step-size=5us --min=5us --max 5000us
and then kill servod:

Code: Select all

~$ sudo killall servod
...now all the interested pins work again !!!

Code: Select all

~$ for p in 17 27 22 10 9 11 0 5 6 13 19 26 14 15 18 23 24 25 8 7 1 12 16 20 21; do gpio export $p out; done
~$ for p in 17 27 22 10 9 11 0 5 6 13 19 26 14 15 18 23 24 25 8 7 1 12 16 20 21; do gpio -g write $p 1; done
~$ gpio readall
+-----+-----+---------+------+---+---Pi 3---+---+------+---------+-----+-----+
 | 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 | OUT  | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | OUT  | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |  OUT | 1 | 11 || 12 | 1 | OUT  | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |  OUT | 1 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |  OUT | 1 | 15 || 16 | 1 | OUT  | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 1 | OUT  | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI |  OUT | 1 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO |  OUT | 1 | 21 || 22 | 1 | OUT  | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK |  OUT | 1 | 23 || 24 | 1 | OUT  | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | OUT  | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |  OUT | 1 | 27 || 28 | 1 | OUT  | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO.21 |  OUT | 1 | 29 || 30 |   |      | 0v      |     |     |
 |   6 |  22 | GPIO.22 |  OUT | 1 | 31 || 32 | 1 | OUT  | GPIO.26 | 26  | 12  |
 |  13 |  23 | GPIO.23 |  OUT | 1 | 33 || 34 |   |      | 0v      |     |     |
 |  19 |  24 | GPIO.24 |  OUT | 1 | 35 || 36 | 1 | OUT  | GPIO.27 | 27  | 16  |
 |  26 |  25 | GPIO.25 |  OUT | 1 | 37 || 38 | 1 | OUT  | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 1 | OUT  | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+---Pi 3---+---+------+---------+-----+-----+
Now, why is this happening?

Thanks for any advice.
One of my projects with the Raspberry Pi:
--------------------------------------------------------
(Raspberry) Pi Aquarium Controller: https://github.com/dentex/piac

User avatar
joan
Posts: 14759
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: GPIO strange behaviour at boot

Thu Sep 22, 2016 5:10 pm

I assume you are starting servoblaster at boot.

Presumably servoblaster is controlling the GPIO and overriding the gpio commands.

User avatar
dentex
Posts: 180
Joined: Sun May 20, 2012 7:58 am
Location: Italy
Contact: Website

Re: GPIO strange behaviour at boot [SOLVED]

Thu Sep 22, 2016 5:39 pm

joan wrote:I assume you are starting servoblaster at boot.

Presumably servoblaster is controlling the GPIO and overriding the gpio commands.
O. M. G.

:shock:

I do have a `/etc/init.d/servoblaster` and after boot, `sudo cat /dev/servoblaster-cfg` returns:

Code: Select all

p1pins=7,11,12,13,15,16,18,22
p5pins=

Servo mapping:
     0 on P1-7           GPIO-4
     1 on P1-11          GPIO-17
     2 on P1-12          GPIO-18
     3 on P1-13          GPIO-27
     4 on P1-15          GPIO-22
     5 on P1-16          GPIO-23
     6 on P1-18          GPIO-24
     7 on P1-22          GPIO-25
...that is exactly what was locked.

`sudo make uninstall` and I'm good to go.

Thank you very much!
I sensationally missed this one.
One of my projects with the Raspberry Pi:
--------------------------------------------------------
(Raspberry) Pi Aquarium Controller: https://github.com/dentex/piac

Return to “Automation, sensing and robotics”