Moderator: RevPiModIO

Topic Author
Posts: 4
Joined: 23 Jul 2020, 13:54

Software PWM and read analog input at the same time

29 Sep 2020, 09:17

Hey all,

I have problems with my PWM running and retrieving analog values at the same time.

I have connected a motor that I run through the PWM of the Revolution Pi. I let this motor run at different speeds and toggle it with a button.
I realized this with the following code (These are only excerpts):

import revpimodio2
class MyRevPiApp():

def event_flipflop_o3(self, ioname, iovalue): = not
if = 20
else: = 70

Then I use a current sensor to measure the current going through the wire that drives the motor.
I obtain the values of the current sensor via an analog input of the Revolution Pis and retrieve them cyclically.
I realized this with the following code:

import sys
import revpimodio2
import threading
import paho.mqtt.client as mqtt
import time

rpi = revpimodio2.RevPiModIO(autorefresh=True)

import paho.mqtt.client as mqtt #import the client1
#broker_address="" #use external broker
client = mqtt.Client("P1") #create new instance
client.connect(broker_address) #connect to broker

def printCurrentValue():
threading.Timer(1.0, printCurrentValue).start()
if < 2490:
print("Value = ",


When I run my python scripts one at a time I have no problems and the PWM runs stable.
But as soon as I let the PWM run and then execute the script to query the analog readings, the PWM is unstable and the motor stutters.

Can someone explain to me what the reason for this is and how I can solve this problem?
Many thanks for the help:)
User avatar
Posts: 1504
Joined: 15 Dec 2016, 13:19

Re: Software PWM and read analog input at the same time

29 Sep 2020, 10:05

Hi Ludwig I have moved your post to the RevPiModIO forum.
User avatar
Posts: 249
Joined: 20 Jan 2017, 08:44

Re: Software PWM and read analog input at the same time

01 Oct 2020, 03:39

Hi Ludwig!

If you are using RevPiModIO, it will force the IO values, which are set in your python program to the process image. This could be very important, if you are controlling a plant with the system. So RevPiModIO is the master of your process image.

If you are starting two programs with RevPiModIO, each instance will force there values. So, if you are setting the value of PWM_1 to 30 in program A, the program B will reset PWM_1 to 0, because there was no change of the value. After that, program A will reset the value back to 30 again, and so on.

What can you do:
1) Rewrite your control program and integrate the complete logic to the one program (safest way)
2) Set the shared_procimg=True switch in your .RevPiModIO(autorefresh=True, shared_procimg=True) call.

python3-RevPiModIO - || Der RevPi ist das Beste, was passieren konnte!

Who is online

Users browsing this forum: No registered users and 1 guest