Closed fisherds closed 9 years ago
I am seeing the same thing and will investigate.
I have a temporary work-around that will turn off the motors, but will throw some benign exceptions on exiting. Modify your signal handler to:
def signal_handler(sig, frame):
print('\nYou pressed Ctrl+C')
if board is not None:
board.reset()
sys.exit(0)
An original design goal was to provide an internal working Control-C handler, which is clearly not the case. I will leave this issue open until I come up with a workable solution in code or coding guidance.
I can live with that.
Also as an FYI this is a non-issue when I run the Python script from Eclipse. Even without any signal_handler code at all. When I hit the red stop button on the Eclipse Console the wheels shutdown correctly. It's like magic. The wheels stop, there are like four quick flashes on LED 13, a quick flash on the Rx LED and the thing is shutdown. No logs shown, but the Adruino is properly shutdown. Is that your attempt at the internal Control-C handler working??? Just tell everyone to use Eclipse instead of running scripts from the command line. :) 100% reliable.
Thanks for the feedback. The flashing L13 is how Firmata announces its version number( in addition to sending out the serial port), so that is correct. There is signal handling code built into pymata_core that is supposed to handle control-c detection. It sees the signal, but does not shutdown cleanly, so I will be investigating.
I retested with version 2.1 and when I press ctrl-c the motors stop. I removed the signal handler code from the example, and retested, and again, the motors stop from the internal ctrl-c handling within pymata_core. Therefore I am closing this issue.
I'm not sure if it is supposed to or not, but in the old version of Pymata that used time.sleep you could hit Ctrl-C to get a reset (which is now called shutdown). If I hit Ctrl-C during a board.sleep the shutdown command it's actually doing a shutdown on the Arduino. Ctrl-C works to print messages and shutdown is called, but there is no actual reset happening on the Arduino.
Running the code below does this...
But then the motors all keep running whatever the current state is. Is there a way to get back the Ctrl-C feature while using board.sleep? Here is the complete code...