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):
def event_flipflop_o3(self, ioname, iovalue):
self.rpi.io.O_3.value = not self.rpi.io.O_3.value
self.rpi.io.PWM_5.value = 20
self.rpi.io.PWM_5.value = 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 paho.mqtt.client as mqtt
rpi = revpimodio2.RevPiModIO(autorefresh=True)
import paho.mqtt.client as mqtt #import the client1
#broker_address="iot.eclipse.org" #use external broker
client = mqtt.Client("P1") #create new instance
client.connect(broker_address) #connect to broker
if rpi.io.InputValue_2.value < 2490:
print("Value = ", rpi.io.InputValue_2.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:)