Luke14
Posts: 16
Joined: Sun Jun 06, 2021 11:59 am

'pigpio' help! (+ servo jitter)

Thu Jun 10, 2021 5:57 pm

***EDIT***
SOLVED. :D

*************************
Hi all.

I’m fairly new to this forum so please forgive me if I have done anything wrong here, I have also posted this on a different board but figured it is probably better on this one – if this is not allowed then please do forgive me as I have looked through the forum FAQ but couldn’t seem to find anything.

Also to add, I am only a beginner with the Raspberry Pi so don't fully understand all this...

For a bit of background: I am a beginner learning python and am using gpiozero on python. I am trying to create a project just to continue learning how to use gpiozero where I am trying to connect things like a servo motor, LCD display, LDR, etc.

I am trying to use some servo motors with my Pi using a Servo Six board - I was having issues with servo jitter and was told my cheap sg90 servos may be causing the problem... So I bought a TowerPro metal geared servo but that still hasn't fixed the problem.

Yesterday I updated my Pi and when I tried to run my code I had this message come up in the python shell:

/usr/lib/python3/dist-packages/gpiozero/output_devices.py PWMSoftwareFallback: To reduce servo jitter, use pigpio pin factory.See https://gpiozero.readthedocs.io/en/stab ... html#servo for more info
'To reduce servo jitter, use the pigpio pin factory.'

Has anyone switched their pin factory on their Pi?

As I'm only beginner and don't fully understand all of this stuff, I have a few questions to ask before I change my pin factory.

1. Is it even fully safe to change or can it cause problems with the Pi or other items, I would rather have problems with all my servos than my Pi and/or the basic things like buttons, leds, my LCD?

2. Can I still use gpiozero in python (as this is what I have been learning)... And if so are all the things the same (e.g. 'From gpiozero import LED, Lightsensor', 'led = LED(27)', 'led.on', etc, etc)

3. *IF I can't use pigpio like the default using things such as gpiozero as I have mentioned in question 2*... Is it something that I can set just for the servos. So I could have pigpio for use with my servo motors and then still use the default with my other things (like LEDs, buttons, LDR, LCD)

If no to above questions... Can anyone recommend anything else to reduce servo jitter?

Sorry for the long post and all the questions, any help is much appreciated.

Above, I have also mentioned that I am using a servo six board, so for those who don’t already know:

The Servo Six board is essentially a PCB that has 7 ‘input’ pins to connect to the pi, 6 for the GPIO connection to a numbered pin for the actual servo and 1 to go to GND. It then also has a ‘strip’ of 18 pins opposite that you can connect up to 6 servo motors to. The power for the servo motors is supplied via 4 AA batteries that are connected via a screw terminal.

Sorry if I have worded this wrong, think that is the gist of it anyway.

TIA.
Last edited by Luke14 on Sun Jun 13, 2021 10:11 am, edited 1 time in total.

User avatar
bensimmo
Posts: 5365
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: 'pigpio' help! (+ servo jitter)

Thu Jun 10, 2021 6:43 pm

Yes, just change it.
Nice to see it now mentions it.
But changing just alters the back end and not anything you need to do.

If I remember correctly it still had some jitter, never worked out how to use the environment variable method at least working from Thonny and Mu so went th import method.

Both pigpio and gpiozero have been updated since though.
You may want to try the newer lgpio too (done in the same pin swap lines at the top or an environment variable).

I never found the document too clear, it in depth but 'just do this' to get pigpio on the Pi you are working on.
(you will need to enable the background pigpiod as it mentions, oh and it is PiGPIO not PigPiO as people always call it ;-)

Luke14
Posts: 16
Joined: Sun Jun 06, 2021 11:59 am

Re: 'pigpio' help! (+ servo jitter)

Thu Jun 10, 2021 7:33 pm

bensimmo wrote:
Thu Jun 10, 2021 6:43 pm
Yes, just change it.
Nice to see it now mentions it.
But changing just alters the back end and not anything you need to do.

If I remember correctly it still had some jitter, never worked out how to use the environment variable method at least working from Thonny and Mu so went th import method.

Both pigpio and gpiozero have been updated since though.
You may want to try the newer lgpio too (done in the same pin swap lines at the top or an environment variable).

I never found the document too clear, it in depth but 'just do this' to get pigpio on the Pi you are working on.
(you will need to enable the background pigpiod as it mentions, oh and it is PiGPIO not PigPiO as people always call it ;-)
Thank you! I'm pleased to say I have been calling it PiGpio :D

When you say 'import method' do you mean there is a way I can just get it to simply use that pin factory from an import line at the top of my script? If so is there anything else I would need to do or could I just use 1 extra line of code... Just thinking it may be an easier way to try a few of the different pin factories, such as the lgpio one you mentioned, if it is a case of 1 line (until I find the one that works best to set as the 'default') .

Thanks again, and sorry for the stupid questions - as I say I'm only a beginnler.

User avatar
bensimmo
Posts: 5365
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: 'pigpio' help! (+ servo jitter)

Thu Jun 10, 2021 8:23 pm

I think the environment method Is the quickest and easiest.

In the pins section it goes into details of the two methods. But like I said it long winded and not a just so this.
All the pigpio seems to be written with remote use (which is cool).

Now unfortunately I don't have my code near me nor a Pi to check what works.
I also use the cheap blue servos and still had jitter (a lot less though).


But something like

Code: Select all

from gpiozero.pins.pigpio import PiGPIOFactory

gpiozero.Device.pin_factory = PiGPIOFactory('127.0.0.1')

Luke14
Posts: 16
Joined: Sun Jun 06, 2021 11:59 am

Re: 'pigpio' help! (+ servo jitter)

Thu Jun 10, 2021 9:10 pm

bensimmo wrote:
Thu Jun 10, 2021 8:23 pm
I think the environment method Is the quickest and easiest.

In the pins section it goes into details of the two methods. But like I said it long winded and not a just so this.
All the pigpio seems to be written with remote use (which is cool).

Now unfortunately I don't have my code near me nor a Pi to check what works.
I also use the cheap blue servos and still had jitter (a lot less though).


But something like

Code: Select all

from gpiozero.pins.pigpio import PiGPIOFactory

gpiozero.Device.pin_factory = PiGPIOFactory('127.0.0.1')
Thank you!

Well if I can still use it with gpiozero when I change the pin factory I will give it a try (tomorrow)... Thank you for all your help! :D

Luke14
Posts: 16
Joined: Sun Jun 06, 2021 11:59 am

Re: 'pigpio' help! (+ servo jitter)

Sat Jun 12, 2021 12:52 pm

bensimmo wrote:
Thu Jun 10, 2021 8:23 pm
I think the environment method Is the quickest and easiest.

In the pins section it goes into details of the two methods. But like I said it long winded and not a just so this.
All the pigpio seems to be written with remote use (which is cool).

Now unfortunately I don't have my code near me nor a Pi to check what works.
I also use the cheap blue servos and still had jitter (a lot less though).


But something like

Code: Select all

from gpiozero.pins.pigpio import PiGPIOFactory

gpiozero.Device.pin_factory = PiGPIOFactory('127.0.0.1')
Thank you again for this. I had a look yesterday and tried it on some code with my Pi B+ - if that worked I was going to use the lines in my script on my Pi 400.

Sadly, the code did not work and I got this error in the python shell (see pic). I know you said you weren't sure if it would work but I can't seem to find any other versions like you said on the Internet so just wondering if you have any suggestions?

Thank you!
Attachments
Screenshot_20210612_134332.jpg
Screenshot_20210612_134332.jpg (238 KiB) Viewed 647 times

User avatar
B.Goode
Posts: 12263
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: 'pigpio' help! (+ servo jitter)

Sat Jun 12, 2021 1:49 pm

Transcribed from your photo -

Code: Select all

Can't connect to pigpio at 127.0.0.1(8888)

Did you start the pigpio daemon? E.g. sudo pigpiod

My hunch is that you didn't....

Luke14
Posts: 16
Joined: Sun Jun 06, 2021 11:59 am

Re: 'pigpio' help! (+ servo jitter)

Sat Jun 12, 2021 5:26 pm

B.Goode wrote:
Sat Jun 12, 2021 1:49 pm
Transcribed from your photo -

Code: Select all

Can't connect to pigpio at 127.0.0.1(8888)

Did you start the pigpio daemon? E.g. sudo pigpiod

My hunch is that you didn't....

Please forgive my ignorance - as I said in my original post I'm only a beginner so don't fully understand... No I didn't start it as I have zero clue was a daemon is?

Do I just type 'sudo pigpiod' into terminal to start it or do I need to do something different?

Thank you! :D

User avatar
bensimmo
Posts: 5365
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: 'pigpio' help! (+ servo jitter)

Sat Jun 12, 2021 6:32 pm

absolutely just type in in a terminal.

OR

staying in the Desktop, this makes it permanent.
https://gpiozero.readthedocs.io/en/stab ... onnections

They call it remote connections, while it is used for that it isn't exclusively for that, I also think it's mainly used locally to be honest.

User avatar
B.Goode
Posts: 12263
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: 'pigpio' help! (+ servo jitter)

Sat Jun 12, 2021 6:43 pm

Luke14 wrote:
Sat Jun 12, 2021 5:26 pm
B.Goode wrote:
Sat Jun 12, 2021 1:49 pm
Transcribed from your photo -

Code: Select all

Can't connect to pigpio at 127.0.0.1(8888)

Did you start the pigpio daemon? E.g. sudo pigpiod

My hunch is that you didn't....

Please forgive my ignorance - as I said in my original post I'm only a beginner so don't fully understand... No I didn't start it as I have zero clue was a daemon is?

Do I just type 'sudo pigpiod' into terminal to start it or do I need to do something different?

Thank you! :D

Yes, that is what the software developer is helpfully suggesting.

Alternatively you could use the raspi-config utility, or the equivalent Raspberry Pi Configuration tool in the Desktop GUI menu system.


As for being a beginner... most of us are beginners at something most of the time. Each step is an opportunity, if you want to take it, to learn more about the environment you are working in. For example, you could research pigpiod here http://abyz.me.uk/rpi/pigpio/pigpiod.html

Luke14
Posts: 16
Joined: Sun Jun 06, 2021 11:59 am

Re: 'pigpio' help! (+ servo jitter)

Sat Jun 12, 2021 6:49 pm

bensimmo wrote:
Sat Jun 12, 2021 6:32 pm
absolutely just type in in a terminal.

OR

staying in the Desktop, this makes it permanent.
https://gpiozero.readthedocs.io/en/stab ... onnections

They call it remote connections, while it is used for that it isn't exclusively for that, I also think it's mainly used locally to be honest.
Thank you! I will give this a go. :D

Luke14
Posts: 16
Joined: Sun Jun 06, 2021 11:59 am

Re: 'pigpio' help! (+ servo jitter)

Sat Jun 12, 2021 6:50 pm

B.Goode wrote:
Sat Jun 12, 2021 6:43 pm
Luke14 wrote:
Sat Jun 12, 2021 5:26 pm
B.Goode wrote:
Sat Jun 12, 2021 1:49 pm
Transcribed from your photo -

Code: Select all

Can't connect to pigpio at 127.0.0.1(8888)

Did you start the pigpio daemon? E.g. sudo pigpiod

My hunch is that you didn't....

Please forgive my ignorance - as I said in my original post I'm only a beginner so don't fully understand... No I didn't start it as I have zero clue was a daemon is?

Do I just type 'sudo pigpiod' into terminal to start it or do I need to do something different?

Thank you! :D

Yes, that is what the software developer is helpfully suggesting.

Alternatively you could use the raspi-config utility, or the equivalent Raspberry Pi Configuration tool in the Desktop GUI menu system.


As for being a beginner... most of us are beginners at something most of the time. Each step is an opportunity, if you want to take it, to learn more about the environment you are working in. For example, you could research pigpiod here http://abyz.me.uk/rpi/pigpio/pigpiod.html
Thank you. I will try this and hopefully it will work. :D

Luke14
Posts: 16
Joined: Sun Jun 06, 2021 11:59 am

Re: 'pigpio' help! (+ servo jitter)

Sat Jun 12, 2021 7:40 pm

bensimmo wrote:
Thu Jun 10, 2021 8:23 pm
I think the environment method Is the quickest and easiest.

In the pins section it goes into details of the two methods. But like I said it long winded and not a just so this.
All the pigpio seems to be written with remote use (which is cool).

Now unfortunately I don't have my code near me nor a Pi to check what works.
I also use the cheap blue servos and still had jitter (a lot less though).


But something like

Code: Select all

from gpiozero.pins.pigpio import PiGPIOFactory

gpiozero.Device.pin_factory = PiGPIOFactory('127.0.0.1')
Just booted up my Pi and changed it using the line in terminal.

I now get this in the shell using your code:

Code: Select all

Traceback (most recent call last):
                File   "/home/pi/Python/component tests/pigpio servo test for 400.py", line 7, in <module>
                Gpiozero.Device.pin-factory =piGPIOFactory('127.0.0 1')
                NameError: name 'gpiozero' is not defined.
                
Sorry if the spacing is strange above. I have never added code on this forum before so not sure if I have done it correctly... :lol:

Any help appreciated.

User avatar
B.Goode
Posts: 12263
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: 'pigpio' help! (+ servo jitter)

Sat Jun 12, 2021 8:29 pm

Luke14 wrote:
Sat Jun 12, 2021 7:40 pm
bensimmo wrote:
Thu Jun 10, 2021 8:23 pm
I think the environment method Is the quickest and easiest.

In the pins section it goes into details of the two methods. But like I said it long winded and not a just so this.
All the pigpio seems to be written with remote use (which is cool).

Now unfortunately I don't have my code near me nor a Pi to check what works.
I also use the cheap blue servos and still had jitter (a lot less though).


But something like

Code: Select all

from gpiozero.pins.pigpio import PiGPIOFactory

gpiozero.Device.pin_factory = PiGPIOFactory('127.0.0.1')
Just booted up my Pi and changed it using the line in terminal.

I now get this in the shell using your code:

Code: Select all

Traceback (most recent call last):
                File   "/home/pi/Python/component tests/pigpio servo test for 400.py", line 7, in <module>
                Gpiozero.Device.pin-factory =piGPIOFactory('127.0.0 1')
                NameError: name 'gpiozero' is not defined.
                
Sorry if the spacing is strange above. I have never added code on this forum before so not sure if I have done it correctly... :lol:

Any help appreciated.


Supporting documentation and usage example here - https://gpiozero.readthedocs.io/en/stab ... in-factory




Specifically - gpiozero is an 'external' Python library module. You have to import it before you can use its contents.

Luke14
Posts: 16
Joined: Sun Jun 06, 2021 11:59 am

Re: 'pigpio' help! (+ servo jitter)

Sat Jun 12, 2021 8:42 pm

B.Goode wrote:
Sat Jun 12, 2021 8:29 pm
Luke14 wrote:
Sat Jun 12, 2021 7:40 pm
bensimmo wrote:
Thu Jun 10, 2021 8:23 pm
I think the environment method Is the quickest and easiest.

In the pins section it goes into details of the two methods. But like I said it long winded and not a just so this.
All the pigpio seems to be written with remote use (which is cool).

Now unfortunately I don't have my code near me nor a Pi to check what works.
I also use the cheap blue servos and still had jitter (a lot less though).


But something like

Code: Select all

from gpiozero.pins.pigpio import PiGPIOFactory

gpiozero.Device.pin_factory = PiGPIOFactory('127.0.0.1')
Just booted up my Pi and changed it using the line in terminal.

I now get this in the shell using your code:

Code: Select all

Traceback (most recent call last):
                File   "/home/pi/Python/component tests/pigpio servo test for 400.py", line 7, in <module>
                Gpiozero.Device.pin-factory =piGPIOFactory('127.0.0 1')
                NameError: name 'gpiozero' is not defined.
                
Sorry if the spacing is strange above. I have never added code on this forum before so not sure if I have done it correctly... :lol:

Any help appreciated.


Supporting documentation and usage example here - https://gpiozero.readthedocs.io/en/stab ... in-factory




Specifically - gpiozero is an 'external' Python library module. You have to import it before you can use its contents.
Thank you. I'm a bit confused as looking at that example on that link I have got gpiozero. If you look at my picture in a previous reply on this thread you can see I have the line:

Code: Select all

from gpiozero import AngularServo
Is that not what you mean? Do I need just the line...

Code: Select all

import gpiozero
... to import the whole of the python libary for use with both my 'components' and to have the correct parts to fix the error?

Thank you. :D

User avatar
B.Goode
Posts: 12263
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: 'pigpio' help! (+ servo jitter)

Sun Jun 13, 2021 7:33 am

Luke14 wrote:
Sat Jun 12, 2021 8:42 pm


Thank you. I'm a bit confused as looking at that example on that link I have got gpiozero. If you look at my picture in a previous reply on this thread you can see I have the line:

Code: Select all

from gpiozero import AngularServo
Is that not what you mean? Do I need just the line...

Code: Select all

import gpiozero
... to import the whole of the python libary for use with both my 'components' and to have the correct parts to fix the error?

Thank you. :D


The line of code you quote here does pretty much what is says in English: it makes available the AngularServo Class, (and that Class only ) from the entire gpiozero library.


If that is the model of working you want to adopt, that's fine. But you will need to modify your script.

You need to import the Device Class as an initial step, and then change the way you create an instance of it -

Code: Select all

from gpiozero import Device
Device.pin_factory = PiGPIOFactory('127.0.0.1')


Illustrated in the gpiozero documentation already referenced, and described in detail in the Python3 documentation - https://docs.python.org/3/reference/sim ... tml#import

Luke14
Posts: 16
Joined: Sun Jun 06, 2021 11:59 am

Re: 'pigpio' help! (+ servo jitter)

Sun Jun 13, 2021 8:02 am

B.Goode wrote:
Sun Jun 13, 2021 7:33 am
Luke14 wrote:
Sat Jun 12, 2021 8:42 pm


Thank you. I'm a bit confused as looking at that example on that link I have got gpiozero. If you look at my picture in a previous reply on this thread you can see I have the line:

Code: Select all

from gpiozero import AngularServo
Is that not what you mean? Do I need just the line...

Code: Select all

import gpiozero
... to import the whole of the python libary for use with both my 'components' and to have the correct parts to fix the error?

Thank you. :D


The line of code you quote here does pretty much what is says in English: it makes available the AngularServo Class, (and that Class only ) from the entire gpiozero library.


If that is the model of working you want to adopt, that's fine. But you will need to modify your script.

You need to import the Device Class as an initial step, and then change the way you create an instance of it -

Code: Select all

from gpiozero import Device
Device.pin_factory = PiGPIOFactory('127.0.0.1')


Illustrated in the gpiozero documentation already referenced, and described in detail in the Python3 documentation - https://docs.python.org/3/reference/sim ... tml#import
Thank you - I will give this a try a little later and see how it goes. :D

User avatar
bensimmo
Posts: 5365
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: 'pigpio' help! (+ servo jitter)

Sun Jun 13, 2021 9:47 am

That's a different way and I don't see that in the document.
Much easier though.


As for the part I gave from the docs it is
pin_factory and not pin_factory that you have posted

Luke14
Posts: 16
Joined: Sun Jun 06, 2021 11:59 am

Re: 'pigpio' help! (+ servo jitter)

Sun Jun 13, 2021 9:52 am

B.Goode wrote:
Sun Jun 13, 2021 7:33 am
Luke14 wrote:
Sat Jun 12, 2021 8:42 pm


Thank you. I'm a bit confused as looking at that example on that link I have got gpiozero. If you look at my picture in a previous reply on this thread you can see I have the line:

Code: Select all

from gpiozero import AngularServo

Is that not what you mean? Do I need just the line...

Code: Select all

import gpiozero
... to import the whole of the python libary for use with both my 'components' and to have the correct parts to fix the error?

Thank you. :D


The line of code you quote here does pretty much what is says in English: it makes available the AngularServo Class, (and that Class only ) from the entire gpiozero library.


If that is the model of working you want to adopt, that's fine. But you will need to modify your script.

You need to import the Device Class as an initial step, and then change the way you create an instance of it -

Code: Select all

from gpiozero import Device
Device.pin_factory = PiGPIOFactory('127.0.0.1')


Illustrated in the gpiozero documentation already referenced, and described in detail in the Python3 documentation - https://docs.python.org/3/reference/sim ... tml#import
Thank you... I have just tried this and it worked. There are no now errors or jitter!

Thank you so much for your help :D

Luke14
Posts: 16
Joined: Sun Jun 06, 2021 11:59 am

Re: 'pigpio' help! (+ servo jitter)

Sun Jun 13, 2021 9:55 am

bensimmo wrote:
Sun Jun 13, 2021 9:47 am
That's a different way and I don't see that in the document.
Much easier though.


As for the part I gave from the docs it is
pin_factory and not pin_factory that you have posted
Thank you. Using the way B.Goode said with the import Device it is now working with no jitter.

Thank you for all your help. :D

Return to “Python”