Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4079

Troubleshooting • Sensor pin irq callback doesn't work when dc motor is running

$
0
0
I'm using raspberry pi pico with dc motor and sensor to count motor rotations. If I rotate shaft by myself sensor_callback works.

from machine import Pin,PWM
from dcmotor import DCMotor

count = 0
def sensor_callback(pin):
global count
if pin.value() == 0:
count = count + 1
print("count", count)

sensor = Pin(28, Pin.IN, Pin.PULL_UP)
sensor.irq(trigger=Pin.IRQ_FALLING, handler=sensor_callback)

dc_motor_frequency = 1000
dc_motor_pin1 = Pin(0, Pin.OUT)
dc_motor_pin2 = Pin(1, Pin.OUT)
dc_motor_enable = PWM(Pin(4), dc_motor_frequency)
dc_motor = DCMotor(dc_motor_pin1, dc_motor_pin2, dc_motor_enable)

dc_motor.start()


How to count RPS for dc motor?

Statistics: Posted by webwin — Fri Mar 28, 2025 4:48 pm



Viewing all articles
Browse latest Browse all 4079

Trending Articles