My IDE configuration using Notepad++, ampy and Tera Term
My IDE configuration using Notepad++, ampy and Tera Term
I use Notepad++ for editing, ampy for downloading and Tera Term for serial terminal. In Notepad++ I use NPPExec to execute the following commands:
NPP_SAVE
ampy --port COM4 put $(FULL_CURRENT_PATH)
reset.bat
exit
The file is first saved, then downloaded via COM4. The reset.bat file sends a Ctrl-D to COM4 and resets the esp8266. I set up a shortcut key Alt-Z to trigger the NPPExec script above. So Alt-Z saves, downloads and resets the device. Without the reset in the script you have to go to Tera Term, connect to the port and do a Ctrl-D, a bit of a pain if you don't need the REPL.
Reset.bat contains:
echo off
mode COM4 BAUD=115200 PARITY=n DATA=8 >nul
echo off
echo ** >COM4
To get the actual Ctrl-D character into a text file type the following in DOS:
echo {Do the key combinations CTRL-P followed by CTRL-D} > temp.bat
Edit this file with Notepad++ and you will see in reverse colours DLE EOT which it displays for CTRL-P and CTRL-D these should be pasted into the reset.bat file in place of the two asterisks.
NPP_SAVE
ampy --port COM4 put $(FULL_CURRENT_PATH)
reset.bat
exit
The file is first saved, then downloaded via COM4. The reset.bat file sends a Ctrl-D to COM4 and resets the esp8266. I set up a shortcut key Alt-Z to trigger the NPPExec script above. So Alt-Z saves, downloads and resets the device. Without the reset in the script you have to go to Tera Term, connect to the port and do a Ctrl-D, a bit of a pain if you don't need the REPL.
Reset.bat contains:
echo off
mode COM4 BAUD=115200 PARITY=n DATA=8 >nul
echo off
echo ** >COM4
To get the actual Ctrl-D character into a text file type the following in DOS:
echo {Do the key combinations CTRL-P followed by CTRL-D} > temp.bat
Edit this file with Notepad++ and you will see in reverse colours DLE EOT which it displays for CTRL-P and CTRL-D these should be pasted into the reset.bat file in place of the two asterisks.
Paul Mulvey
Re: My IDE configuration using Notepad++, ampy and Tera Term
This works great on my home laptop (Win 8.1) but when I tried it on the students' Win 7 machines it doesn't work. Seems to be something different going on at the DOS level. Anyway I made a grand improvement that does work.
My Project has a workspace folder with a globals folder in this so I have a package arrangement with the __init__.py in the globals folder. So the task is to use a shortcut key to execute a NPPExec script:
This is SendCTRLD.py which sends a CTRL-D to the Board. So one shortcut key saves the file, downloads it and does a soft reset on the ESP8266.
My Project has a workspace folder with a globals folder in this so I have a package arrangement with the __init__.py in the globals folder. So the task is to use a shortcut key to execute a NPPExec script:
Code: Select all
NPP_CONSOLE -
set port = COM4
cd $(CURRENT_DIRECTORY)
npe_console v+ // Send console to the $(OUTPUTL) variable
cmd /c if exist "boot.py" echo Exists // Am I in the workspace folder?
npe_console v-
if "$(OUTPUTL)" = "Exists"
NPP_SAVE // Save the file
NPP_CONSOLE +
ampy --port $(port) put $(FULL_CURRENT_PATH) // Download to ESP
NPP_CONSOLE -
cd $(CURRENT_DIRECTORY)
cd.. // The SendCTRLD.py script is up one level from here
NPP_CONSOLE +
py SendCTRLD.py $(port)
else
NPP_SAVE
NPP_CONSOLE +
ampy --port $(port) put $(FULL_CURRENT_PATH) \Globals\$(FILE_NAME)
NPP_CONSOLE -
cd $(CURRENT_DIRECTORY)
cd.. // The SendCTRLD.py script is up two levels from here
cd..
NPP_CONSOLE +
py SendCTRLD.py $(port)
NPP_CONSOLE +
exit
echo No
This is SendCTRLD.py which sends a CTRL-D to the Board. So one shortcut key saves the file, downloads it and does a soft reset on the ESP8266.
Code: Select all
import serial
import sys
ser = serial.Serial(
port=sys.argv[1],
baudrate=115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
)
ser.write(serial.to_bytes([0x04]))
ser.close()
print("Board Reset")
Paul Mulvey
Re: My IDE configuration using Notepad++, ampy and Tera Term
Ignore my previous posts... this is a work in progress!
When I am using Tera Term to view serial output I had to close the connection before downloading and then open it again because ampy needs the port. In order to improve the automation around programming the device I have added two python programs, DisTeraTerm to close it and ConTeraTerm to reconnect. These essentially find the Tera Term application and send it the appropriate keystrokes. I have just finished it so I'm not 100% sure how bullet proof it is. The updated NPPExec script now looks like this:
This is DisTeraTerm.py:
and ConTeraTerm.py is:
This folder structure is
I would welcome feedback on this.
When I am using Tera Term to view serial output I had to close the connection before downloading and then open it again because ampy needs the port. In order to improve the automation around programming the device I have added two python programs, DisTeraTerm to close it and ConTeraTerm to reconnect. These essentially find the Tera Term application and send it the appropriate keystrokes. I have just finished it so I'm not 100% sure how bullet proof it is. The updated NPPExec script now looks like this:
Code: Select all
NPP_CONSOLE -
set port = COM4
cd $(CURRENT_DIRECTORY)
npe_console v+
cmd /c if exist "boot.py" echo Exists
npe_console v-
if "$(OUTPUTL)" = "Exists"
NPP_SAVE
cd..
NPP_CONSOLE +
py DisTeraTerm.py $(port)
ampy --port $(port) put $(FULL_CURRENT_PATH)
NPP_CONSOLE -
cd $(CURRENT_DIRECTORY)
cd..
NPP_CONSOLE +
py SendCTRLD.py $(port)
py ConTeraTerm.py
else
NPP_SAVE
cd..
cd..
NPP_CONSOLE +
py DisTeraTerm.py $(port)
ampy --port $(port) put $(FULL_CURRENT_PATH) \Globals\$(FILE_NAME)
NPP_CONSOLE -
cd $(CURRENT_DIRECTORY)
cd..
cd..
NPP_CONSOLE +
py SendCTRLD.py $(port)
py ConTeraTerm.py
NPP_CONSOLE +
exit
echo No
Code: Select all
import win32api
import win32ui
from time import sleep
import sys
teraterm = sys.argv[1] + " - Tera Term VT"
try:
PyCWnd1 = win32ui.FindWindow( None, teraterm )
print ("Stopping " + teraterm)
PyCWnd1.SetForegroundWindow()
PyCWnd1.SetFocus()
win32api.keybd_event(0x12, 0, ) # Alt
win32api.keybd_event(0x12, 0, 2 ) # Alt release
win32api.keybd_event(0x46, 0, ) # F
win32api.keybd_event(0x44, 0, ) # D
except:
print ("No Tera Term")
Code: Select all
import win32api
import win32ui
from time import sleep
import sys
teraterm = "Tera Term - [disconnected] VT"
try:
PyCWnd1 = win32ui.FindWindow( None, teraterm )
print ("Starting " + teraterm)
PyCWnd1.SetForegroundWindow()
PyCWnd1.SetFocus()
win32api.keybd_event(0x12, 0, ) # Alt
win32api.keybd_event(0x12, 0, 2 ) # Alt release
win32api.keybd_event(0x46, 0, ) # F
win32api.keybd_event(0x4E, 0, ) # N
win32api.keybd_event(0x2B, 0, ) # Enter Key
except:
print ("No Tera Term")
This folder structure is
Code: Select all
ProjectX
DisTeraTerm.py
ConTeraTerm.py
SendCTRLD.py
workspace
boot.py
main.py
MyProg.py
Globals
MyLibrary.py
LCDLib.py
Paul Mulvey
Re: My IDE configuration using Notepad++, ampy and Tera Term
Just discovered, Thonny 3.2.7 does all of the above!
Paul Mulvey
Re: My IDE configuration using Notepad++, ampy and Tera Term
Does anyone use Notepad++ for coding? How can I use its features effectively for C++?
Lucky Patcher Kodi nox
Lucky Patcher Kodi nox
Re: My IDE configuration using Notepad++, ampy and Tera Term
Paul, great pieces of Python!
I use EditPadPro, and since I started with MC, I defined "tools" on it called "μP Put" and "μP PutAsMain", which appear as icons on the tool bar when a python file is selected. Each tool invocation causes the file to be saved and an specific CMD file to be called. Very similar to what you are doing.
I also have a "μP Run" which upon ampy run completion, returned an open editor file with the run output. It was very handy for syntax debugging. It somehow got broken recently, not sure why, now I do not get the redirected ampy output... I have not had the time to look into it.
This tools had the annoying requirement of having to stop Teraterm. Now I have added your Python pieces, which seem to be working fine. Upon completion of the tool runs, I end up on the Teraterm window, which I am not sure yet, is what I want or not. But in any case a great improvement.
Thanks!
I use EditPadPro, and since I started with MC, I defined "tools" on it called "μP Put" and "μP PutAsMain", which appear as icons on the tool bar when a python file is selected. Each tool invocation causes the file to be saved and an specific CMD file to be called. Very similar to what you are doing.
I also have a "μP Run" which upon ampy run completion, returned an open editor file with the run output. It was very handy for syntax debugging. It somehow got broken recently, not sure why, now I do not get the redirected ampy output... I have not had the time to look into it.
This tools had the annoying requirement of having to stop Teraterm. Now I have added your Python pieces, which seem to be working fine. Upon completion of the tool runs, I end up on the Teraterm window, which I am not sure yet, is what I want or not. But in any case a great improvement.
Thanks!
Re: My IDE configuration using Notepad++, ampy and Tera Term
I have since found that on some PCs (old ones) that my python script for sending keystrokes to TeraTerm was unreliable. After some experimentation I added a sleep(.2) just before the line that sends the keystrokes and this seems to resolve the issue.
Having thought that Thonny was going do all of this for me I found that it was very unreliable for a variety of reasons, crashing and raising errors on the device. I cannot understand why there is not an IDE specifically for the very popular world of MicroPython. Still it's great fun cobbling together my own home brew IDE from bits and pieces!
Having thought that Thonny was going do all of this for me I found that it was very unreliable for a variety of reasons, crashing and raising errors on the device. I cannot understand why there is not an IDE specifically for the very popular world of MicroPython. Still it's great fun cobbling together my own home brew IDE from bits and pieces!
Paul Mulvey
- aivarannamaa
- Posts: 171
- Joined: Fri Sep 22, 2017 3:19 pm
- Location: Estonia
- Contact:
Re: My IDE configuration using Notepad++, ampy and Tera Term
I'm Thonny's author. The main problem is that I haven't been able to reproduce most of the reported crashes. The serial communication just seems to be too fragile with some combinations of specific device, OS and USB driver.
In the next Thonny version I plan to reduce the block size when writing to ESP-32 and ESP-8266 devices, add configuration parameters for tweaking block size and delays and increase some read timeouts. I'm already using separate thread to read device's output as fast as possible (buffer overruns seemed to be my main problem in early versions).
I'm very interested in more ideas about how to make the communication more reliable (without hurting performance too much). Can I somehow detect the receiving capability of the device so that I can choose optimal writing block size dynamically? Currently I'm using raw-mode for executing commands. I have considered using paste-mode instead and treating echo as feedback mechanism. Any thoughts about this?
Aivar Annamaa
https://thonny.org
https://thonny.org
Re: My IDE configuration using Notepad++, ampy and Tera Term
I started with Notepad++ but couldn't get it to colorize Python correctly so I switched to Atom. That was a good decision. Atom has github built-in so that speeds things up too. So for my desktop development I use Atom and cmd.
For ESP32 I use Mu. The editor isn't the greatest, but it's workable. What makes Mu really nice and fast is that it has a local/device folder view that mostly eliminates the need for Ampy. It also has a REPL window, so there's no need for a terminal emulator like TeraTerm, etc. Basically it's a one-stop-shop for ESP32 Python development. I think the idea is similar to Thonny, which I haven't tried, and uPyCraft which I tried, but it wasn't very far along.
For ESP32 I use Mu. The editor isn't the greatest, but it's workable. What makes Mu really nice and fast is that it has a local/device folder view that mostly eliminates the need for Ampy. It also has a REPL window, so there's no need for a terminal emulator like TeraTerm, etc. Basically it's a one-stop-shop for ESP32 Python development. I think the idea is similar to Thonny, which I haven't tried, and uPyCraft which I tried, but it wasn't very far along.
Re: My IDE configuration using Notepad++, ampy and Tera Term
This is probably off topic from this thread, but are you using flow control when communicating to MicroPython targets? I'm using Ampy and esptool at crazy fast baud rates without any issues, ever. I can't imagine all of that would work reliably without use of CTS/RTS flow control.aivarannamaa wrote: ↑Sun Mar 01, 2020 11:15 am... The serial communication just seems to be too fragile with some combinations of specific device, OS and USB driver.