After set timer, ampy doesn't work

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
jerrycai73
Posts: 8
Joined: Wed Jan 20, 2021 9:12 pm

After set timer, ampy doesn't work

Post by jerrycai73 » Thu Feb 25, 2021 9:49 pm

I'm using timer to get input value from a Rotary encoder .
timer = machine.Timer(0)

Code: Select all

def handleInterrupt(timer):
	global last
	global e 
	global d
	value = e.getValue()
	d = value - last
	last = value;
	if d != 0:
 		print("rotary::" , str(d))
 	
timer.init(period=200, mode=machine.Timer.PERIODIC, callback=handleInterrupt)
The code works well. But when I tried to upload code again, with following command:
ampy -p com9 put main.py

I got "could not enter raw repl". If I removed main.py for esp8266 and reboot. the ampy woks.

Any solution for this?
Last edited by jimmo on Thu Feb 25, 2021 11:47 pm, edited 1 time in total.
Reason: Add [code] formatting

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: After set timer, ampy doesn't work

Post by jimmo » Thu Feb 25, 2021 11:50 pm

jerrycai73 wrote:
Thu Feb 25, 2021 9:49 pm
I got "could not enter raw repl". If I removed main.py for esp8266 and reboot. the ampy woks.
Because ampy uses the REPL to send/receive data, anything that your program prints out will confuse ampy.

Unfortunately there's no way for ampy to stop your ISR from running -- if it does a soft reset, then main.py will start again, and if it just does a Ctrl-C, then the ISR is still registered in the background.

I would suggest one of two things:
- Detect if a button is being held at startup, and in which case don't start your program (including not registering the ISR). That way ampy will run as normal.
- Don't do anything in main.py automatically. Let the user start the program manually from the repl() (e.g. provide a run() method that starts everything).

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: After set timer, ampy doesn't work

Post by jimmo » Thu Feb 25, 2021 11:51 pm

In general though, instead of using ampy, I recommend either pyboard.py or rshell.

pyboard.py has a neat feature where you can run your program from RAM, ratehr than copying the file to the board. So when your board restarts, nothing is running until you run it with pyboard.py

See http://docs.micropython.org/en/latest/r ... rd.py.html

jerrycai73
Posts: 8
Joined: Wed Jan 20, 2021 9:12 pm

Re: After set timer, ampy doesn't work

Post by jerrycai73 » Fri Feb 26, 2021 12:04 am

Thanks a lot.
I'll try it

Post Reply