Page 1 of 1

Code only runs when USB serial connected

Posted: Mon Mar 20, 2017 8:14 pm
by smssms
Has anyone else experienced this:

I have some code which will run fine in the REPL as snippets, it will run fine as main.py (with USB serial connected), but when I try to run it without the USB plugged in, it just stops part way through. As I don't have the USB connected I can't see error messages or exactly where it fails.

Re: Code only runs when USB serial connected

Posted: Tue Mar 21, 2017 6:34 am
by Roberthh
Will it run when connected though telnet? Or do you see the error message then?

Re: Code only runs when USB serial connected

Posted: Tue Mar 21, 2017 10:46 am
by smssms
It will not run with a Telnet connection either (and there are no error messages when it fails on Telnet).

I've had a stab at try: except: to write exceptions to the SD card, but nothing seems to go there.

I'm starting to thing it is some sort of power supply issue i.e. it is only working with USB power available. But it is strange that it fails part way through the code, it can run boot.py and the first 1/3 of main.py.

Re: Code only runs when USB serial connected

Posted: Tue Mar 21, 2017 11:04 am
by Roberthh
How do you power the device in the absence of USB?

Re: Code only runs when USB serial connected

Posted: Tue Mar 21, 2017 11:31 am
by smssms
XP JCJ1012S05 1.5A 5V output DC/DC converter into Vin/Gnd Plus 10uF capacitor for smoothing as it also has to run a stepper motor. The max. draw is only 800mA, so well within the supply's limits. The stepper motor is running in the first 1/3 of main.py too with no problems. But without USB, it just seems to hit a point where it freezes with no error messages (that I can capture).

http://uk.farnell.com/xp-power/jcj1012s05/converter-dc-dc-10w-5v/dp/1637871

Re: Code only runs when USB serial connected

Posted: Tue Mar 21, 2017 11:58 am
by Roberthh
The supply looks fine. Assuming that you power the WiPy 1(?) on the expansion board and lookg at the schematics, it seems, that the USB/Serial chip is not powered when you suply though Vin. That may cause Tx/Rx/CTS and RTS to be pulled low. I do not know what that causes to the device. But just for test, you could remove the jumpers for TX, RX, CTS and RTS.

Re: Code only runs when USB serial connected

Posted: Tue Mar 21, 2017 12:12 pm
by smssms
It is the latest WiPy and on an Expansion Board.

Tried removing the jumpers as described - same problem :(

Re: Code only runs when USB serial connected

Posted: Tue Mar 21, 2017 12:20 pm
by devnull
I faced a similar problem and the cause is a lack of pullup on either the TX / RX or both (don't recall which).

When you connect a USB > Serial, the TX/RX Lines are pulled high, but when disconnected they are floating and the device will not start as it is waiting for the high signal.

Re: Code only runs when USB serial connected

Posted: Tue Mar 21, 2017 2:07 pm
by smssms
SOLVED

Despite the stepper motor working fine upto the point of failure, it looks like it was a power supply issue.

When I drive the stepper motor from a separate supply it all seems to work ok with or without USB connected.