Pigpio for PWM on Raspberry Pi 3

raspberrypi3

#1

I am using a Raspberry Pi 3 and a servo SG-90 to move a camera. The servo is controlled using a PWM signal. Right now I am using a specific library, called pigpio, for the PWM. The reason that I don’t want to use the standard GPIO package is that the timing of the PWM signal is controlled by software, not by hardware (as long as I understood), and therefore is not suitable for servos (the movement was quite trembling and very imprecise, but solved using pigpio).

I found a github project which specifies a Dockerfile to use this library properly. My question is: am I in the correct way, or is there an easier way to deal with PWM signals on RPI3?

Moreover, pigpio runs a daemon process which controls the hardware, and listens the port 8888 (by default), allowing to use this library in different languages (python in my case). I have multiple services which use the RPI3 hardware through pigpio. I think that the best way is to run a container with this daemon, and one more container for each service that I want to use. What do you think?

Thank you.


#2

Hey @jcozar,

I’m not hugely familiar with PWM’ing on an rpi but I’m pretty sure the same code should work on resin and non-resin projects.

The Dockerfile you posted should work fine, with a caveat. You will need to create a start script which will first start up the pigpio server in the background, and then move on to starting your own application.

For the CMD line on Dockerfile, set it to something like:
CMD "./start.sh"
and then create a file start.sh which looks like this:
/usr/bin/svscan "/etc/svscan/" & python myprogram.py
and that will start the pigpio service in the background which your code can then call into.

Multiple containers on a single device is something that we are working on with priority, but we don’t have a date of release just yet.


#3

Another approach would be to enable the INIT system (set ENV INITSYSTEM on in your Dockerfile), and then COPY a systemd script into /etc/systemd/system/ and set it to start at boot.

This would then run the daemon in the background and allow you to access it from anywhere on the network, not just the local pi.


#4

Thank you all!

Finally, I am using the docker image that I posted ([quote=“jcozar, post:1, topic:1341”] github project [/quote]) and the multiple containers approach that @cameron said (I know that it’s still not ready, but right now it works with a hack). Therefore, the container running the pigpio server is running together with my main application, and it is working correctly. Thanks again!


#5

Hi…i am a new user here. I have a 7MHz signal and I want to modulate it with a 330KHz signal. Can any on the C2000 mirocontroller generate a 7MHz PWM signal to modulate a sine wave of 330KHz signal.I am building an inverter to produce a sine wave of 330KHz. I have 142nseconds period of 7MHz signal and I want to have a duty cycle of 10% to 100%.

pcb assembly