Search found 3821 matches
- Fri Jul 08, 2022 12:41 am
- Forum: General Discussion and Questions
- Topic: Injecting commands into while loop from Python
- Replies: 3
- Views: 2009
Re: Injecting commands into while loop from Python
And if you change run_forever.py to look like this instead: #!/usr/bin/env python import select import time def log_for(secs): global pyb end = time.time() + secs while time.time() < end: events = poll.poll(1000) for file in events: if file[0] == pyb.serial.fileno(): ch = pyb.serial.read(1) print(ch...
- Fri Jul 08, 2022 12:21 am
- Forum: General Discussion and Questions
- Topic: Injecting commands into while loop from Python
- Replies: 3
- Views: 2009
Re: Injecting commands into while loop from Python
The problem is that your toggle_forever is running, well, forever. The only way to tell if data is available on sys.stdin is to use poll or select. It looks like you're running on an ESP. I have a pyboard so I modified your example a bit to run on my pyboard. I created forever.py: import time import...
- Thu Jul 07, 2022 11:33 pm
- Forum: General Discussion and Questions
- Topic: Timer Callback Can't Be Stopped
- Replies: 7
- Views: 8413
Re: Timer Callback Can't Be Stopped
I think that pyb.exec only expects to be called once.
The first thing it does is read until it gets a > but all it gets is the output from your timer.
If you replace the with then it will execute the stop_pyb() and things work as expected.
The first thing it does is read until it gets a > but all it gets is the output from your timer.
If you replace the
Code: Select all
pyb.exec('stop_pyb()')
Code: Select all
pyb.serial.write(b'stop_pyb()')
- Mon Jun 27, 2022 8:22 pm
- Forum: General Discussion and Questions
- Topic: How to check if file exists?
- Replies: 5
- Views: 12282
Re: How to check if file exists?
Something like this should work: import os def file_or_dir_exists(filename): try: os.stat(filename) return True except OSError: retrun False If you want to determine if filename is a directory or a regular file then you can write: import os def dir_exists(filename): try: return (os.stat(filename)[0]...
- Sun Jun 26, 2022 6:05 pm
- Forum: Pyboard D-series
- Topic: external interrupts on the D series board
- Replies: 3
- Views: 23376
Re: external interrupts on the D series board
That's a limitation of the ExtInt module.
What do you need all of the interrupts for?
What do you need all of the interrupts for?
- Sun Jun 26, 2022 5:59 pm
- Forum: MicroPython pyboard
- Topic: Are different channels of the same timer synchronized in nature?
- Replies: 2
- Views: 22620
Re: Are different channels of the same timer synchronized in nature?
Yes - different channels of the same timer are synchronized. Some of the timers also support "center-aligned mode" where the centers of the two pulse will be aligned rather than the leading edge.
- Sat Jun 25, 2022 4:33 pm
- Forum: MicroPython pyboard
- Topic: Is it possible to query Timer output?
- Replies: 2
- Views: 21967
Re: Is it possible to query Timer output?
The counter() function: https://docs.micropython.org/en/latest/library/pyb.Timer.html#pyb.Timer.counter should return the value of the timer counter (in particular the TIMx_CNT register). I think that you can also read the corresponding GPIO pin (if you're trying to read say CH3 from Timer 4 (pin Y3...
- Wed Jun 22, 2022 8:10 pm
- Forum: ESP8266 boards
- Topic: Maximum possible machine.Timer period
- Replies: 17
- Views: 12897
Re: Maximum possible machine.Timer period
Some of the timers are 16-bit and some are 32-bit. If you try to store too large a value then it's probably getting truncated.
The documentation for the `period` field: https://docs.micropython.org/en/latest/ ... Timer.init shows which timers are 16-bit and which are 32-bit.
The documentation for the `period` field: https://docs.micropython.org/en/latest/ ... Timer.init shows which timers are 16-bit and which are 32-bit.
- Fri Jun 10, 2022 4:05 am
- Forum: General Discussion and Questions
- Topic: Trying to understand how memory allocation is working here...
- Replies: 10
- Views: 4053
Re: Trying to understand how memory allocation is working here...
I built the latest MicroPython for the RPi Pico and I see these results when using a simple terminal: (the repl within rshell) >>> gc.mem_alloc() 4496 >>> gc.mem_alloc() 4672 >>> gc.mem_alloc() 4816 >>> gc.mem_alloc() 4960 >>> gc.mem_alloc() 5104 >>> So only 144 bytes per iteration. Have you tried u...
- Wed Jun 08, 2022 7:49 pm
- Forum: General Discussion and Questions
- Topic: Trying to understand how memory allocation is working here...
- Replies: 10
- Views: 4053
Re: Trying to understand how memory allocation is working here...
When you enter things in the REPL, they get added to a history buffer, so that you can use the up arrow to bring back the previous command. Each time you enter a command a new entry get allocated for the history buffer, this is what's consuming the memory. The history buffer has a fixed number of en...