Is it possible to detect when motors are connected or disconnected? #1980
Unanswered
MrShinyAndNew
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Here is an example for dynamically checking what is connected: https://docs.pybricks.com/en/latest/iodevices/pupdevice.html#detecting-devices Here is an example that lets you use a motor and ignore errors when nothing is plugged in: https://pybricks.com/project/disable-motor-detect/ |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm new to PyBricks (and python) and coming here from Node PoweredUp, so please forgive any ignorance on my part. When using Node PoweredUp there is a signal whenever a device is plugged or unplugged. This allows me to dynamically detect what is connected, and adapt the program's behaviour as needed. I've come up with a solution for the Remote (basically: when I poll the buttons and get ENODEV I go back into an initialization loop waiting for the remote) .
What I'd like to do is have a long-running program on a hub that can withstand a motor being unplugged then plugged back in (or a sensor). I'd especially like to know if a motor could be plugged back in to the "wrong" port - for example consider a train with one train motor. It doesn't matter which port the motor is plugged into, and when you're managing a long-running Lego display it's helpful to not have to memorize the details of the programming if you can avoid it.
Beta Was this translation helpful? Give feedback.
All reactions