OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Can't control servo with Python using Raspberry Pi

  • Thread starter Thread starter realhuman
  • Start date Start date
R

realhuman

Guest
I am using a Raspberry Pi model 4B and a Tower Pro servo SG51R which only turns 180 degrees. I am writing code on the Raspberry Pi to control the servo (which works as I have tested it with my Arduino Uno, it responds and works correctly) with Python.

I installed the gpiozero library successfully on my Raspberry Pi using the below commands:

Code:
sudo apt-get install python3-rpi.gpio
sudo pip install gpiozero

I then connected my servo to the Raspberry Pi similar to the diagram shown below diagram
I made sure the brown wire connected to GND, the red wire to a 4.8 volt power supply. and the yellow wire to the GPIO pin 25 (normal pin 22).

I then ran the below code:

Code:
from gpiozero import Servo
 
test = Servo(22)
print('moving')
test.max()
print('done moving')
from time import sleep
sleep(1)
print('moving again')
test.min()
print('finished second movement')
 
sleep(5)
 
test.value = 0
 
sleep(1)
test.value = 1
 
sleep(1)
test.value = -1
 
print('done entirely')

and received the below output:

Code:
/usr/lib/python3/dist-packages/gpiozero/output_devices.py:1532: PWMSoftwareFallback: To reduce servo jitter, use the pigpio pin factory.See https://gpiozero.readthedocs.io/en/stable/api_output.html#servo for more info
  warnings.warn(PWMSoftwareFallback(
moving
done moving
moving again
finished second movement
done entirely

Yet the servo still does not move. I even tried using a different servo of the same model, and using different pins to no avail. Is there anything else I'm missing? How could I make this work?
<p>I am using a <strong>Raspberry Pi model 4B</strong> and a <strong>Tower Pro servo SG51R</strong> which only turns 180 degrees. I am writing code on the Raspberry Pi to control the servo <em>(which works as I have tested it with my Arduino Uno, it responds and works correctly)</em> with Python.</p>
<p>I installed the <code>gpiozero</code> library successfully on my Raspberry Pi using the below commands:</p>
<pre><code>sudo apt-get install python3-rpi.gpio
sudo pip install gpiozero
</code></pre>
<p>I then connected my servo to the Raspberry Pi similar to the diagram shown below
<a href="https://i.sstatic.net/UmX7n5bE.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/UmX7n5bE.png" alt="diagram" /></a><br />
I made sure the brown wire connected to GND, the red wire to a 4.8 volt power supply. and the yellow wire to the GPIO pin 25 (normal pin 22).</p>
<p>I then ran the below code:</p>
<pre class="lang-py prettyprint-override"><code>from gpiozero import Servo

test = Servo(22)
print('moving')
test.max()
print('done moving')
from time import sleep
sleep(1)
print('moving again')
test.min()
print('finished second movement')

sleep(5)

test.value = 0

sleep(1)
test.value = 1

sleep(1)
test.value = -1

print('done entirely')
</code></pre>
<p>and received the below output:</p>
<pre><code>/usr/lib/python3/dist-packages/gpiozero/output_devices.py:1532: PWMSoftwareFallback: To reduce servo jitter, use the pigpio pin factory.See https://gpiozero.readthedocs.io/en/stable/api_output.html#servo for more info
warnings.warn(PWMSoftwareFallback(
moving
done moving
moving again
finished second movement
done entirely
</code></pre>
<p>Yet the servo still does not move. I even tried using a different servo of the same model, and using different pins to no avail. Is there anything else I'm missing? How could I make this work?</p>
 

Latest posts

N
Replies
0
Views
1
Nazar Bilyi
N
Top