2

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

  • "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 ? – Shreyas Murali 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 ? – Shreyas Murali Sep 27 '16 at 6:31
0

Have you installed the RPI.GPIO on your Pi?. If not install it using this command

if you are using Python2 then type sudo apt-get -y install python-rpi.gpio

and if you are using Python3 then type 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.

If you don't know what I mean see the following photo:

pin-out diagram

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

If this is not the problem. try chancing 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)
p.start(1)
input('Press return to stop:')   # use raw_input for Python 2
p.stop()
GPIO.cleanup()

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

  • 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 – Shreyas Murali 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.

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.