BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Control servo with a button in a Raspbeery Pi 3

rpi
python

#1

Hi all,

I’m new in blynk community and i making a project and i need to control a servo motor with a button in Blynk app.
I have the code bellow:

import RPi.GPIO as GPIO
import time

servoPIN = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(servoPIN, GPIO.OUT)
GPIO.setwarnings(False)

p = GPIO.PWM(servoPIN, 50) # GPIO 17 for PWM with 50Hz
p.start(2.5) # Initialization

p.ChangeDutyCycle(12.5)
time.sleep(0.5)
p.ChangeDutyCycle(2.5)
time.sleep(0.5)

p.stop()
GPIO.cleanup()

What i need is: every time i will push the button, the app shall be run this code.
Anyone knows how i do this ?
I will appreciatte any helps.
Thank you.


#2

Look at the examples in the Python Library and extrapolate from there…

And I fixed your required formatting when pasting code here…

Blynk - FTFC


#3

Hi Guuner,

Thanks for the formatting fixed.
When i run one of the examples of the python library in Python 2 lDLE into my raspberry i receive the follow answer:

Traceback (most recent call last):
  File "/home/pi/test.py", line 1, in <module>
    import BlynkLib
ImportError: No module named BlynkLib

I follow all the steps from the http://docs.blynk.cc/#hardware-set-ups-raspberry-pi and apparently I did everything right.

Could you please help me with that ?

Thanks and regards.


#4

That link is for NodeJS… if you are using Python, then look here… Same link as above.