1

I am using an SG90 and the GPIO Pin #17 but it only sometimes turns when I run the code. It always works if I reset the Kernel everytime.

I am connected to my Pi through putty and am running the code in Jupyter Notebook.

Connections: Connections on Raspberry Pi

The code:

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
p = GPIO.PWM(17,50)

p.start(0)
time.sleep(3)

p.ChangeDutyCycle(2)
time.sleep(2)
p.ChangeDutyCycle(12)
time.sleep(2)
p.ChangeDutyCycle(7)
time.sleep(2)
p.ChangeDutyCycle(2)
time.sleep(2)
p.ChangeDutyCycle(0)


p.stop()
GPIO.cleanup()
8
  • BCM GPIO 17 is connected to physical pin 11. Is that what you are using. Can you add a photo of the connections? – joan Jul 13 '20 at 9:54
  • yes it is connected to the 11th pin. thank you for editing the post – whydoesntitwork Jul 13 '20 at 10:05
  • Connections look okay. Does the following work? sudo pigpiod followed by pigs s 17 1500 mils 2000 s 17 1000 mils 2000 s 17 2000 – joan Jul 13 '20 at 10:08
  • 2
    I'm not sure what you mean by "reset the Kernel". It should work again without doing anything like that. – joan Jul 13 '20 at 11:10
  • 1
    Ditto joan WRT "reset the Kernel" -- it would be better if you just said what you did in literal terms, because that phrase is meaningless in context (ie., it's nonsensical) or at best extremely ambiguous. – goldilocks Jul 13 '20 at 14:03

Your Answer

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

Browse other questions tagged or ask your own question.