I came across a DFU issue in my project. Basic information:
- two buttons are connected to the pyboard 1.1's digital inputs, the user can move a stepper motor manually by pressing them. This code is located in main.py
- user can also provide a PWM frequency and time delay and pyboard will move the motor according to that. This piece of code runs on PC:
I found out that after I run the code above without resetting the machine at the end, main.py doesn't run again so the manual movement doesn't work anymore. I tried with sys.exit(), didn't solve the problem, so I went with machine.reset() which works. I noticed that after doing this a couple of times in a row, pyboard sometimes switches to DFU mode by itself, the number of resets after this happens looks random. Disconnecting pyboard's USB cable and connecting it again puts it back into normal mode. Any clues how I can correct that?
Code: Select all
import pyboard def serial(f1, t1): t_ser = str(int(t1)) f_ser = str(f1) pyb = pyboard.Pyboard('com7') pyb.enter_raw_repl() pyb.exec('from pyb import Pin, Timer') pyb.exec("import time") pyb.exec("import machine") pyb.exec("step = Pin('X1')") pyb.exec("direction = Pin('X2', Pin.OUT_PP)") pyb.exec("direction.low()") pyb.exec("tim = Timer(2, freq=" + f_ser + ")") pyb.exec("ch = tim.channel(1, Timer.PWM, pin=step)") pyb.exec("ch.pulse_width_percent(50)") pyb.exec("pyb.delay("+ t_ser + ")") pyb.exec("tim.deinit()") pyb.exec("machine.reset()") pyb.exit_raw_repl() pyb.close()