Hi,
I found this related thread topic=127868.0, but I didn’t want to necro-bump it…
I wrote my own python class for an only partly identified stepper, the KH42JM2-B203.
It came out of an office-type scanner model.
I connected it with the mosfets to four pins of the arduino-board.
This setup works, the script makes the head move to the requested position
However, if I let it run in a loop to go to different locations subsequently, the script hangs
this is the loop
if len(outputs) == 4:
prin(self.current_position)
for i, out in enumerate(outputs):
self.PINS[i].write(out)
sleep (self.time_out)
This is the output when pressing Ctrl-C:
KeyboardInterrupt Traceback (most recent call last)
<ipython-input-712-bcd6e553d7b8> in <module>()
1 for r in R:
2 print('Moving to position {}'.format(r))
----> 3 myServo.move_to_percent(r)
4 sleep(3)
5
/home/sam/scripts/Python/Electronics/MotorTest.py in move_to_percent(self, percent)
125
126 for i in range(0, int(abs(take_steps))):
--> 127 self.one_tick(reverse)
128 print()
129 def angle(self, degrees):
/home/sam/scripts/Python/Electronics/MotorTest.py in one_tick(self, reverse)
97 prin(self.current_position)
98 for i, out in enumerate(outputs):
---> 99 self.PINS[i].write(out)
100
101 sleep (self.time_out)
/usr/lib/python3.6/site-packages/pyfirmata/pyfirmata.py in write(self, value)
531 if self.mode is OUTPUT:
532 if self.port:
--> 533 self.port.write()
534 else:
535 msg = bytearray([DIGITAL_MESSAGE, self.pin_number, value])
/usr/lib/python3.6/site-packages/pyfirmata/pyfirmata.py in write(self)
424 # print("type pinnr", type(pin_nr))
425 msg = bytearray([DIGITAL_MESSAGE + self.port_number, mask % 128, mask >> 7])
--> 426 self.board.sp.write(msg)
427
428 def _update(self, mask):
/usr/lib/python3.6/site-packages/serial/serialposix.py in write(self, data)
554 assert timeout.time_left() is None
555 # wait for write operation
--> 556 abort, ready, _ = select.select([self.pipe_abort_write_r], [self.fd], [], None)
557 if abort:
558 os.read(self.pipe_abort_write_r, 1)
KeyboardInterrupt:
From this thread I thought that the power supply was the problem, because I’m driving a stepper of which I don’t know the exact specifications, but I suspect that the current the adapter delivers, is not enough.
However, when i try without anything connected, i get the same error…
What could I be doing wrong ?
Is it ok to write to four ports without any delay ?
Or should i supply a parameter with the timeout value ?
Thank you for any help