3

I just got a raspberry pi 3 B+ model and have wrote some scripts to create an LED pattern. Everything worked and then suddenly stopped. Now every time I run a python script through sudo python #scriptName the console crashes meaning I can't run anymore python code or shutdown the computer without pulling the power chord, I can't ctrl+C as it just prints ^c on the console screen and there in no python program to use the kill command on. Without the Cobbler connected code will run sometimes, but with it connected the console freezes. Also the led connected in the bread board dimly glows without the GPIO being turned on on startup and stays on until I turn it off from the console. Did I burn something out? Can someone please offer me advice as to what is happening? My Trial Script

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(12, GPIO.OUT)
GPIO.output(12, GPIO.HIGH)
time.sleep(1)
GPIO.output(12,GPIO.LOW)

Here is a picture of the problem. The Problem Here is a picture of the circuit I set up The Circuit

5
  • "or shutdown the computer without pulling the power chord" -> Why can't you just open another terminal/use the GUI? "ctrl+C...just prints ^c" -> The ^C indicates you are pressing Ctrl-C, which sends a polite stop request to the foreground process. However, the process is not required to obey this, but in general they politely should and if not, something is probably wrong, e.g., an I/O error. If you can get another console, have a look at sudo tail /var/log/syslog when this happens.
    – goldilocks
    Jul 25 '16 at 13:56
  • If the GUI doesn't respond at all, try Alt-Ctrl-F[1-6] (cycle through each F-key up to 6); you should get a non-GUI console (or possibly another GUI login screen). If nothing happens that way then the system is truly locked up. In that case you could try pulling the plug, rebooting, and looking back through /var/log/syslog to when before the reboot occurred (the reboot will be indicated with kernel timestamps that are all zero, eg. [ 0.000000]).
    – goldilocks
    Jul 25 '16 at 14:04
  • can you change GPIO.setwarnings(False) to GPIO.setwarnings(True) and see if any warnings appear ? Sep 27 '16 at 6:27
  • apparently there was a similar problem back in the time of raspbian/wheezy. Can you share the o/p of uname -a and cat /etc/os-release ? Sep 27 '16 at 6:31
  • Have you checked the ribbon cable for your cobbler is round the right way at the RPi end? They usually have a keyed connector for the cobbler, but there's no keying at the RPi. The cable usually has a different colour for the pin#1 cable that needs to be at the top of the RPi board.
    – Dougie
    Aug 20 '20 at 8:44
1

Have you installed the RPI.GPIO on your Pi?. If not, try installing it using one of the following commands:

Python2: sudo apt-get -y install python-rpi.gpio

Python3: sudo apt-get -y install python3-rpi.gpio

If this is not the problem, you can skip this step.


There is a difference between physical numbering and GPIO numbering. Have you taken this into consideration?

Please refer to the following image:

pin-out diagram

Notice that for example Pin#16 is GPIO23 not GPIO16.


If this is not the problem. try changing the mode to be PWM instead of BCM.

An example to blink an LED once every two seconds:

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)

p = GPIO.PWM(12, 0.5) # channel=12 , frequency=0.5Hz
p.start(1)
input('Press return to stop:')   # use raw_input for Python 2
p.stop()
GPIO.cleanup()

I am trying to give you all the possibilities. I have faced your problem before and I tried these solutions and It worked for me pretty well.

3
  • 2
    If it was not installed it should report ImportError: No module named... upon running the script.
    – Ghanima
    Jul 25 '16 at 12:53
  • @Ghanima Not in all this cases I faced his problem before and it wasn't installed. I also improved the answer a little bit.
    – Tes3awy
    Jul 25 '16 at 12:55
  • it is clear from the photo, the OP is not connecting the external circuit directly to the Pi. the pin 16 printed on the bread board has little to do with the pin # on the cobbler board or the PI Sep 27 '16 at 5:52
0

Try adding GPIO.cleanup() before calling the GPIO functions. Also sometimes I add debug prints after every statement to see which call the process is hanging. Adding a handler for ctrl+C (keyboard interrupt) may help in killing the process or use kill command from another terminal. A quick dirty workaround maybe to use Ctrl+Z so the process goes to background and you get access to the terminal. Then kill it. Of course, not a solution but won't need reboot.

0

In such a case it's recommended to go "one level lower" and to use a diagnostic utility like the gpio program, which comes with the wiringPi library. See the manpage on how to use it. To find out the logic levels of your GPIO pins, you can use the piscope utility. If it also hangs whilst trying to access the GPIO pin with the LED attached, a hardware issue may be the cause.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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