Comments (18)
Figured it out! It is a speed problem - adding time.sleep(1)
after the while
loop solves the issue:
# flush input (without relying on serial.flushInput())
n = self.serial.inWaiting()
while n > 0:
self.serial.read(n)
n = self.serial.inWaiting()
time.sleep(1)
0.5 seconds is not enough - 1 second does the trick. Apparently I wasn't the only one who's had the issue, see the same issue with ampy: scientifichackers/ampy#19 (comment).
(Took me 4 hours, but worth it I hope)
from belay.
I think I did try with >>>
earlier, and it didn’t help (but let me give it another try in the morning, as I’m not 100% where I placed it).
from belay.
I am unable to reproduce; the examples work fine for me on an esp32.
As a debugging step, what does the following do for you:
python -m serial.tools.miniterm /dev/tty.usbserial-0001 115200
# After it's booted and you're in a prompt, then press CTRL+A
It should look like:
MacBook-Air:~/projects/belay$ python -m serial.tools.miniterm /dev/tty.usbserial-0001 115200
--- Miniterm on /dev/tty.usbserial-0001 115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x1f (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:4540
ho 0 tail 12 room 4
load:0x40078000,len:12344
ho 0 tail 12 room 4
load:0x40080400,len:4124
entry 0x40080680
MicroPython v1.19.1 on 2022-06-18; ESP32 module with ESP32
Type "help()" for more information.
>>>
raw REPL; CTRL-B to exit
>
from belay.
That's strange... I get:
(buxr) ➜ ~ python -m serial.tools.miniterm /dev/tty.usbserial-0001 115200
--- Miniterm on /dev/tty.usbserial-0001 115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
MicroPython v1.19.1 on 2022-06-18; ESP32 module with ESP32
Type "help()" for more information.
>>>
raw REPL; CTRL-B to exit
>
I'm still unable to connect though Belay only. I'm in a conda environment, but I don't think that should make any difference.
from belay.
I see the ports fine too:
from serial.tools import list_ports
working_serial = []
for port in list(list_ports.comports()):
working_serial.append(port.device)
print(working_serial)
# ['/dev/cu.BLTH', '/dev/cu.Bluetooth-Incoming-Port', '/dev/cu.usbserial-0001', '/dev/cu.SLAB_USBtoUART']
I am connecting it to a external USB hub.
from belay.
I wonder if there is some subtle race condition going on; do you have an unusually fast computer
Try putting a time.sleep(0.01)
after the self.serial.write
here and here.
If that does anything, then we know we're on the right trail.
from belay.
glad you found a solution! Right now I'm trying to think of a generic solution, and I think there are 2 paths:
Option 1: Figure out why Pyboard.read_until
is not working as expected. Clearly the reported data
b'MicroPython v1.19.1 on 2022-06-18; ESP32 module with ESP32\r\nType "help()" for more information.\r\n>>> '
does not end with b"raw REPL; CTRL-B to exit\r\n>"
. So why does Pyboard.read_until
return? You're not reaching the 10s timeout, are you? This is a bit hard on my side since I cannot reporduce this. Once we fix this, then hopefully we don't need an inelegant sleep
.
Option 2 (backup): If we cannot get option 1 working, what are your thoughts if I add an additional kwarg raw_repl_delay=0
to the Device
constructor and pipe it through to enter_raw_repl
? so, in your case, it would look like:
pyb = belay.Device('/dev/cu.SLAB_USBtoUART', 115200, raw_repl_delay=1)
I'd be hesitent to hard program in a value because:
- I'd say anything above 1 second is too long for cases that don't need it. I'd realistically draw the line at 0.25 seconds.
- Some people said 1 second wasn't enough.
from belay.
I think I understand the problem a little better now; does your current setup have a main.py
on board?
from belay.
I actually do reach the 10s timeout, so it isn’t reading anything. What happens is beyond me. I think the second solution is a good one, especially, as you say, you’re unable to reproduce the error and I also wouldn’t want to hardcode such a long sleep in. And since it’s still an issue both in pyboard.py
and ampy
I wouldn’t spend more time than necessary on it.
from belay.
Maybe just call the argument delay
for simplicity and cover it in the documentation.🤷🏻♂️
from belay.
Nope, there’s no main.py
on board. Just the autogenerated boot.py
with everything commented out.
from belay.
sounds good, here are a few more thoughts:
- I'm going to modify
read_until
to raise an exception if the timeout is reached. All the locations its called is always followed by a check to see if the end_marker is actually in the returned data. And, in all cases, it seems to be an irrecoverable error if not. So raising an exception will make a lot of code calling code a little terser and the issue more obvious. No action required on your side. - Shot in the dark, if you were to put
self.read_until(1, b">>>")
instead of yourtime.sleep(1)
, does that solve the issue either?
EDIT: fixed command in (2)
from belay.
took care of (1) in #39, will wait on your response for implementing the fix for this delay issue.
from belay.
Alright, back at it. self.read_until(1, b">>>")
works like a charm! I timed it, and for me it takes roughly 650ms - which corresponds quite well with the minimum time.sleep()
needed to make the connection.
from belay.
excellent!! so last test, does everything still work if you comment out the while loop above it? So your code should look like:
def enter_raw_repl(self, soft_reset=True):
self.serial.write(b"\r\x03\x03") # ctrl-C twice: interrupt any running program
# flush input (without relying on serial.flushInput())
n = self.serial.inWaiting()
# while n > 0:
# self.serial.read(n)
# n = self.serial.inWaiting()
self.read_until(1, b">>>")
self.serial.write(b"\r\x01") # ctrl-A: enter raw REPL
# and the rest of the normal code here
If that works, thats the solution we'll go with, and the action items will be:
- Make a PR here with the change that worked (whether or not that includes deleting the while loop).
- Make a PR into the
micropython/micropython
repository with the upgrade.
If you're comfortable, I'd suggest you make the PR for (1) here and (2). However, if you don't want to, I'd be more than happy to.
EDIT: unfortunately, waiting for ">>>" doesn't reliably work in my setup; I'll try and come up with a PR that works for me and I think will work for you, and you can test it.
from belay.
alright @roaldarbol , I think I solved it; give #41 a try. If it works for you, I'll merge it and make a PR to upstream micropython.
from belay.
Really neat @BrianPugh! I'll test first thing in the morning (I'm on London time).
from belay.
Fixed with #41.
from belay.
Related Issues (20)
- global scope vars can't be accessed if reassigned in task HOT 3
- Bug: `setup` with arguments fails HOT 5
- Continuous logging and injecting parameters HOT 13
- Advised way of importing libraries HOT 9
- Package manager documentation HOT 15
- Package manager dependency indexes HOT 3
- Using belay in a class HOT 10
- AttributeError: type object 'Executer' has no attribute 'setup' HOT 2
- Find available devices HOT 13
- `Yield` returns `None` HOT 4
- Using Pimoroni libraries HOT 4
- Timed generator helper function HOT 3
- Injecting methods HOT 9
- Send event/request from board/device HOT 5
- OSError: could not get source code HOT 3
- sync uses wrong path `\` characters when copying files to /pyboard while Python 3 is running on windows machines. HOT 13
- Unable to synch with CircuitPython 8.0 on Trinkey HOT 14
- CircuitPython remount in boot.py makes drive readonly to PC. HOT 3
- ImportError no module named analogio HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from belay.